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:
parent
d687e95a8f
commit
c33f952ce7
10 changed files with 73 additions and 20 deletions
17
README.txt
17
README.txt
|
@ -52,14 +52,23 @@ top-level loops container and a concept manager:
|
|||
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
|
||||
testing we use a simple dummy implementation. As relationships are
|
||||
based on predicates that are themselves concepts we also need a
|
||||
default predicate concept; the default name for this is 'standard'.
|
||||
testing we use a simple dummy implementation.
|
||||
|
||||
>>> 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.registry import DummyRelationRegistry
|
||||
>>> from zope.app.testing import ztapi
|
||||
>>> 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')
|
||||
|
||||
Now we can assign the concept c2 as a child to c1 (using the standard
|
||||
|
|
|
@ -27,6 +27,7 @@ from zope.app.catalog.interfaces import ICatalog
|
|||
from zope.app.dublincore.interfaces import ICMFDublinCore
|
||||
from zope.app.event.objectevent import ObjectCreatedEvent
|
||||
from zope.app.form.browser.interfaces import ITerms
|
||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.dottedname.resolve import resolve
|
||||
from zope.event import notify
|
||||
|
@ -53,6 +54,9 @@ class ConceptEditForm(EditForm):
|
|||
|
||||
class ConceptView(BaseView):
|
||||
|
||||
template = ViewPageTemplateFile('concept_macros.pt')
|
||||
macro = template.macros['conceptlisting']
|
||||
|
||||
def children(self):
|
||||
for r in self.context.getChildRelations():
|
||||
yield ConceptRelationView(r, self.request, contextIsSecond=True)
|
||||
|
@ -165,6 +169,8 @@ class ConceptConfigureView(ConceptView):
|
|||
criteria['loops_type'] = (start, end)
|
||||
cat = zapi.getUtility(ICatalog)
|
||||
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:
|
||||
result = self.loopsRoot.getConceptManager().values()
|
||||
if searchType == 'none':
|
||||
|
|
32
browser/concept_macros.pt
Normal file
32
browser/concept_macros.pt
Normal 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>
|
|
@ -28,6 +28,13 @@
|
|||
permission="zope.View"
|
||||
/>
|
||||
|
||||
<page
|
||||
for="*"
|
||||
name="concept_macros"
|
||||
template="concept_macros.pt"
|
||||
permission="zope.View"
|
||||
/>
|
||||
|
||||
<page
|
||||
for="*"
|
||||
name="relation_macros"
|
||||
|
|
|
@ -26,10 +26,8 @@
|
|||
<tal:content define="item view/item;
|
||||
level level|python: 1;
|
||||
macro item/macro">
|
||||
<tal:content>
|
||||
<metal:block use-macro="macro" />
|
||||
</tal:content>
|
||||
</tal:content>
|
||||
</metal:body>
|
||||
|
||||
|
||||
|
|
|
@ -233,6 +233,8 @@ class ConfigureView(NodeView):
|
|||
criteria['loops_type'] = (start, end)
|
||||
cat = zapi.getUtility(ICatalog)
|
||||
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:
|
||||
result = (list(self.loopsRoot.getConceptManager().values())
|
||||
+ list(self.loopsRoot.getResourceManager().values()))
|
||||
|
|
|
@ -35,19 +35,16 @@
|
|||
|
||||
|
||||
<metal:body define-macro="conceptbody">
|
||||
<tal:body define="body item/body;
|
||||
target item/target;">
|
||||
<tal:body define="body item/body;">
|
||||
<div class="content-1"
|
||||
tal:define="onclick string:openEditWindow('${item/url}/@@configure.html')"
|
||||
tal:attributes="class string:content-$level;
|
||||
ondblclick python: item.editable and onclick or ''">
|
||||
<span tal:content="structure body">Node Body</span>
|
||||
</div>
|
||||
<div tal:repeat="resource target/resources">
|
||||
<a href="#"
|
||||
tal:attributes="href string:${item/url}/.target${resource/uniqueId}"
|
||||
tal:content="resource/title">Resource Title</a>
|
||||
</div>
|
||||
<tal:concepts define="item item/target">
|
||||
<div metal:use-macro="views/concept_macros/conceptlisting2" />
|
||||
</tal:concepts>
|
||||
</tal:body>
|
||||
</metal:body>
|
||||
|
||||
|
|
|
@ -106,6 +106,8 @@ class ResourceConfigureView(ResourceView, ConceptConfigureView):
|
|||
criteria['loops_type'] = (start, end)
|
||||
cat = zapi.getUtility(ICatalog)
|
||||
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:
|
||||
result = self.loopsRoot.getConceptManager().values()
|
||||
if searchType == 'none':
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<metal:block define-macro="render">
|
||||
<div>
|
||||
Here comes a document...
|
||||
<h3 tal:content="item/title">Title</h3>
|
||||
<span tal:replace="structure item/render" />
|
||||
</div>
|
||||
</metal:block>
|
||||
|
@ -8,7 +8,7 @@
|
|||
|
||||
<metal:block define-macro="image">
|
||||
<div>
|
||||
Here comes an image...
|
||||
<h3 tal:content="item/title">Title</h3>
|
||||
<img src="#"
|
||||
tal:attributes="src string:${view/url}/.target${view/targetId}/view" />
|
||||
</div>
|
||||
|
@ -17,7 +17,7 @@
|
|||
|
||||
<metal:block define-macro="download">
|
||||
<div>
|
||||
Here comes a file...
|
||||
<h3 tal:content="item/title">Title</h3>
|
||||
<a href="#"
|
||||
tal:attributes="href string:${view/url}/.target${view/targetId}/view">
|
||||
Download '<span tal:replace="item/title" />'
|
||||
|
|
6
view.py
6
view.py
|
@ -170,11 +170,11 @@ class NodeTraverser(ItemTraverser):
|
|||
if name == '.loops':
|
||||
return self.context.getLoopsRoot()
|
||||
if name.startswith('.target'):
|
||||
target = self.context.target
|
||||
if len(name) > len('.target') and IConcept.providedBy(target):
|
||||
if len(name) > len('.target'):
|
||||
idx = int(name[len('.target'):])
|
||||
target = zapi.getUtility(IIntIds).getObject(idx)
|
||||
#target = target.getResources()[idx]
|
||||
else:
|
||||
target = self.context.target
|
||||
viewAnnotations = request.annotations.get('loops.view', {})
|
||||
viewAnnotations['target'] = target
|
||||
request.annotations['loops.view'] = viewAnnotations
|
||||
|
|
Loading…
Add table
Reference in a new issue