Basic form/view set-up for configuring a node (including target creation)
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1032 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
e18410e0ac
commit
2f8d17e0f7
4 changed files with 51 additions and 5 deletions
10
README.txt
10
README.txt
|
@ -9,6 +9,7 @@ loops - Linked Objects for Organization and Processing Services
|
||||||
|
|
||||||
>>> from zope.app import zapi
|
>>> from zope.app import zapi
|
||||||
>>> from zope.app.tests import ztapi
|
>>> from zope.app.tests import ztapi
|
||||||
|
>>> from zope.interface import Interface
|
||||||
>>> from zope.publisher.browser import TestRequest
|
>>> from zope.publisher.browser import TestRequest
|
||||||
|
|
||||||
|
|
||||||
|
@ -291,6 +292,15 @@ target may be moved or renamed without any problems.)
|
||||||
>>> m111 in doc1.getClients()
|
>>> m111 in doc1.getClients()
|
||||||
True
|
True
|
||||||
|
|
||||||
|
There is a special edit view class that can be used to configure a node
|
||||||
|
in a way, that allows the creation of a target object on the fly.
|
||||||
|
(We here use the base class providing the method for this action; the real
|
||||||
|
application uses a subclass that does all the other stuff for form handling.)
|
||||||
|
|
||||||
|
>>> from loops.browser.node import ConfigureBaseView
|
||||||
|
>>> view = ConfigureBaseView(INodeConfigSchema(m111), TestRequest())
|
||||||
|
>>> view.checkCreateTarget()
|
||||||
|
|
||||||
It is also possible to edit a target's attributes directly in an
|
It is also possible to edit a target's attributes directly in an
|
||||||
edit form provided by the node:
|
edit form provided by the node:
|
||||||
|
|
||||||
|
|
|
@ -308,9 +308,10 @@
|
||||||
label="Configure Node"
|
label="Configure Node"
|
||||||
name="configure.html"
|
name="configure.html"
|
||||||
schema="loops.interfaces.INodeConfigSchema"
|
schema="loops.interfaces.INodeConfigSchema"
|
||||||
fields="title description nodeType targetType targetUri createTarget"
|
fields="title description nodeType targetUri targetType createTarget"
|
||||||
for="loops.interfaces.INode"
|
for="loops.interfaces.INode"
|
||||||
template="edit.pt"
|
template="edit.pt"
|
||||||
|
class="loops.browser.node.ConfigureView"
|
||||||
permission="zope.ManageContent"
|
permission="zope.ManageContent"
|
||||||
menu="zmi_views" title="Configure">
|
menu="zmi_views" title="Configure">
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,33 @@ class NodeView(object):
|
||||||
return item.context == self.context
|
return item.context == self.context
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigureBaseView(object):
|
||||||
|
""" Helper view object for editing/configuring a node, providing the
|
||||||
|
stuff needed for creating a target object.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, context, request):
|
||||||
|
self.context = context
|
||||||
|
self.request = request
|
||||||
|
|
||||||
|
def checkCreateTarget(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigureView(object):
|
||||||
|
""" An editing view for configuring a node, optionally creating
|
||||||
|
a target object.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, context, request):
|
||||||
|
super(ConfigureView, self).__init__(context, request)
|
||||||
|
self.delegate = ConfigureBaseView(context, request)
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
self.delegate.checkCreateTarget()
|
||||||
|
return super(ConfigureView, self).update()
|
||||||
|
|
||||||
|
|
||||||
class OrderedContainerView(JustContents):
|
class OrderedContainerView(JustContents):
|
||||||
""" A view providing the necessary methods for moving sub-objects
|
""" A view providing the necessary methods for moving sub-objects
|
||||||
within an ordered container.
|
within an ordered container.
|
||||||
|
|
16
view.py
16
view.py
|
@ -166,7 +166,7 @@ class NodeConfigAdapter(object):
|
||||||
|
|
||||||
def __init__(self, context):
|
def __init__(self, context):
|
||||||
self.context = removeSecurityProxy(context)
|
self.context = removeSecurityProxy(context)
|
||||||
#self.context = context
|
self._targetType = None
|
||||||
|
|
||||||
implements(INodeConfigSchema)
|
implements(INodeConfigSchema)
|
||||||
adapts(INode)
|
adapts(INode)
|
||||||
|
@ -208,9 +208,17 @@ class NodeConfigAdapter(object):
|
||||||
|
|
||||||
def getTargetType(self):
|
def getTargetType(self):
|
||||||
target = self.context.target
|
target = self.context.target
|
||||||
return '%s.%s' % (target.__module__, target.__class__.__name__)
|
if target:
|
||||||
|
return '%s.%s' % (target.__module__, target.__class__.__name__)
|
||||||
|
return None
|
||||||
def setTargetType(self, tt):
|
def setTargetType(self, tt):
|
||||||
pass
|
self._targetType = tt # to be able to use it in setCreateTarget()
|
||||||
targetType = property(getTargetType, setTargetType)
|
targetType = property(getTargetType, setTargetType)
|
||||||
|
|
||||||
|
def setCreateTarget(self, value):
|
||||||
|
if value:
|
||||||
|
print 'targetType:', self._targetType or self.targetType
|
||||||
|
def getCreateTarget(self): return False
|
||||||
|
createTarget = property(getCreateTarget, setCreateTarget)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue