[Checkins] SVN: grok/branches/darrylcousins-branch/ Commiting
yesterdays work before a refractoring
Darryl Cousins
darryl at darrylcousins.net.nz
Tue Jul 3 19:20:27 EDT 2007
Log message for revision 77383:
Commiting yesterdays work before a refractoring
Changed:
U grok/branches/darrylcousins-branch/buildout.cfg
D grok/branches/darrylcousins-branch/megrok.layer/src/megrok/layer/tests/layer/simple_fixture/
U grok/branches/darrylcousins-branch/megrok.layer/src/megrok/layer/tests/layer/static.py
U grok/branches/darrylcousins-branch/megrok.layer/src/megrok/layer/tests/layer/view.py
U grok/branches/darrylcousins-branch/megrok.layer/src/megrok/layer/tests/test_layer.py
U grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/__init__.py
U grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/components.py
U grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/directive.py
U grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/meta.py
U grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/ftesting.zcml
A grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/template/layoutview.py
A grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/template/templateview.py
D grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/template/view.py
D grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/template/view_templates/
U grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/components.py
U grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/meta.py
U grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/ftesting.zcml
U grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/test_view.py
U grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/argument.py
A grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/argument_templates/
A grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/argument_templates/update.pt
A grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/arguments_templates/
D grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/index.py
D grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/macros.py
U grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/template.py
A grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/template_templates/sculpture.pt
D grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/view.py
U grok/branches/darrylcousins-branch/megrok.viewlet/src/megrok/viewlet/components.py
U grok/branches/darrylcousins-branch/megrok.viewlet/src/megrok/viewlet/tests/ftesting.zcml
U grok/branches/darrylcousins-branch/megrok.viewlet/src/megrok/viewlet/tests/test_viewlet.py
U grok/branches/darrylcousins-branch/megrok.viewlet/src/megrok/viewlet/tests/viewlet/adapter.py
U grok/branches/darrylcousins-branch/setup.py
U grok/branches/darrylcousins-branch/src/grok/meta.py
-=-
Modified: grok/branches/darrylcousins-branch/buildout.cfg
===================================================================
--- grok/branches/darrylcousins-branch/buildout.cfg 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/buildout.cfg 2007-07-03 23:20:27 UTC (rev 77383)
@@ -1,6 +1,6 @@
[buildout]
-develop = . grokwiki ldapaddressbook martian megrok.layer megrok.viewlet megrok.view megrok.template
-parts = app data instance test devpython
+develop = . megrok.layer megrok.viewlet megrok.view megrok.template
+parts = app data instance test
find-links = http://download.zope.org/distribution/
[zope3]
@@ -9,7 +9,6 @@
[app]
eggs = grok
- grokwiki
martian
megrok.layer
megrok.template
@@ -96,9 +95,3 @@
megrok.view
defaults = ['--tests-pattern', '^f?tests$', '-v']
-# installs bin/devpython to do simple interpreter tests
-[devpython]
-recipe = zc.recipe.egg
-interpreter = devpython
-eggs = grok
- martian
Modified: grok/branches/darrylcousins-branch/megrok.layer/src/megrok/layer/tests/layer/static.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.layer/src/megrok/layer/tests/layer/static.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.layer/src/megrok/layer/tests/layer/static.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -2,64 +2,10 @@
If there is a static/ directory inside of a grokked package, its
contents will be available as static resources under a URL:
- >>> import grok
- >>> grok.grok('megrok.layer.tests.layer.simple_fixture')
- >>> from zope.testbrowser.testing import Browser
- >>> browser = Browser()
- >>> browser.handleErrors = False
- >>> browser.open('http://localhost/@@/megrok.layer.tests.layer.simple_fixture/'
- ... 'file.txt')
- >>> print browser.contents
- some text
+Actually it won't be this megrok package because the resource is registered for
+IDefaultBrowserLayer and layers in this package do not inherit from
+IDefaultBrowserLayer.
-We use a special name 'static' in page templates to allow easy linking
-to resources:
+Instead resources will be configured explicitly.
- >>> root = getRootFolder()
- >>> from megrok.layer.tests.layer.simple_fixture.ellie import Mammoth
- >>> root[u'ellie'] = Mammoth()
- >>> browser.open('http://localhost/ellie')
- >>> print browser.contents
- <html>
- <body>
- <a href="http://localhost/@@/megrok.layer.tests.layer.simple_fixture/file.txt">Some text in a file</a>
- </body>
- </html>
-
-Static also means that page templates will not be interpreted:
-
- >>> browser.open('http://localhost/@@/megrok.layer.tests.layer.simple_fixture/static.pt')
- >>> print browser.contents
- <html>
- <body>
- <h1 tal:content="string:will not be interpreted"/>
- </body>
- </html>
-
-We also support subdirectories for resources:
-
- >>> browser.open('http://localhost/@@/megrok.layer.tests.layer.simple_fixture/subdir/otherfile.txt')
- >>> print browser.contents
- This is yet another file.
-
-Sanity check custom layers
-
- >>> browser.open('http://localhost/ellie/@@cavedrawings')
- >>> print browser.contents
- stick figures
-
- >>> browser.open('http://localhost/++skin++mammothskin/ellie/@@tarpit')
- >>> print browser.contents
- inky darkness all around
-
-
- >>> browser.open('http://localhost/++skin++mammothskin/@@/megrok.layer.tests.layer.simple_fixture/subdir/otherfile.txt')
- >>> print browser.contents
- This is yet another file.
-
- >>> browser.open('http://localhost/++skin++Rotterdam/@@/megrok.layer.tests.layer.simple_fixture/subdir/otherfile.txt')
- >>> print browser.contents
- This is yet another file.
-
"""
-
Modified: grok/branches/darrylcousins-branch/megrok.layer/src/megrok/layer/tests/layer/view.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.layer/src/megrok/layer/tests/layer/view.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.layer/src/megrok/layer/tests/layer/view.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -37,6 +37,7 @@
from zope import interface
import megrok.layer
+import megrok.view
megrok.layer.layer(IBasicSkin)
class MySkinLayer(megrok.layer.IMinimalLayer):
@@ -48,7 +49,7 @@
class Mammoth(grok.Model):
pass
-class CaveDrawings(grok.View):
+class CaveDrawings(megrok.view.View):
pass
cavedrawings = grok.PageTemplate("""\
@@ -59,13 +60,13 @@
</html>
""")
-class MoreDrawings(grok.View):
+class MoreDrawings(megrok.view.View):
megrok.layer.layer(rotterdam)
def render(self):
return "Pretty"
-class EvenMoreDrawings(grok.View):
+class EvenMoreDrawings(megrok.view.View):
megrok.layer.layer(MySkinLayer)
def render(self):
Modified: grok/branches/darrylcousins-branch/megrok.layer/src/megrok/layer/tests/test_layer.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.layer/src/megrok/layer/tests/test_layer.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.layer/src/megrok/layer/tests/test_layer.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -9,6 +9,7 @@
def suiteFromPackage(name):
files = resource_listdir(__name__, name)
suite = unittest.TestSuite()
+ #files = ['view.py']
for filename in files:
if not filename.endswith('.py'):
continue
Modified: grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/__init__.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/__init__.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/__init__.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -1,3 +1,3 @@
-from directive import layout, macro
-from components import TemplateFactory
+from directive import layout, macro, content_type
+from components import TemplateFactory, LayoutFactory
Modified: grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/components.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/components.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/components.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -1,11 +1,8 @@
-import zope.component
-import zope.interface
-from zope.publisher.interfaces.browser import IBrowserRequest
-from zope.publisher.browser import BrowserPage
-from zope.pagetemplate.interfaces import IPageTemplate
-
class TemplateFactory(object):
pass
+class LayoutFactory(object):
+ pass
+
Modified: grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/directive.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/directive.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/directive.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -1,9 +1,9 @@
-from martian.directive import (InterfaceOrClassDirective,
- ClassDirectiveContext)
+from martian.directive import (SingleTextDirective,
+ ClassDirectiveContext)
-layout = InterfaceOrClassDirective('megrok.template.layout',
+layout = SingleTextDirective('megrok.template.layout',
ClassDirectiveContext())
-macro = InterfaceOrClassDirective('megrok.template.macro',
+macro = SingleTextDirective('megrok.template.macro',
ClassDirectiveContext())
-content_type = InterfaceOrClassDirective('megrok.template.content_type',
+content_type = SingleTextDirective('megrok.template.content_type',
ClassDirectiveContext())
Modified: grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/meta.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/meta.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/meta.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -1,3 +1,5 @@
+import os
+
import zope.component
import zope.interface
from zope.publisher.interfaces.browser import IBrowserRequest
@@ -4,9 +6,11 @@
from zope.pagetemplate.interfaces import IPageTemplate
from z3c.template.template import TemplateFactory
+from z3c.template.interfaces import ILayoutTemplate
import martian
from martian import util
+from martian.error import GrokError
import grok
from grok.util import check_adapts
@@ -14,8 +18,8 @@
import megrok.template
# TODO raise errors if anything missing?
-class TemplateFactoryGrokker(martian.ClassGrokker):
- component_class = megrok.template.TemplateFactory
+class TemplateFactoryGrokkerBase(martian.ClassGrokker):
+ component_class = None
def grok(self, name, factory, context, module_info, templates):
view_context = util.determine_class_context(factory, context)
@@ -25,29 +29,40 @@
template_name = util.class_annotation(factory, 'grok.template',
factory_name)
template = templates.get(template_name)
+ if not template:
+ raise GrokError("No template found for %r. Please define a template"
+ "to use."
+ % (factory),
+ factory)
if factory_name != template_name:
# grok.template is being used
- if templates.get(self.factory_name):
+ if templates.get(factory_name):
raise GrokError("Multiple possible templates for template %r. It "
"uses grok.template('%s'), but there is also "
"a template called '%s'."
% (factory, template_name, factory_name),
factory)
- provides = util.class_annotation(factory, 'grok.provides', IPageTemplate)
+ provides = util.class_annotation(factory, 'grok.provides', self.provides)
macro = util.class_annotation(factory, 'megrok.template.macro', None)
contentType = util.class_annotation(factory,
'megrok.template.content_type', 'text/html')
view_layer = util.class_annotation(factory, 'megrok.layer.layer',
None) or module_info.getAnnotation('megrok.layer.layer',
None) or IBrowserRequest
- view_name = util.class_annotation(factory, 'grok.name', u'')
+ view_name = util.class_annotation(factory, 'grok.name', '')
filename = template.__grok_location__
+ if not os.path.exists(filename):
+ raise GrokError("Inline templates are not supported for %s."
+ " Please drop a tempate named %s in %s_templates."
+ % (factory.__name__, factory_name, factory.module_info.name),
+ factory)
factory = TemplateFactory(filename, contentType, macro)
templates.markAssociated(template_name)
zope.interface.directlyProvides(factory, provides)
+ print '\nname:', view_name,'context:', view_context,'factory:', factory, '\n'
zope.component.provideAdapter(factory,
adapts=(view_context, view_layer),
provides=provides,
@@ -55,4 +70,18 @@
return True
+class TemplateFactoryGrokker(TemplateFactoryGrokkerBase):
+ component_class = megrok.template.TemplateFactory
+ @property
+ def provides(self):
+ return IPageTemplate
+
+class LayoutFactoryGrokker(TemplateFactoryGrokkerBase):
+ component_class = megrok.template.LayoutFactory
+
+ @property
+ def provides(self):
+ return ILayoutTemplate
+
+
Modified: grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/ftesting.zcml
===================================================================
--- grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/ftesting.zcml 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/ftesting.zcml 2007-07-03 23:20:27 UTC (rev 77383)
@@ -9,6 +9,7 @@
<include package="megrok.viewlet" file="meta.zcml" />
<include package="megrok.layer" file="meta.zcml" />
<include package="megrok.template" file="meta.zcml" />
+ <include package="zope.app.pagetemplate" file="meta.zcml" />
<include package="zope.app.zcmlfiles" />
Added: grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/template/layoutview.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/template/layoutview.py (rev 0)
+++ grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/template/layoutview.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -0,0 +1,75 @@
+"""
+ >>> import grok
+ >>> from megrok.template.tests.template.layoutview import Mammoth
+ >>> grok.grok('megrok.template.tests.template.layoutview')
+
+ >>> mammoth = getRootFolder()["mammoth"] = Mammoth()
+
+Layout views have a call method (TemplateViews do not) so we can use testbrowser.
+
+ >>> from zope.testbrowser.testing import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+
+ >>> browser.open("http://localhost/mammoth/@@painting")
+ >>> print browser.contents
+ <div>Mammoth view</div>
+
+Like TemplateFactories, LayoutFactories also support a `macro` directive (see z3c.template).
+
+ >>> browser.open("http://localhost/mammoth/@@drawing")
+ >>> print browser.contents
+ <div>This is within the mymacro macro</div>
+
+And also allow the setting of the contentType. But I haven't got that to render yet.
+
+ >>> import zope.component
+ >>> from z3c.template.interfaces import ILayoutTemplate
+ >>> from megrok.template.tests.template.layoutview import TextDrawing
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest()
+ >>> plaintext = TextDrawing(mammoth, request)
+ >>> template = zope.component.getMultiAdapter(
+ ... (plaintext, request), ILayoutTemplate)
+ >>> print template.content_type
+ text/plain
+
+"""
+
+import grok
+
+import megrok.template
+import megrok.view
+
+class Mammoth(grok.Model):
+ pass
+
+class Painting(megrok.view.LayoutView):
+ pass
+
+ def render(self):
+ return u'Mammoth view'
+
+class LayoutTemplate(megrok.template.LayoutFactory):
+ """Only file templates can be used with template factory"""
+ grok.context(Painting) # this is layout template for Painting
+
+class Drawing(megrok.view.LayoutView):
+ pass
+
+class DrawingTemplate(megrok.template.LayoutFactory):
+ """Only file templates can be used with template factory"""
+ grok.context(Drawing)
+ megrok.template.macro('mymacro')
+
+class TextDrawing(megrok.view.LayoutView):
+ pass
+
+ def render(self):
+ return self.response.getHeader('Content-Type')
+
+class TextDrawingTemplate(megrok.template.LayoutFactory):
+ """Only file templates can be used with template factory"""
+ grok.context(TextDrawing)
+ megrok.template.content_type('text/plain')
+
Property changes on: grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/template/layoutview.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/template/templateview.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/template/templateview.py (rev 0)
+++ grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/template/templateview.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -0,0 +1,67 @@
+"""
+ >>> import grok
+ >>> from megrok.template.tests.template.templateview import Mammoth
+ >>> grok.grok('megrok.template.tests.template.templateview')
+
+ >>> mammoth = Mammoth()
+ >>> import zope.component
+ >>> from zope.pagetemplate.interfaces import IPageTemplate
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest()
+ >>> from megrok.template.tests.template.templateview import MammothView
+ >>> mammothview = MammothView(mammoth, request)
+ >>> template = zope.component.getMultiAdapter(
+ ... (mammothview, request), IPageTemplate)
+ >>> print template
+ <zope.app.pagetemplate.viewpagetemplatefile.ViewPageTemplateFile object at ...>
+ >>> print mammothview.render()
+ <div>Factory template</div>
+
+TemplateFactories support a `macro` directive (see z3c.template).
+
+ >>> from megrok.template.tests.template.templateview import MammothViewFromMacro
+ >>> mammothviewfrommacro = MammothViewFromMacro(mammoth, request)
+ >>> print mammothviewfrommacro.render()
+ <div>This is within the mymacro macro</div>
+
+TemplateFactories also allow the setting of the contentType.
+
+ >>> from megrok.template.tests.template.templateview import MammothViewPlainText
+ >>> mammothviewplaintext = MammothViewPlainText(mammoth, request)
+ >>> template = zope.component.getMultiAdapter(
+ ... (mammothviewplaintext, request), IPageTemplate)
+ >>> print template.content_type
+ text/plain
+
+"""
+
+import grok
+
+import megrok.template
+import megrok.view
+
+class Mammoth(grok.Model):
+ pass
+
+class MammothView(megrok.view.TemplateView):
+ pass
+
+class MammothViewTemplate(megrok.template.TemplateFactory):
+ """Only file templates can be used with template factory"""
+ grok.context(MammothView) # this is template for MammothView
+
+class MammothViewFromMacro(megrok.view.TemplateView):
+ pass
+
+class MammothViewFromMacroTemplate(megrok.template.TemplateFactory):
+ grok.context(MammothViewFromMacro)
+ megrok.template.macro('mymacro')
+
+class MammothViewPlainText(megrok.view.TemplateView):
+ pass
+
+class MammothViewPlainTextTemplate(megrok.template.TemplateFactory):
+ grok.context(MammothViewPlainText)
+ megrok.template.content_type('text/plain')
+
+
Property changes on: grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/template/templateview.py
___________________________________________________________________
Name: svn:keywords
+ Id
Deleted: grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/template/view.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/template/view.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.template/src/megrok/template/tests/template/view.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -1,32 +0,0 @@
-"""
- >>> import grok
- >>> from megrok.template.tests.template.view import MyFactory, Mammoth
- >>> grok.grok('megrok.template.tests.template.view')
-
- >>> mammoth = Mammoth()
- >>> import zope.component
- >>> from zope.pagetemplate.interfaces import IPageTemplate
- >>> from zope.publisher.browser import TestRequest
- >>> request = TestRequest()
- >>> template = zope.component.getMultiAdapter(
- ... (mammoth, request), IPageTemplate)
- >>> print template
- <zope.app.pagetemplate.viewpagetemplatefile.ViewPageTemplateFile object at ...>
-
-"""
-
-import grok
-
-import megrok.template
-import zope.interface
-
-class Mammoth(grok.Model):
- pass
-
-class MyFactory(megrok.template.TemplateFactory):
- pass
-
-#myfactory = grok.PageTemplate("""\
-#<div>Factory template</div>
-#""")
-
Modified: grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/components.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/components.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/components.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -1,5 +1,6 @@
import zope.component
import zope.interface
+from zope.component.interfaces import ComponentLookupError
from zope.publisher.browser import BrowserPage
from zope.publisher.publish import mapply
from zope.pagetemplate.interfaces import IPageTemplate
@@ -11,13 +12,7 @@
class ViewBase(object):
- def _render_template(self):
- namespace = self.template.pt_getContext()
- namespace['request'] = self.request
- namespace['view'] = self
- namespace['context'] = self.context
- namespace['static'] = self.static
- return self.template.pt_render(namespace)
+ template_name = u''
def application(self):
obj = self.context
@@ -78,6 +73,9 @@
class View(BrowserPage, ViewBase):
+ """Chief difference here between grok.View is that this is registered not on
+ IDefaultBrowserLayer but on IBrowserRequest so that it is available to MinimalLayer
+ which does not subclass IDefaultBrowserLayer"""
zope.interface.implements(IGrokView)
def __init__(self, context, request):
@@ -89,17 +87,27 @@
)
def __call__(self):
+ """note that I've lost the static directory in the namespace,
+ to bring this back in would mean changes to z3c.template.
+
+ I'll think again about this further on"""
+ # should check if update() is not called elsewhere
mapply(self.update, (), self.request)
if self.request.response.getStatus() in (302, 303):
- # A redirect was triggered somewhere in update(). Don't
- # continue rendering the template or doing anything else.
return
-
template = getattr(self, 'template', None)
- if template is not None:
- return self._render_template()
+ if template is None:
+ try:
+ template = zope.component.getMultiAdapter(
+ (self, self.request), IPageTemplate)
+ return template(self)
+ except ComponentLookupError:
+ pass
+ else:
+ return template(self)
return mapply(self.render, (), self.request)
+
class ITemplateView(zope.interface.Interface):
pass
@@ -123,26 +131,16 @@
name=self.module_info.package_dotted_name
)
- def _render_template(self):
- # z3c.template factory is a z.a.viewpagetemplatefile
- namespace = self.template.pt_getContext(self, self.request)
- namespace['request'] = self.request
- namespace['view'] = self
- namespace['context'] = self.context
- namespace['static'] = self.static
- #for key in namespace.keys():
- # print key
- return self.template.pt_render(namespace)
-
def render(self):
- # should check if update() is not called elsewhere
mapply(self.update, (), self.request)
- if self.template is None:
- self.template = zope.component.getMultiAdapter(
+ if self.request.response.getStatus() in (302, 303):
+ return
+ template = getattr(self, 'template', None)
+ if template is None:
+ template = zope.component.getMultiAdapter(
(self, self.request), IPageTemplate)
- self.template.macro = None
- return self._render_template()
- return self._render_template()
+ return template(self)
+ return template(self)
class ILayoutView(zope.interface.Interface):
pass
@@ -166,21 +164,16 @@
name=self.module_info.package_dotted_name
)
- def _render_layout(self):
- # z3c.template factory is a z.a.viewpagetemplatefile
- namespace = self.layout.pt_getContext(self, self.request)
- namespace['request'] = self.request
- namespace['view'] = self
- namespace['context'] = self.context
- namespace['static'] = self.static
- return self.layout.pt_render(namespace)
-
def __call__(self):
- # should check if update() is not called elsewhere
mapply(self.update, (), self.request)
- if self.layout is None:
- self.layout = zope.component.getMultiAdapter(
+ if self.request.response.getStatus() in (302, 303):
+ return
+ layout = getattr(self, 'layout', None)
+ if layout is None:
+ layout = zope.component.getMultiAdapter(
(self, self.request), ILayoutTemplate)
- return self._render_layout()
- return self._render_layout()
+ return layout(self)
+ return layout(self)
+ def render(self):
+ pass
Modified: grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/meta.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/meta.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/meta.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -26,11 +26,19 @@
factory.module_info = module_info
self.factory_name = factory.__name__.lower()
+ self.view_layer = util.class_annotation(factory, 'megrok.layer.layer',
+ None) or module_info.getAnnotation('megrok.layer.layer',
+ None) or IBrowserRequest
+
+ self.view_name = util.class_annotation(factory, 'grok.name',
+ self.factory_name)
+
# find templates
template_name = util.class_annotation(factory, 'grok.template',
self.factory_name)
template = templates.get(template_name)
+ factory.template_name = template_name
if self.factory_name != template_name:
# grok.template is being used
if templates.get(self.factory_name):
@@ -42,13 +50,6 @@
self.register_template(factory, template, template_name, templates)
- self.view_layer = util.class_annotation(factory, 'megrok.layer.layer',
- None) or module_info.getAnnotation('megrok.layer.layer',
- None) or IBrowserRequest
-
- self.view_name = util.class_annotation(factory, 'grok.name',
- self.factory_name)
-
# __view_name__ is needed to support IAbsoluteURL on views
factory.__view_name__ = self.view_name
@@ -71,15 +72,16 @@
return True
def register_template(self, factory, template, template_name, templates):
- """May be overridden"""
+ """Jumping a bit here to make the z3c.template Macro available to the
+ template, either it needs to be in grok.PageTemplate ...?"""
+
+ print '\ntemplatename:', template_name,'template:', template,'factory:', factory, '\n'
if template:
templates.markAssociated(template_name)
factory.template = template
else:
- if not getattr(factory, 'render', None):
- # we do not accept a view without any way to render it
- raise GrokError("View %r has no associated template or "
- "'render' method." % factory, factory)
+ # we assume that a template has or will be grokked from a class
+ pass
def register(self, factory, module_info):
@@ -107,29 +109,6 @@
provides=zope.interface.Interface,
name=self.view_name)
- def register_template(self, factory, template, template_name, templates):
- """Jumping a bit here to make the z3c.template Macro available to the
- template, either it needs to be in grok.PageTemplate ...?"""
- contentType = getattr(factory, 'contentType', 'text/html')
- if template:
- print '\n', template, '\n'
- #filename = getattr(template, 'filename', None)
- #if not filename:
- # raise GrokError("%s cannot use the inline "
- # "template called '%s'. Please use grok.PageTemplateFle "
- # "or drop a template in %s_templates called '%s'"
- # % (factory, template_name,
- # factory.module_info.name,
- # self.factory_name),
- # factory)
- filename = template.__grok_location__
- templates.markAssociated(template_name)
- #template = TemplateFactory(filename, contentType)
- factory.template = template
- else:
- # we assume that a template has or will be grokked from a class
- pass
-
class LayoutViewGrokker(ViewGrokkerBase):
component_class = megrok.view.LayoutView
Modified: grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/ftesting.zcml
===================================================================
--- grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/ftesting.zcml 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/ftesting.zcml 2007-07-03 23:20:27 UTC (rev 77383)
@@ -8,6 +8,7 @@
<include package="megrok.view" file="meta.zcml" />
<include package="megrok.viewlet" file="meta.zcml" />
<include package="megrok.layer" file="meta.zcml" />
+ <include package="megrok.template" file="meta.zcml" />
<include package="zope.app.zcmlfiles" />
Modified: grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/test_view.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/test_view.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/test_view.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -9,7 +9,6 @@
def suiteFromPackage(name):
files = resource_listdir(__name__, name)
suite = unittest.TestSuite()
- files = ['template.py']
for filename in files:
if not filename.endswith('.py'):
continue
Modified: grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/argument.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/argument.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/argument.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -52,6 +52,7 @@
"""
import grok
import megrok.view
+import megrok.template
class Mammoth(grok.Model):
pass
@@ -64,14 +65,10 @@
class UpdateWithArguments(megrok.view.View):
grok.name('update')
- grok.template('update')
def update(self, message, another):
self.message = message
self.another = another
-update = grok.PageTemplate("""
-Coming to us from update():
-Message: <span tal:replace="view/message" />
-Another: <span tal:replace="view/another" />
-""")
+class Update(megrok.template.TemplateFactory):
+ grok.context(UpdateWithArguments)
Added: grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/argument_templates/update.pt
===================================================================
--- grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/argument_templates/update.pt (rev 0)
+++ grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/argument_templates/update.pt 2007-07-03 23:20:27 UTC (rev 77383)
@@ -0,0 +1,4 @@
+Coming to us from update():
+Message: <span tal:replace="view/message" />
+Another: <span tal:replace="view/another" />
+
Deleted: grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/index.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/index.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/index.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -1,40 +0,0 @@
-"""
- >>> import grok
- >>> from megrok.view.tests.view.index import Mammoth
- >>> grok.grok('megrok.view.tests.view.index')
- >>> getRootFolder()["manfred"] = Mammoth()
-
-The default view name for a model is 'index':
-
- >>> from zope.testbrowser.testing import Browser
- >>> browser = Browser()
- >>> browser.handleErrors = False
- >>> browser.open("http://localhost/manfred")
- >>> print browser.contents
- <html>
- <body>
- <h1>Hello, world!</h1>
- <span>Blue</span>
- <span>Blue</span>
- </body>
- </html>
-
-"""
-import grok
-import megrok.view
-
-class Mammoth(grok.Model):
- teeth = u"Blue"
-
-class Index(megrok.view.View):
- pass
-
-index = grok.PageTemplate("""\
-<html>
-<body>
-<h1>Hello, world!</h1>
-<span tal:content="python:context.teeth">green</span>
-<span tal:content="context/teeth">green</span>
-</body>
-</html>
-""")
Deleted: grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/macros.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/macros.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/macros.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -1,97 +0,0 @@
-"""
- >>> import grok
- >>> from megrok.view.tests.view.macros import Mammoth
- >>> grok.grok('megrok.view.tests.view.macros')
- >>> getRootFolder()["manfred"] = Mammoth()
-
- >>> from zope.testbrowser.testing import Browser
- >>> browser = Browser()
- >>> browser.handleErrors = False
- >>> browser.open("http://localhost/manfred/@@painting")
- >>> print browser.contents
- <html>
- <body>
- <h1>GROK MACRO!</h1>
- <div>
- GROK SLOT!
- </div>
- </body>
- </html>
-
-Views without a template do not support macros:
-
- >>> browser.open("http://localhost/manfred/@@dancing")
- Traceback (most recent call last):
- AttributeError: 'DancingHall' object has no attribute 'template'
-
-If the view has an attribute with the same name as a macro, the macro
-shadows the view. XXX This should probably generate a warning at runtime.
-
- >>> browser.open("http://localhost/manfred/@@grilldish")
- >>> print browser.contents
- <html>
- Curry
- </html>
-
-"""
-import grok
-import megrok.view
-
-class Mammoth(grok.Model):
- pass
-
-class DancingHall(megrok.view.View):
-
- def render(self):
- return "A nice large dancing hall for mammoths."
-
-class Grilled(megrok.view.View):
-
- def update(self):
- self.spices = "Pepper and salt"
-
-class Painting(megrok.view.View):
- pass
-
-painting = grok.PageTemplate("""\
-<html metal:use-macro="context/@@layout/main">
-<div metal:fill-slot="slot">
-GROK SLOT!
-</div>
-</html>
-""")
-
-class Layout(megrok.view.View):
- pass
-
-layout = grok.PageTemplate("""\
-<html metal:define-macro="main">
-<body>
-<h1>GROK MACRO!</h1>
-<div metal:define-slot="slot">
-</div>
-</body>
-</html>""")
-
-class Dancing(megrok.view.View):
- pass
-
-dancing = grok.PageTemplate("""\
-<html metal:use-macro="context/@@dancinghall/something">
-</html>
-""")
-
-class GrillDish(megrok.view.View):
- pass
-
-grilldish = grok.PageTemplate("""
-<html metal:use-macro="context/@@grilled/spices">
-</html>""")
-
-class Grilled(megrok.view.View):
- pass
-
-grilled = grok.PageTemplate("""\
-<html metal:define-macro="spices">
-Curry
-</html>""")
Modified: grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/template.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/template.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/template.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -61,9 +61,15 @@
We can also use megrok.template to provide more sophisticated possiblities.
+ >>> from megrok.view.tests.view.template import SculptureView
+ >>> view = SculptureView(mammoth, request)
+ >>> print view.render()
+ <div>Sculpture template</div>
+
"""
import grok
import megrok.view
+import megrok.template
class Mammoth(grok.Model):
pass
@@ -81,5 +87,11 @@
<div>Carving inline template</div>
""")
-class Sculpture(megrok.template.Template):
+class SculptureView(megrok.view.TemplateView):
+ """We don't need to define a template here because the following
+ TemplateFactory will be used"""
pass
+
+class Sculpture(megrok.template.TemplateFactory):
+ grok.context(SculptureView)
+
Added: grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/template_templates/sculpture.pt
===================================================================
--- grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/template_templates/sculpture.pt (rev 0)
+++ grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/template_templates/sculpture.pt 2007-07-03 23:20:27 UTC (rev 77383)
@@ -0,0 +1,2 @@
+<div>Sculpture template</div>
+
Deleted: grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/view.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/view.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.view/src/megrok/view/tests/view/view.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -1,34 +0,0 @@
-"""
- >>> import grok
- >>> from megrok.view.tests.view.view import Mammoth
- >>> grok.grok('megrok.view.tests.view.view')
- >>> getRootFolder()["manfred"] = Mammoth()
-
- >>> from zope.testbrowser.testing import Browser
- >>> browser = Browser()
- >>> browser.handleErrors = False
- >>> browser.open("http://localhost/manfred/@@painting")
- >>> print browser.contents
- <html>
- <body>
- <h1>Hello, world!</h1>
- </body>
- </html>
-
-"""
-import grok
-import megrok.view
-
-class Mammoth(grok.Model):
- pass
-
-class Painting(megrok.view.View):
- pass
-
-painting = grok.PageTemplate("""\
-<html>
-<body>
-<h1>Hello, world!</h1>
-</body>
-</html>
-""")
Modified: grok/branches/darrylcousins-branch/megrok.viewlet/src/megrok/viewlet/components.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.viewlet/src/megrok/viewlet/components.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.viewlet/src/megrok/viewlet/components.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -23,8 +23,16 @@
if self.request.response.getStatus() in (302, 303):
return
template = getattr(self, 'template', None)
- if template is not None:
- return self._render_template()
+ if template is None:
+ try:
+ template = zope.component.getMultiAdapter(
+ (self, self.request), IPageTemplate)
+ return template(self)
+ except ComponentLookupError:
+ pass
+ else:
+ return template(self)
+ return mapply(self.render, (), self.request)
class ContentProvider(ViewBase, TemplateContentBase):
@@ -94,7 +102,7 @@
return
template = getattr(self, 'template', None)
if template is not None:
- return self._render_template()
+ return template(self)
else:
return u'\n'.join([viewlet.render() for viewlet in self.viewlets])
Modified: grok/branches/darrylcousins-branch/megrok.viewlet/src/megrok/viewlet/tests/ftesting.zcml
===================================================================
--- grok/branches/darrylcousins-branch/megrok.viewlet/src/megrok/viewlet/tests/ftesting.zcml 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.viewlet/src/megrok/viewlet/tests/ftesting.zcml 2007-07-03 23:20:27 UTC (rev 77383)
@@ -8,6 +8,7 @@
<include package="megrok.view" file="meta.zcml" />
<include package="megrok.viewlet" file="meta.zcml" />
<include package="megrok.layer" file="meta.zcml" />
+ <include package="megrok.template" file="meta.zcml" />
<include package="zope.app.zcmlfiles" />
Modified: grok/branches/darrylcousins-branch/megrok.viewlet/src/megrok/viewlet/tests/test_viewlet.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.viewlet/src/megrok/viewlet/tests/test_viewlet.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.viewlet/src/megrok/viewlet/tests/test_viewlet.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -9,6 +9,7 @@
def suiteFromPackage(name):
files = resource_listdir(__name__, name)
suite = unittest.TestSuite()
+ files = ['adapter.py']
for filename in files:
if not filename.endswith('.py'):
continue
Modified: grok/branches/darrylcousins-branch/megrok.viewlet/src/megrok/viewlet/tests/viewlet/adapter.py
===================================================================
--- grok/branches/darrylcousins-branch/megrok.viewlet/src/megrok/viewlet/tests/viewlet/adapter.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/megrok.viewlet/src/megrok/viewlet/tests/viewlet/adapter.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -35,6 +35,7 @@
import megrok.layer
import megrok.view
+import megrok.template
class Mammoth(grok.Model):
pass
@@ -50,6 +51,10 @@
why when inline the `provider` tal directive wasn't found"""
pass
+class PaintingPT(megrok.template.TemplateFactory):
+ grok.template('painting')
+ grok.context(Painting)
+
class MammothContentProvider(grok.MultiAdapter):
grok.adapts(Mammoth, IMySkinLayer, IBrowserView)
grok.implements(IContentProvider)
Modified: grok/branches/darrylcousins-branch/setup.py
===================================================================
--- grok/branches/darrylcousins-branch/setup.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/setup.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -50,5 +50,6 @@
'zope.app.twisted',
'zope.app.securitypolicy',
'zope.app.zcmlfiles',
+ 'martian',
],
)
Modified: grok/branches/darrylcousins-branch/src/grok/meta.py
===================================================================
--- grok/branches/darrylcousins-branch/src/grok/meta.py 2007-07-03 21:15:38 UTC (rev 77382)
+++ grok/branches/darrylcousins-branch/src/grok/meta.py 2007-07-03 23:20:27 UTC (rev 77383)
@@ -310,7 +310,7 @@
resource_factory = components.DirectoryResourceFactory(
resource_path, module_info.dotted_name)
component.provideAdapter(
- resource_factory, (IBrowserRequest,),
+ resource_factory, (IDefaultBrowserLayer,),
interface.Interface, name=module_info.dotted_name)
return True
More information about the Checkins
mailing list