diff --git a/README.txt b/README.txt
index a116d0b..af08259 100755
--- a/README.txt
+++ b/README.txt
@@ -274,12 +274,9 @@ Node Views
Node Schema Adapters
--------------------
-When creating or editing (more precisely: configuring) a node you may
+When configuring a node you may
specify what you want to do with respect to the node's target: associate
-an existing one or create a new one (with specifying the target's type),
-and give an URI that will be used to identify the target. (Internally
-the reference to the target will be stored as a relation so that the
-target may be moved or renamed without any problems.)
+an existing one or create a new one.
>>> from loops.interfaces import INodeConfigSchema
>>> from loops.view import NodeConfigAdapter
@@ -293,7 +290,7 @@ target may be moved or renamed without any problems.)
u'New title for m111'
>>> m111.title
u'New title for m111'
- >>> nodeConfig.targetUri = '.loops/resources/doc1'
+ >>> nodeConfig.target = doc1
>>> m111.target is doc1
True
>>> nodeConfig.targetType
@@ -305,6 +302,8 @@ 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.)
+When creating a new target object you may specify a uri that determines
+the location of the new target object and its name.
>>> from loops.browser.node import ConfigureBaseView
>>> view = ConfigureBaseView(INodeConfigSchema(m111), TestRequest())
diff --git a/browser/configure.zcml b/browser/configure.zcml
index ed06b9a..0e1ff43 100644
--- a/browser/configure.zcml
+++ b/browser/configure.zcml
@@ -309,7 +309,7 @@
label="Edit Node"
name="edit.html"
schema="loops.interfaces.INode"
- fields="title description nodeType body target"
+ fields="title description nodeType body"
for="loops.interfaces.INode"
template="edit.pt"
permission="zope.ManageContent"
@@ -330,7 +330,7 @@
label="Configure Node"
name="configure.html"
schema="loops.interfaces.INodeConfigSchema"
- fields="title description nodeType targetUri targetType createTarget"
+ fields="title description nodeType target createTarget targetUri targetType"
for="loops.interfaces.INode"
template="edit.pt"
class="loops.browser.node.ConfigureView"
@@ -409,4 +409,17 @@
name="node.html"
/>
+
+
+
+
+
+
diff --git a/browser/node.py b/browser/node.py
index 4d2dbee..af49dc7 100644
--- a/browser/node.py
+++ b/browser/node.py
@@ -163,7 +163,8 @@ class ConfigureBaseView(object):
target = container[name]
# set possibly new targetUri in request for further processing:
targetUri = self.loopsRoot.getLoopsUri(target)
- form['field.targetUri'] = targetUri
+ #form['field.targetUri'] = targetUri
+ form['field.target'] = targetUri
return target
diff --git a/browser/target.py b/browser/target.py
index 5100ec3..f4d79e7 100644
--- a/browser/target.py
+++ b/browser/target.py
@@ -25,24 +25,18 @@ $Id$
from zope.app import zapi
from zope.app.form.browser.interfaces import ITerms
-from zope.schema.interfaces import IIterableSource
+from zope.schema.vocabulary import SimpleTerm
from zope.cachedescriptors.property import Lazy
from zope.interface import implements
from zope.security.proxy import removeSecurityProxy
-class Term(object):
-
- def __init__(self, **kw):
- self.__dict__.update(kw)
-
-
class TargetTerms(object):
implements(ITerms)
def __init__(self, context, request):
- self.context = context.context
+ self.context = context.context # the context parameter is the source object
self.request = request
@Lazy
@@ -51,26 +45,8 @@ class TargetTerms(object):
def getTerm(self, value):
token = self.loopsRoot.getLoopsUri(value)
- #token = value.getLoopsRoot().getLoopsUri(value)
- title = value.title
- return Term(title=title, token=token)
+ return SimpleTerm(value, token, value.title)
def getValue(self, token):
return self.loopsRoot.loopsTraverse(token)
-
-class TargetSourceList(object):
-
- implements(IIterableSource)
-
- def __init__(self, context):
- self.context = removeSecurityProxy(context)
- self.resources = self.context.getLoopsRoot()['resources']
-
- def __iter__(self):
- return iter(self.resources.values())
-
- def __len__():
- return len(self.resources)
-
-
diff --git a/configure.zcml b/configure.zcml
index 84af746..ed83f8b 100644
--- a/configure.zcml
+++ b/configure.zcml
@@ -233,22 +233,11 @@
-
-
-
-
diff --git a/interfaces.py b/interfaces.py
index b03543c..2b974bc 100644
--- a/interfaces.py
+++ b/interfaces.py
@@ -31,6 +31,8 @@ from zope.app.file.interfaces import IImage as IBaseAsset
from zope.app.folder.interfaces import IFolder
from cybertools.relation.interfaces import IRelation
+import util
+
_ = MessageFactory('loops')
@@ -258,7 +260,7 @@ class IBaseNode(IOrderedContainer):
def getLoopsRoot():
""" Return the loops root object.
"""
-
+
class INode(IView, IBaseNode):
""" A node is a view that may contain other views, thus building a
@@ -272,7 +274,12 @@ class INode(IView, IBaseNode):
nodeType = schema.Choice(
title=_(u'Node Type'),
description=_(u'Type of the node'),
- values=('text', 'page', 'menu', 'info'),
+ source=util.KeywordVocabulary((
+ ('text', _(u'Text')),
+ ('page', _(u'Page')),
+ ('menu', _(u'Menu')),
+ ('info', _(u'Info')),
+ )),
default='info',
required=True)
@@ -312,8 +319,7 @@ class INode(IView, IBaseNode):
"""
def getTextItems():
- """ Return the menu items belonging to this object (that should be
- a menu).
+ """ Return the text items belonging to this object.
"""
diff --git a/target.py b/target.py
index cd147e8..f186d91 100644
--- a/target.py
+++ b/target.py
@@ -27,6 +27,7 @@ from zope.app import zapi
from zope.cachedescriptors.property import Lazy
from zope.component import adapts
from zope.interface import implements
+from zope import schema
from zope.security.proxy import removeSecurityProxy
from loops.interfaces import IResource
@@ -36,6 +37,8 @@ from loops.interfaces import IView
from loops.interfaces import IConcept, IConceptView
+# proxies for accessing target objects from views/nodes
+
class ConceptProxy(object):
implements(IConcept)
@@ -98,3 +101,20 @@ class MediaAssetProxy(ResourceProxy):
data = property(getData, setData)
+# source classes for target vocabularies
+
+class TargetSourceList(object):
+
+ implements(schema.interfaces.IIterableSource)
+
+ def __init__(self, context):
+ self.context = removeSecurityProxy(context)
+ self.resources = self.context.getLoopsRoot()['resources']
+
+ def __iter__(self):
+ return iter(self.resources.values())
+
+ def __len__():
+ return len(self.resources)
+
+
diff --git a/util.py b/util.py
index a72ed06..30c6e61 100644
--- a/util.py
+++ b/util.py
@@ -23,7 +23,16 @@ $Id$
"""
from zope.interface import directlyProvides, directlyProvidedBy
-from view import TargetRelation
+from zope.schema import vocabulary
+#from view import TargetRelation
+
+
+class KeywordVocabulary(vocabulary.SimpleVocabulary):
+
+ def __init__(self, items, *interfaces):
+ terms = [vocabulary.SimpleTerm(token, token, title)
+ for token, title in items]
+ super(KeywordVocabulary, self).__init__(terms, *interfaces)
def removeTargetRelation(context, event):
diff --git a/view.py b/view.py
index 5c4714c..7f482d9 100644
--- a/view.py
+++ b/view.py
@@ -71,11 +71,10 @@ class View(object):
rels = list(registry.query(first=self, relationship=TargetRelation))
if len(rels) > 0:
oldRel = rels[0]
- if oldRel.second is target:
+ if oldRel.second == target:
return
else:
registry.unregister(oldRel)
-
if target:
targetSchema = target.proxyInterface
rel = TargetRelation(self, target)
@@ -196,15 +195,15 @@ class NodeConfigAdapter(object):
def setNodeType(self, nodeType): self.context.nodeType = nodeType
nodeType = property(getNodeType, setNodeType)
+ def getTarget(self): return self.context.target
+ def setTarget(self, target): self.context.target = target
+ target = property(getTarget, setTarget)
+
# the real config stuff:
@Lazy
def loopsRoot(self): return self.context.getLoopsRoot()
- @readproperty
- def target(self):
- return self.context.target
-
def getTargetUri(self):
target = self.target
if target is not None:
@@ -213,6 +212,7 @@ class NodeConfigAdapter(object):
return ''
def setTargetUri(self, uri):
+ return # ignore - only relevant for target creation
if uri:
names = uri.split('/')
if names[0] == '.loops':