Some refactoring concerning node configuration and target assignment
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1052 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
15fa9c6a91
commit
4bbf9d4df9
9 changed files with 72 additions and 59 deletions
11
README.txt
11
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())
|
||||
|
|
|
@ -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"
|
||||
/>
|
||||
|
||||
<!-- vocabulary, traversing, and other stuff -->
|
||||
|
||||
<zope:adapter factory="loops.browser.target.TargetTerms"
|
||||
for="loops.target.TargetSourceList
|
||||
zope.publisher.interfaces.browser.IBrowserRequest" />
|
||||
|
||||
<zope:view factory="loops.view.NodeTraverser"
|
||||
for="loops.interfaces.INode"
|
||||
type="zope.publisher.interfaces.browser.IBrowserRequest"
|
||||
provides="zope.publisher.interfaces.browser.IBrowserPublisher"
|
||||
allowed_interface="zope.publisher.interfaces.browser.IBrowserPublisher"
|
||||
permission="zope.Public" />
|
||||
|
||||
</configure>
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -233,22 +233,11 @@
|
|||
<adapter factory="loops.target.ConceptProxy"
|
||||
permission="zope.ManageContent" />
|
||||
|
||||
<adapter factory="loops.browser.target.TargetTerms"
|
||||
for="loops.browser.target.TargetSourceList
|
||||
zope.publisher.interfaces.browser.IBrowserRequest" />
|
||||
|
||||
<vocabulary
|
||||
factory="loops.browser.target.TargetSourceList"
|
||||
factory="loops.target.TargetSourceList"
|
||||
name="loops.targetSource"
|
||||
/>
|
||||
|
||||
<view factory="loops.view.NodeTraverser"
|
||||
for="loops.interfaces.INode"
|
||||
type="zope.publisher.interfaces.browser.IBrowserRequest"
|
||||
provides="zope.publisher.interfaces.browser.IBrowserPublisher"
|
||||
allowed_interface="zope.publisher.interfaces.browser.IBrowserPublisher"
|
||||
permission="zope.Public" />
|
||||
|
||||
<!-- Register various browser related components, including all views -->
|
||||
<include package=".browser" />
|
||||
|
||||
|
|
|
@ -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.
|
||||
"""
|
||||
|
||||
|
||||
|
|
20
target.py
20
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)
|
||||
|
||||
|
||||
|
|
11
util.py
11
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):
|
||||
|
|
12
view.py
12
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':
|
||||
|
|
Loading…
Add table
Reference in a new issue