diff --git a/README.txt b/README.txt index 045d1d3..f70ab0d 100755 --- a/README.txt +++ b/README.txt @@ -9,6 +9,7 @@ loops - Linked Objects for Organization and Processing Services >>> from zope.app import zapi >>> from zope.app.tests import ztapi + >>> from zope.interface import Interface >>> from zope.publisher.browser import TestRequest @@ -291,6 +292,15 @@ target may be moved or renamed without any problems.) >>> m111 in doc1.getClients() 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 edit form provided by the node: diff --git a/browser/configure.zcml b/browser/configure.zcml index db1171b..5110c4b 100644 --- a/browser/configure.zcml +++ b/browser/configure.zcml @@ -308,9 +308,10 @@ label="Configure Node" name="configure.html" schema="loops.interfaces.INodeConfigSchema" - fields="title description nodeType targetType targetUri createTarget" + fields="title description nodeType targetUri targetType createTarget" for="loops.interfaces.INode" template="edit.pt" + class="loops.browser.node.ConfigureView" permission="zope.ManageContent" menu="zmi_views" title="Configure"> diff --git a/browser/node.py b/browser/node.py index 4080d7b..137ad17 100644 --- a/browser/node.py +++ b/browser/node.py @@ -94,6 +94,33 @@ class NodeView(object): 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): """ A view providing the necessary methods for moving sub-objects within an ordered container. diff --git a/view.py b/view.py index ca63d9e..80666f6 100644 --- a/view.py +++ b/view.py @@ -166,7 +166,7 @@ class NodeConfigAdapter(object): def __init__(self, context): self.context = removeSecurityProxy(context) - #self.context = context + self._targetType = None implements(INodeConfigSchema) adapts(INode) @@ -208,9 +208,17 @@ class NodeConfigAdapter(object): def getTargetType(self): 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): - pass + self._targetType = tt # to be able to use it in setCreateTarget() 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) +