diff --git a/browser/README.txt b/browser/README.txt index af72845..dc02bbc 100644 --- a/browser/README.txt +++ b/browser/README.txt @@ -5,7 +5,7 @@ We first set up a test and working environment: >>> from zope.app import zapi >>> from zope.app.testing import ztapi - + >>> from zope import component, interface >>> from zope.publisher.browser import TestRequest >>> from zope.publisher.interfaces.browser import IBrowserRequest @@ -26,17 +26,16 @@ because this already provides some predefined stuff: Before creating a controller we have to set up a context object and a view: - + >>> class SomeObject(object): pass >>> obj = SomeObject() - >>> class View(object): - ... def __init__(self, context, request): - ... self.context = context - ... self.request = request + >>> from cybertools.browser.view import GenericView + >>> class View(GenericView): + ... pass >>> from zope.publisher.browser import TestRequest >>> request = TestRequest() >>> view = View(obj, request) - + >>> controller = Controller(view, request) >>> controller.view is view True @@ -44,6 +43,8 @@ a view: True >>> controller.request is request True + >>> request.annotations['cybertools.browser']['controller'] == controller + True The controller registers itself with the view: diff --git a/browser/configure.zcml b/browser/configure.zcml index ca2746c..f7a61f3 100644 --- a/browser/configure.zcml +++ b/browser/configure.zcml @@ -6,6 +6,24 @@ i18n_domain="zope" > + + + + + + + +
+
+ +
+
+ + + +
+
+
+ + + + + +
+ +
+ + +
+ + + + diff --git a/browser/liquid/configure.zcml b/browser/liquid/configure.zcml index 8cebc26..d902568 100644 --- a/browser/liquid/configure.zcml +++ b/browser/liquid/configure.zcml @@ -11,7 +11,7 @@ - + + resourceBase controller/resourceBase;"> @@ -29,7 +29,8 @@ tal:attributes="href string:${resourceBase}favicon.png" /> - +
diff --git a/browser/main.pt b/browser/main.pt new file mode 100644 index 0000000..1fda407 --- /dev/null +++ b/browser/main.pt @@ -0,0 +1,31 @@ + + + + + + Powered by Zope 3 + + + + + + + + + + + + + + + + + + + diff --git a/browser/view.py b/browser/view.py new file mode 100644 index 0000000..831ce37 --- /dev/null +++ b/browser/view.py @@ -0,0 +1,86 @@ +# +# Copyright (c) 2006 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 +# + +""" +A generic view class. + +$Id$ +""" + +from zope import component +from zope.interface import Interface, implements +from zope.cachedescriptors.property import Lazy +from zope.publisher.interfaces.browser import ISkin +from zope.app.pagetemplate import ViewPageTemplateFile + + +class UnboundTemplateFile(ViewPageTemplateFile): + + def __get__(self, instance, type): + return self + + +class GenericView(object): + + index = ViewPageTemplateFile('main.pt') + bodyTemplate = UnboundTemplateFile('liquid/body.pt') + + menu = macro = skin = None + + def setController(self, controller): + # make the (one and only controller) available via the request + viewAnnotations = self.request.annotations.setdefault('cybertools.browser', {}) + viewAnnotations['controller'] = controller + if getattr(controller, 'skinName', None): + self.setSkin(controller.skinName.value) + controller.skin = self.skin + # this is the place to register special macros with the controller: + self.setupController() + def getController(self): + viewAnnotations = self.request.annotations.setdefault('cybertools.browser', {}) + return viewAnnotations.get('controller', None) + controller = property(getController, setController) + + def __init__(self, context, request): + self.context = context + self.request = request + + def __call__(self, *args, **kw): + return self.index(*args, **kw) + + def setupController(self): + pass + + def pageBody(self): + template = component.getMultiAdapter((self.context, self.request), + name='body.html').bodyTemplate + return template(self) + + def setSkin(self, skinName): + skin = None + if skinName: + skin = component.queryUtility(ISkin, skinName) + if skin: + applySkin(self.request, skin) + self.skin = skin + + @Lazy + def item(self): + return self + +