provide resource standard layout
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@3166 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
edd2b3fbe4
commit
da8c54e0ea
6 changed files with 157 additions and 51 deletions
|
@ -92,7 +92,8 @@ class TargetLayoutInstance(NodeLayoutInstance):
|
|||
return []
|
||||
result = []
|
||||
names = region.layouts.keys()
|
||||
tp = target.context.conceptType
|
||||
#tp = target.context.conceptType
|
||||
tp = target.context.getType()
|
||||
for n in tp.getClients():
|
||||
if n.nodeType == 'info' and n.viewName in names:
|
||||
if pageName != n.pageName:
|
||||
|
|
85
layout/browser/base.py
Normal file
85
layout/browser/base.py
Normal file
|
@ -0,0 +1,85 @@
|
|||
#
|
||||
# Copyright (c) 2009 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
|
||||
#
|
||||
|
||||
"""
|
||||
Base classes for layout-based views.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
from zope import component
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.proxy import removeAllProxies
|
||||
from zope.traversing.browser import absoluteURL
|
||||
|
||||
from loops.common import adapted
|
||||
from loops.i18n.browser import LanguageInfo
|
||||
from loops import util
|
||||
|
||||
|
||||
class BaseView(object):
|
||||
|
||||
def __init__(self, context, request):
|
||||
self.context = context # this is the adapted concept!
|
||||
self.request = request
|
||||
|
||||
@Lazy
|
||||
def title(self):
|
||||
return self.context.title
|
||||
|
||||
@Lazy
|
||||
def description(self):
|
||||
return self.context.description
|
||||
|
||||
@Lazy
|
||||
def uid(self):
|
||||
return util.getUidForObject(self.context.context)
|
||||
|
||||
@Lazy
|
||||
def menu(self):
|
||||
return self.node.getMenu()
|
||||
|
||||
@Lazy
|
||||
def url(self):
|
||||
return '%s/.%s-%s' % (absoluteURL(self.menu, self.request),
|
||||
self.context.uid, normalize(self.context.title))
|
||||
|
||||
def requireDojo(self, *packages):
|
||||
# TODO: make sure dojo and dojo_require are displayed in page.js
|
||||
djInfo = self.request.annotations.setdefault('ajax.dojo', {})
|
||||
requirements = djInfo.setdefault('requirements', set())
|
||||
for p in packages:
|
||||
requirements.add(p)
|
||||
|
||||
def renderText(self, text, contentType):
|
||||
typeKey = util.renderingFactories.get(contentType, None)
|
||||
if typeKey is None:
|
||||
if contentType == u'text/html':
|
||||
return util.toUnicode(text)
|
||||
return u'<pre>%s</pre>' % util.html_quote(util.toUnicode(text))
|
||||
source = component.createObject(typeKey, text)
|
||||
view = component.getMultiAdapter((removeAllProxies(source), self.request))
|
||||
return view.render()
|
||||
|
||||
|
||||
pattern = re.compile(r'[ /\?\+%]')
|
||||
|
||||
def normalize(text):
|
||||
return pattern.sub('-', text)
|
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
|
||||
# Copyright (c) 2009 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
|
||||
|
@ -29,39 +29,14 @@ from zope.cachedescriptors.property import Lazy
|
|||
from zope.proxy import removeAllProxies
|
||||
from zope.traversing.browser import absoluteURL
|
||||
|
||||
from loops.browser.common import BaseView
|
||||
from loops.common import adapted
|
||||
from loops.i18n.browser import LanguageInfo
|
||||
from loops.interfaces import IConcept
|
||||
from loops.layout.browser.base import BaseView
|
||||
from loops import util
|
||||
|
||||
|
||||
class ConceptView(object):
|
||||
|
||||
def __init__(self, context, request):
|
||||
self.context = context # this is the adapted concept!
|
||||
self.request = request
|
||||
|
||||
@Lazy
|
||||
def title(self):
|
||||
return self.context.title
|
||||
|
||||
@Lazy
|
||||
def description(self):
|
||||
return self.context.description
|
||||
|
||||
@Lazy
|
||||
def uid(self):
|
||||
return util.getUidForObject(self.context.context)
|
||||
|
||||
@Lazy
|
||||
def menu(self):
|
||||
return self.node.getMenu()
|
||||
|
||||
@Lazy
|
||||
def url(self):
|
||||
return '%s/.%s-%s' % (absoluteURL(self.menu, self.request),
|
||||
self.context.uid, normalize(self.context.title))
|
||||
class ConceptView(BaseView):
|
||||
|
||||
@property
|
||||
def children(self):
|
||||
|
@ -70,25 +45,3 @@ class ConceptView(object):
|
|||
view.node = self.node
|
||||
yield view
|
||||
|
||||
def requireDojo(self, *packages):
|
||||
# TODO: make sure dojo and dojo_require are displayed in page.js
|
||||
djInfo = self.request.annotations.setdefault('ajax.dojo', {})
|
||||
requirements = djInfo.setdefault('requirements', set())
|
||||
for p in packages:
|
||||
requirements.add(p)
|
||||
|
||||
def renderText(self, text, contentType):
|
||||
typeKey = util.renderingFactories.get(contentType, None)
|
||||
if typeKey is None:
|
||||
if contentType == u'text/html':
|
||||
return util.toUnicode(text)
|
||||
return u'<pre>%s</pre>' % util.html_quote(util.toUnicode(text))
|
||||
source = component.createObject(typeKey, text)
|
||||
view = component.getMultiAdapter((removeAllProxies(source), self.request))
|
||||
return view.render()
|
||||
|
||||
|
||||
pattern = re.compile(r'[ /\?\+%]')
|
||||
|
||||
def normalize(text):
|
||||
return pattern.sub('-', text)
|
||||
|
|
|
@ -53,6 +53,13 @@
|
|||
provides="zope.interface.Interface"
|
||||
factory="loops.layout.browser.concept.ConceptView" />
|
||||
|
||||
<zope:adapter
|
||||
name="layout"
|
||||
for="loops.interfaces.ITextDocument
|
||||
zope.publisher.interfaces.browser.IBrowserRequest"
|
||||
provides="zope.interface.Interface"
|
||||
factory="loops.layout.browser.resource.TextView" />
|
||||
|
||||
<!-- traversal adapter -->
|
||||
|
||||
<zope:view factory="loops.layout.browser.traversal.NodeTraverser"
|
||||
|
@ -62,4 +69,8 @@
|
|||
allowed_interface="zope.publisher.interfaces.browser.IBrowserPublisher"
|
||||
permission="zope.Public" />
|
||||
|
||||
<!-- layouts -->
|
||||
|
||||
<zope:module module="loops.layout.browser.resource" />
|
||||
|
||||
</configure>
|
||||
|
|
4
layout/browser/resource.pt
Normal file
4
layout/browser/resource.pt
Normal file
|
@ -0,0 +1,4 @@
|
|||
<metal:macro define-macro="text"
|
||||
tal:define="target nocall:view/context/targetView">
|
||||
<div tal:content="structure target/render" />
|
||||
</metal:macro>
|
52
layout/browser/resource.py
Normal file
52
layout/browser/resource.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
#
|
||||
# Copyright (c) 2009 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-based concept views.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
from zope import component
|
||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.proxy import removeAllProxies
|
||||
from zope.traversing.browser import absoluteURL
|
||||
|
||||
from cybertools.browser.renderer import RendererFactory
|
||||
from cybertools.composer.layout.base import Layout
|
||||
from loops.common import adapted
|
||||
from loops.i18n.browser import LanguageInfo
|
||||
from loops.interfaces import IConcept
|
||||
from loops.layout.browser.base import BaseView
|
||||
from loops import util
|
||||
|
||||
|
||||
resourceRenderers = RendererFactory(ViewPageTemplateFile('resource.pt'))
|
||||
|
||||
|
||||
Layout('text.standard', 'center.content',
|
||||
renderer=resourceRenderers.text, instanceName='target')
|
||||
|
||||
|
||||
class TextView(BaseView):
|
||||
|
||||
def render(self):
|
||||
return self.renderText(self.context.data, self.context.contentType)
|
Loading…
Add table
Reference in a new issue