add new layout sub-package
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2862 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
dbbd37e63a
commit
fee8b42366
9 changed files with 148 additions and 22 deletions
|
@ -513,6 +513,8 @@ class BaseView(GenericView, I18NView):
|
|||
def registerDojoFormAll(self):
|
||||
self.registerDojo()
|
||||
jsCall = ('dojo.require("dijit.form.Form"); '
|
||||
'dojo.require("dijit.form.DateTextBox"); '
|
||||
'dojo.require("dijit.form.TimeTextBox");'
|
||||
'dojo.require("dijit.form.FilteringSelect"); '
|
||||
'dojo.require("dojox.data.QueryReadStore");')
|
||||
self.controller.macros.register('js-execute', 'dojo.form.all', jsCall=jsCall)
|
||||
|
@ -520,6 +522,26 @@ class BaseView(GenericView, I18NView):
|
|||
|
||||
# vocabulary stuff
|
||||
|
||||
class SimpleTerms(object):
|
||||
""" Provide the ITerms interface, e.g. for usage in selection
|
||||
lists.
|
||||
"""
|
||||
|
||||
implements(ITerms)
|
||||
|
||||
def __init__(self, source, request):
|
||||
# the source parameter is a list of tuples (token, title).
|
||||
self.source = source
|
||||
self.terms = dict(source)
|
||||
|
||||
def getTerm(self, value):
|
||||
token, title = value
|
||||
return SimpleTerm(token, token, title)
|
||||
|
||||
def getValue(self, token):
|
||||
return (token, self.terms[token])
|
||||
|
||||
|
||||
class LoopsTerms(object):
|
||||
""" Provide the ITerms interface, e.g. for usage in selection
|
||||
lists.
|
||||
|
|
|
@ -722,6 +722,10 @@
|
|||
for="loops.resource.ResourceTypeSourceList
|
||||
zope.publisher.interfaces.browser.IBrowserRequest" />
|
||||
|
||||
<zope:adapter factory="loops.browser.common.SimpleTerms"
|
||||
for="loops.view.NodeTypeSourceList
|
||||
zope.publisher.interfaces.browser.IBrowserRequest" />
|
||||
|
||||
<zope:view factory="loops.browser.node.NodeTraverser"
|
||||
for="loops.interfaces.INode"
|
||||
type="zope.publisher.interfaces.http.IHTTPRequest"
|
||||
|
|
4
browser/layout/__init__.py
Normal file
4
browser/layout/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
"""
|
||||
$Id$
|
||||
"""
|
||||
|
21
browser/layout/configure.zcml
Normal file
21
browser/layout/configure.zcml
Normal file
|
@ -0,0 +1,21 @@
|
|||
<!-- $Id$ -->
|
||||
|
||||
<configure
|
||||
xmlns:zope="http://namespaces.zope.org/zope"
|
||||
xmlns:browser="http://namespaces.zope.org/browser"
|
||||
i18n_domain="loops">
|
||||
|
||||
<!-- views -->
|
||||
|
||||
<zope:adapter
|
||||
name="layout"
|
||||
factory="loops.browser.layout.node.NodeLayoutProvider"
|
||||
permission="zope.View"
|
||||
/>
|
||||
|
||||
<zope:adapter
|
||||
factory="loops.browser.layout.node.NodeLayout"
|
||||
permission="zope.View"
|
||||
/>
|
||||
|
||||
</configure>
|
49
browser/layout/node.py
Normal file
49
browser/layout/node.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
#
|
||||
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
"""
|
||||
Layout management and controlling via view space nodes.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.component import adapts
|
||||
from zope.interface import implements
|
||||
|
||||
from cybertools.composer.layout.interfaces import ILayout
|
||||
from loops.interfaces import INode
|
||||
from loops.view import nodeTypes, NodeAdapter
|
||||
|
||||
|
||||
nodeTypes.append(('layout', 'Layout'))
|
||||
|
||||
|
||||
class NodeLayoutProvider(NodeAdapter):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class NodeLayout(object):
|
||||
|
||||
implements(ILayout)
|
||||
adapts(INode)
|
||||
|
||||
def __init__(self, context):
|
||||
self.context = context
|
||||
|
|
@ -419,8 +419,14 @@
|
|||
component="loops.predicate.PredicateInterfaceSourceList"
|
||||
name="loops.PredicateInterfaceSource" />
|
||||
|
||||
<utility
|
||||
provides="zope.schema.interfaces.IVocabularyFactory"
|
||||
component="loops.view.NodeTypeSourceList"
|
||||
name="loops.nodeTypeSource" />
|
||||
|
||||
|
||||
<include package=".browser" />
|
||||
<include package=".browser.layout" />
|
||||
<include package=".classifier" />
|
||||
<include package=".compound.blog" />
|
||||
<include package=".config" />
|
||||
|
|
|
@ -433,12 +433,7 @@ class INodeSchema(IView):
|
|||
nodeType = schema.Choice(
|
||||
title=_(u'Node Type'),
|
||||
description=_(u'Type of the node'),
|
||||
source=util.KeywordVocabulary((
|
||||
('text', _(u'Text')),
|
||||
('page', _(u'Page')),
|
||||
('menu', _(u'Menu')),
|
||||
('info', _(u'Info')),
|
||||
)),
|
||||
source='loops.nodeTypeSource',
|
||||
default='info',
|
||||
required=True)
|
||||
|
||||
|
|
1
util.py
1
util.py
|
@ -33,7 +33,6 @@ import cybertools
|
|||
from loops.browser.util import html_quote
|
||||
|
||||
_ = MessageFactory('loops')
|
||||
#_ = MessageFactory('zope') # it's easier not use a special i18n domain?
|
||||
|
||||
|
||||
renderingFactories = {
|
||||
|
|
56
view.py
56
view.py
|
@ -23,7 +23,6 @@ $Id$
|
|||
"""
|
||||
|
||||
from zope import component
|
||||
from zope.app import zapi
|
||||
from zope.app.container.btree import BTreeContainer
|
||||
from zope.app.container.contained import Contained
|
||||
from zope.app.container.ordered import OrderedContainer
|
||||
|
@ -33,13 +32,15 @@ from zope.component import adapts
|
|||
from zope.interface import implements
|
||||
from zope.interface import alsoProvides, directlyProvides, directlyProvidedBy
|
||||
from zope.publisher.browser import applySkin
|
||||
from zope import schema
|
||||
from zope.security.proxy import removeSecurityProxy
|
||||
from zope.traversing.api import getName, getParent
|
||||
from persistent import Persistent
|
||||
|
||||
from cybertools.relation import DyadicRelation
|
||||
from cybertools.relation.registry import getRelations
|
||||
from cybertools.relation.interfaces import IRelationRegistry, IRelatable
|
||||
from cybertools.util.jeep import Jeep
|
||||
|
||||
from loops.base import ParentInfo
|
||||
from loops.common import AdapterBase
|
||||
from loops.interfaces import IView, INode, INodeSchema, INodeAdapter
|
||||
|
@ -49,12 +50,18 @@ from loops.interfaces import ITargetRelation
|
|||
from loops.interfaces import IConcept
|
||||
from loops.versioning.util import getVersion
|
||||
from loops import util
|
||||
from loops.util import _
|
||||
|
||||
|
||||
class View(object):
|
||||
|
||||
implements(IView, INodeContained, IRelatable)
|
||||
|
||||
def __init__(self, title=u'', description=u''):
|
||||
self.title = title
|
||||
self.description = description
|
||||
super(View, self).__init__()
|
||||
|
||||
_title = u''
|
||||
def getTitle(self): return self._title
|
||||
def setTitle(self, title): self._title = title
|
||||
|
@ -66,10 +73,10 @@ class View(object):
|
|||
description = property(getDescription, setDescription)
|
||||
|
||||
_viewName = u''
|
||||
def getViewName(self): return self._viewName #or getattr(self, '_viewer', u'')
|
||||
def getViewName(self):
|
||||
return self._viewName
|
||||
def setViewName(self, viewName):
|
||||
self._viewName = viewName
|
||||
#self._viewer = u'' # BBB
|
||||
viewName = property(getViewName, setViewName)
|
||||
|
||||
def getTarget(self):
|
||||
|
@ -78,11 +85,11 @@ class View(object):
|
|||
return None
|
||||
if len(rels) > 1:
|
||||
raise ValueError('There may be only one target for a View object: %s - %s'
|
||||
% (zapi.getName(self), `[zapi.getName(r.second) for r in rels]`))
|
||||
% (getName(self), `[getName(r.second) for r in rels]`))
|
||||
return list(rels)[0].second
|
||||
|
||||
def setTarget(self, target):
|
||||
registry = zapi.getUtility(IRelationRegistry)
|
||||
registry = component.getUtility(IRelationRegistry)
|
||||
rels = list(registry.query(first=self, relationship=TargetRelation))
|
||||
if len(rels) > 0:
|
||||
oldRel = rels[0]
|
||||
|
@ -98,13 +105,8 @@ class View(object):
|
|||
|
||||
target = property(getTarget, setTarget)
|
||||
|
||||
def __init__(self, title=u'', description=u''):
|
||||
self.title = title
|
||||
self.description = description
|
||||
super(View, self).__init__()
|
||||
|
||||
def getLoopsRoot(self):
|
||||
return zapi.getParent(self).getLoopsRoot()
|
||||
return getParent(self).getLoopsRoot()
|
||||
|
||||
def getAllParents(self, collectGrants=False):
|
||||
return Jeep()
|
||||
|
@ -127,11 +129,11 @@ class Node(View, OrderedContainer):
|
|||
contentType = u'zope.source.rest'
|
||||
|
||||
def getParentNode(self, nodeTypes=None):
|
||||
parent = zapi.getParent(self)
|
||||
parent = getParent(self)
|
||||
while INode.providedBy(parent):
|
||||
if not nodeTypes or parent.nodeType in nodeTypes:
|
||||
return parent
|
||||
parent = zapi.getParent(parent)
|
||||
parent = getParent(parent)
|
||||
return None
|
||||
|
||||
def getAllParents(self, collectGrants=False):
|
||||
|
@ -179,7 +181,7 @@ class ViewManager(OrderedContainer):
|
|||
implements(IViewManager, ILoopsContained)
|
||||
|
||||
def getLoopsRoot(self):
|
||||
return zapi.getParent(self)
|
||||
return getParent(self)
|
||||
|
||||
def getViewManager(self):
|
||||
return self
|
||||
|
@ -206,3 +208,27 @@ class NodeAdapter(AdapterBase):
|
|||
adapts(INode)
|
||||
|
||||
_contextAttributes = ('title', 'description', 'body',)
|
||||
|
||||
|
||||
nodeTypes = [
|
||||
('text', _(u'Text')), # shown as part of an enclosing page
|
||||
('page', _(u'Page')), # standalone page with a menu item
|
||||
('menu', _(u'Menu')), # top-level menu (also a page)
|
||||
('info', _(u'Info')), # not shown automatically, but may be a link target
|
||||
]
|
||||
|
||||
class NodeTypeSourceList(object):
|
||||
|
||||
implements(schema.interfaces.IIterableSource)
|
||||
|
||||
def __init__(self, context):
|
||||
self.context = context
|
||||
|
||||
def __contains__(self, token):
|
||||
return token in [t[0] for t in nodeTypes]
|
||||
|
||||
def __iter__(self):
|
||||
return iter(nodeTypes)
|
||||
|
||||
def __len__(self):
|
||||
return len(nodeTypes)
|
||||
|
|
Loading…
Add table
Reference in a new issue