View/Node: added 'viewer' attribute

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1160 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2006-04-05 07:10:41 +00:00
parent 35de5b434a
commit 3a5281b047
8 changed files with 64 additions and 29 deletions

View file

@ -25,7 +25,7 @@ $Id$
from zope.app import zapi
from zope.app.catalog.interfaces import ICatalog
from zope.app.dublincore.interfaces import ICMFDublinCore
from zope.app.event.objectevent import ObjectCreatedEvent
from zope.app.event.objectevent import ObjectCreatedEvent, ObjectModifiedEvent
from zope.app.form.browser.interfaces import ITerms
from zope.app.pagetemplate import ViewPageTemplateFile
from zope.cachedescriptors.property import Lazy
@ -144,24 +144,25 @@ class ConceptConfigureView(ConceptView):
type = ITypeManager(self.context).getType(token)
factory = type.factory
container = type.defaultContainer
concept = factory(title)
concept = removeSecurityProxy(factory(title))
container[name] = concept
if IConcept.providedBy(concept):
concept.conceptType = type.typeProvider
notify(ObjectCreatedEvent(removeSecurityProxy(concept)))
notify(ObjectCreatedEvent(concept))
notify(ObjectModifiedEvent(concept))
assignAs = self.request.get('assignAs', 'child')
predicate = request.get('create.predicate') or None
if predicate:
predicate = removeSecurityProxy(
self.loopsRoot.loopsTraverse(predicate))
if assignAs == 'child':
self.context.assignChild(removeSecurityProxy(concept), predicate)
self.context.assignChild(concept, predicate)
elif assignAs == 'parent':
self.context.assignParent(removeSecurityProxy(concept), predicate)
self.context.assignParent(concept, predicate)
elif assignAs == 'resource':
self.context.assignResource(removeSecurityProxy(concept), predicate)
self.context.assignResource(concept, predicate)
elif assignAs == 'concept':
self.context.assignConcept(removeSecurityProxy(concept), predicate)
self.context.assignConcept(concept, predicate)
else:
raise(BadRequest, 'Illegal assignAs parameter: %s.' % assignAs)

View file

@ -388,7 +388,7 @@
label="Edit Node"
name="edit.html"
schema="loops.interfaces.INode"
fields="title description nodeType body"
fields="title description nodeType viewer body"
for="loops.interfaces.INode"
template="edit.pt"
permission="zope.ManageContent"
@ -405,20 +405,13 @@
add="zope.ManageContent"
/>
<editform
label="Configure Node"
<page
name="configure.html"
schema="loops.interfaces.INode"
fields="title description nodeType target"
for="loops.interfaces.INode"
template="node_target.pt"
class="loops.browser.node.ConfigureView"
permission="zope.ManageContent">
<widget field="description" height="2" />
<widget field="body" height="15" />
</editform>
</page>
<menuItem
for="loops.interfaces.INode"

View file

@ -17,7 +17,7 @@
<metal:body fill-slot="body">
<tal:content define="item view/item;
level level|python: 1;
macro item/macro">
macro item/macro;">
<metal:block use-macro="macro" />
</tal:content>
</metal:body>

View file

@ -26,7 +26,7 @@ from zope.cachedescriptors.property import Lazy
from zope.app import zapi
from zope.app.catalog.interfaces import ICatalog
from zope.app.container.browser.contents import JustContents
from zope.app.event.objectevent import ObjectCreatedEvent
from zope.app.event.objectevent import ObjectCreatedEvent, ObjectModifiedEvent
from zope.app.pagetemplate import ViewPageTemplateFile
from zope.app.intid.interfaces import IIntIds
from zope.dottedname.resolve import resolve
@ -46,7 +46,13 @@ from loops.browser.concept import ConceptView
class NodeView(BaseView):
template = ViewPageTemplateFile('node_macros.pt')
macro = template.macros['content']
@Lazy
def macro(self):
macroName = self.request.get('viewer')
if not macroName:
macroName = self.context.viewer or 'content'
return self.template.macros[macroName]
@Lazy
def item(self):
@ -65,7 +71,11 @@ class NodeView(BaseView):
def textItems(self):
return [NodeView(child, self.request)
for child in self.context.getTextItems()]
@Lazy
def pageItems(self):
return [NodeView(child, self.request)
for child in self.context.getPageItems()]
@Lazy
def nodeType(self):
@ -148,8 +158,9 @@ class NodeView(BaseView):
if target is None:
target = self.targetObject
if target is not None:
name = zapi.getDefaultViewName(target, self.request)
targetView = zapi.getMultiAdapter((target, self.request),
name=zapi.getDefaultViewName(target, self.request))
name=name)
return targetView()
return u''
@ -212,6 +223,7 @@ class ConfigureView(NodeView):
if IConcept.providedBy(target):
target.conceptType = type.typeProvider
notify(ObjectCreatedEvent(target))
notify(ObjectModifiedEvent(target))
self.context.target = target
return True

View file

@ -84,6 +84,21 @@
</metal:body>
<metal:body define-macro="listpages">
<div class="content-1"
tal:define="onclick string:openEditWindow('${view/url}/@@edit.html')"
tal:content="structure view/body"
tal:attributes="ondblclick python: view.editable and onclick or ''">
Listing
</div><br />
<div tal:repeat="item view/pageItems">
<a href="#"
tal:attributes="href item/url"
tal:content="item/title">Item</a>
</div>
</metal:body>
<!-- menu -->
<metal:menu define-macro="menu">

View file

@ -9,7 +9,9 @@
<span tal:content="context/title">Concept Title</span>
<a href="#"
tal:condition="python: context.contentType.startswith('text')"
tal:attributes="href string:${context/@@absolute_url}/external_edit">X</a>
tal:attributes="href string:${context/@@absolute_url}/external_edit"
><img src="edit.gif"
tal:attributes="src context/++resource++edit.gif" border="0" /></a>
</h1><br />
<div tal:define="items view/concepts;

View file

@ -309,13 +309,13 @@ class IView(ILoopsObject):
default=u'',
required=False)
#target = Attribute('Target object that is referenced by this view')
target = Attribute('Target object that is referenced by this view')
target = schema.Choice(
title=_(u'Target'),
description=_(u'The target object of this view or node'),
default=None,
source="loops.targetSource",
viewer = schema.TextLine(
title=_(u'Viewer Method Specification'),
description=_(u'Name, path or relative URI specifying a viewer '
'(template, macro, ...) for this object'),
default=u'',
required=False)
@ -388,6 +388,10 @@ class INode(IView, IBaseNode):
""" Return True if this object is a menu item.
"""
def getPageItems():
""" Return the page items belonging to this object.
"""
def getTextItems():
""" Return the text items belonging to this object.
"""

View file

@ -60,6 +60,11 @@ class View(object):
def setDescription(self, description): self._description = description
description = property(getDescription, setDescription)
_viewer = u''
def getViewer(self): return self._viewer
def setViewer(self, viewer): self._viewer = viewer
viewer = property(getViewer, setViewer)
def getTarget(self):
rels = getRelations(first=self, relationships=[TargetRelation])
if len(rels) == 0:
@ -141,6 +146,9 @@ class Node(View, OrderedContainer):
def getMenuItems(self):
return self.getChildNodes(['page', 'menu'])
def getPageItems(self):
return self.getChildNodes(['page', 'menu', 'info'])
def getTextItems(self):
return self.getChildNodes(['text'])