More on viewing concepts and resources within views/nodes

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1127 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2006-03-17 15:35:01 +00:00
parent d687e95a8f
commit c33f952ce7
10 changed files with 73 additions and 20 deletions

View file

@ -52,14 +52,23 @@ top-level loops container and a concept manager:
Now we want to relate the second concept to the first one. Now we want to relate the second concept to the first one.
In order to do this we first have to provide a relation registry. For In order to do this we first have to provide a relation registry. For
testing we use a simple dummy implementation. As relationships are testing we use a simple dummy implementation.
based on predicates that are themselves concepts we also need a
default predicate concept; the default name for this is 'standard'.
>>> from zope.app.intid.interfaces import IIntIds
>>> from cybertools.relation.tests import IntIdsStub
>>> from zope.app.testing import ztapi
>>> ztapi.provideUtility(IIntIds, IntIdsStub())
>>> from cybertools.relation.interfaces import IRelationRegistry >>> from cybertools.relation.interfaces import IRelationRegistry
>>> from cybertools.relation.registry import DummyRelationRegistry >>> from cybertools.relation.registry import DummyRelationRegistry
>>> from zope.app.testing import ztapi
>>> ztapi.provideUtility(IRelationRegistry, DummyRelationRegistry()) >>> ztapi.provideUtility(IRelationRegistry, DummyRelationRegistry())
>>> from cybertools.relation.registry import RelationRegistry
>>> #ztapi.provideUtility(IRelationRegistry, RelationRegistry())
>>> #zapi.getUtility(IRelationRegistry).setupIndexes()
As relationships are based on predicates that are themselves concepts we
also need a default predicate concept; the default name for this is
'standard'.
>>> concepts['standard'] = Concept(u'subconcept') >>> concepts['standard'] = Concept(u'subconcept')
Now we can assign the concept c2 as a child to c1 (using the standard Now we can assign the concept c2 as a child to c1 (using the standard

View file

@ -27,6 +27,7 @@ from zope.app.catalog.interfaces import ICatalog
from zope.app.dublincore.interfaces import ICMFDublinCore from zope.app.dublincore.interfaces import ICMFDublinCore
from zope.app.event.objectevent import ObjectCreatedEvent from zope.app.event.objectevent import ObjectCreatedEvent
from zope.app.form.browser.interfaces import ITerms from zope.app.form.browser.interfaces import ITerms
from zope.app.pagetemplate import ViewPageTemplateFile
from zope.cachedescriptors.property import Lazy from zope.cachedescriptors.property import Lazy
from zope.dottedname.resolve import resolve from zope.dottedname.resolve import resolve
from zope.event import notify from zope.event import notify
@ -53,6 +54,9 @@ class ConceptEditForm(EditForm):
class ConceptView(BaseView): class ConceptView(BaseView):
template = ViewPageTemplateFile('concept_macros.pt')
macro = template.macros['conceptlisting']
def children(self): def children(self):
for r in self.context.getChildRelations(): for r in self.context.getChildRelations():
yield ConceptRelationView(r, self.request, contextIsSecond=True) yield ConceptRelationView(r, self.request, contextIsSecond=True)
@ -165,6 +169,8 @@ class ConceptConfigureView(ConceptView):
criteria['loops_type'] = (start, end) criteria['loops_type'] = (start, end)
cat = zapi.getUtility(ICatalog) cat = zapi.getUtility(ICatalog)
result = cat.searchResults(**criteria) result = cat.searchResults(**criteria)
# TODO: can this be done in a faster way?
result = [r for r in result if r.getLoopsRoot() == self.loopsRoot]
else: else:
result = self.loopsRoot.getConceptManager().values() result = self.loopsRoot.getConceptManager().values()
if searchType == 'none': if searchType == 'none':

32
browser/concept_macros.pt Normal file
View file

@ -0,0 +1,32 @@
<metal:body define-macro="conceptlisting">
<div>
<h3><span i18n:translate="">Concept</span>:
<span tal:content="item/title">Title</span></h3>
<metal:listing define-macro="conceptlisting2">
<div>
<h4>Parents</h4>
<div tal:repeat="related item/parents">
<a href="#"
tal:attributes="href string:${view/url}/.target${related/uniqueId}"
tal:content="related/title">Resource Title</a>
</div>
</div>
<div>
<h4>Children</h4>
<div tal:repeat="related item/children">
<a href="#"
tal:attributes="href string:${view/url}/.target${related/uniqueId}"
tal:content="related/title">Resource Title</a>
</div>
</div>
<div>
<h4>Resources</h4>
<div tal:repeat="related item/resources">
<a href="#"
tal:attributes="href string:${view/url}/.target${related/uniqueId}"
tal:content="related/title">Resource Title</a>
</div>
</div>
</metal:listing>
</div>
</metal:body>

View file

@ -28,6 +28,13 @@
permission="zope.View" permission="zope.View"
/> />
<page
for="*"
name="concept_macros"
template="concept_macros.pt"
permission="zope.View"
/>
<page <page
for="*" for="*"
name="relation_macros" name="relation_macros"

View file

@ -26,10 +26,8 @@
<tal:content define="item view/item; <tal:content define="item view/item;
level level|python: 1; level level|python: 1;
macro item/macro"> macro item/macro">
<tal:content>
<metal:block use-macro="macro" /> <metal:block use-macro="macro" />
</tal:content> </tal:content>
</tal:content>
</metal:body> </metal:body>

View file

@ -233,6 +233,8 @@ class ConfigureView(NodeView):
criteria['loops_type'] = (start, end) criteria['loops_type'] = (start, end)
cat = zapi.getUtility(ICatalog) cat = zapi.getUtility(ICatalog)
result = cat.searchResults(**criteria) result = cat.searchResults(**criteria)
# TODO: can this be done in a faster way?
result = [r for r in result if r.getLoopsRoot() == self.loopsRoot]
else: else:
result = (list(self.loopsRoot.getConceptManager().values()) result = (list(self.loopsRoot.getConceptManager().values())
+ list(self.loopsRoot.getResourceManager().values())) + list(self.loopsRoot.getResourceManager().values()))

View file

@ -35,19 +35,16 @@
<metal:body define-macro="conceptbody"> <metal:body define-macro="conceptbody">
<tal:body define="body item/body; <tal:body define="body item/body;">
target item/target;">
<div class="content-1" <div class="content-1"
tal:define="onclick string:openEditWindow('${item/url}/@@configure.html')" tal:define="onclick string:openEditWindow('${item/url}/@@configure.html')"
tal:attributes="class string:content-$level; tal:attributes="class string:content-$level;
ondblclick python: item.editable and onclick or ''"> ondblclick python: item.editable and onclick or ''">
<span tal:content="structure body">Node Body</span> <span tal:content="structure body">Node Body</span>
</div> </div>
<div tal:repeat="resource target/resources"> <tal:concepts define="item item/target">
<a href="#" <div metal:use-macro="views/concept_macros/conceptlisting2" />
tal:attributes="href string:${item/url}/.target${resource/uniqueId}" </tal:concepts>
tal:content="resource/title">Resource Title</a>
</div>
</tal:body> </tal:body>
</metal:body> </metal:body>

View file

@ -106,6 +106,8 @@ class ResourceConfigureView(ResourceView, ConceptConfigureView):
criteria['loops_type'] = (start, end) criteria['loops_type'] = (start, end)
cat = zapi.getUtility(ICatalog) cat = zapi.getUtility(ICatalog)
result = cat.searchResults(**criteria) result = cat.searchResults(**criteria)
# TODO: can this be done in a faster way?
result = [r for r in result if r.getLoopsRoot() == self.loopsRoot]
else: else:
result = self.loopsRoot.getConceptManager().values() result = self.loopsRoot.getConceptManager().values()
if searchType == 'none': if searchType == 'none':

View file

@ -1,6 +1,6 @@
<metal:block define-macro="render"> <metal:block define-macro="render">
<div> <div>
Here comes a document... <h3 tal:content="item/title">Title</h3>
<span tal:replace="structure item/render" /> <span tal:replace="structure item/render" />
</div> </div>
</metal:block> </metal:block>
@ -8,7 +8,7 @@
<metal:block define-macro="image"> <metal:block define-macro="image">
<div> <div>
Here comes an image... <h3 tal:content="item/title">Title</h3>
<img src="#" <img src="#"
tal:attributes="src string:${view/url}/.target${view/targetId}/view" /> tal:attributes="src string:${view/url}/.target${view/targetId}/view" />
</div> </div>
@ -17,7 +17,7 @@
<metal:block define-macro="download"> <metal:block define-macro="download">
<div> <div>
Here comes a file... <h3 tal:content="item/title">Title</h3>
<a href="#" <a href="#"
tal:attributes="href string:${view/url}/.target${view/targetId}/view"> tal:attributes="href string:${view/url}/.target${view/targetId}/view">
Download '<span tal:replace="item/title" />' Download '<span tal:replace="item/title" />'

View file

@ -170,11 +170,11 @@ class NodeTraverser(ItemTraverser):
if name == '.loops': if name == '.loops':
return self.context.getLoopsRoot() return self.context.getLoopsRoot()
if name.startswith('.target'): if name.startswith('.target'):
target = self.context.target if len(name) > len('.target'):
if len(name) > len('.target') and IConcept.providedBy(target):
idx = int(name[len('.target'):]) idx = int(name[len('.target'):])
target = zapi.getUtility(IIntIds).getObject(idx) target = zapi.getUtility(IIntIds).getObject(idx)
#target = target.getResources()[idx] else:
target = self.context.target
viewAnnotations = request.annotations.get('loops.view', {}) viewAnnotations = request.annotations.get('loops.view', {})
viewAnnotations['target'] = target viewAnnotations['target'] = target
request.annotations['loops.view'] = viewAnnotations request.annotations['loops.view'] = viewAnnotations