[Checkins] SVN: grok/trunk/src/grok/ forbid multiple possible
templates for a view
Philipp von Weitershausen
philikon at philikon.de
Mon Oct 16 04:10:04 EDT 2006
Log message for revision 70673:
forbid multiple possible templates for a view
Changed:
U grok/trunk/src/grok/_grok.py
A grok/trunk/src/grok/tests/view/explicitimplicittemplate.py
-=-
Modified: grok/trunk/src/grok/_grok.py
===================================================================
--- grok/trunk/src/grok/_grok.py 2006-10-16 07:48:36 UTC (rev 70672)
+++ grok/trunk/src/grok/_grok.py 2006-10-16 08:10:03 UTC (rev 70673)
@@ -105,6 +105,15 @@
# find inline templates
template_name = getattr(factory, '__grok_template__', factory_name)
template = templates.get(template_name)
+
+ if factory_name != template_name:
+ # grok.template is being used
+ if templates.get(factory_name):
+ raise GrokError("Multiple possible templates for view %r. It "
+ "uses grok.template('%s'), but there is also "
+ "a template called '%s'."
+ % (factory, template_name, factory_name))
+
if template:
templates.markAssociated(template_name)
factory.template = template
Added: grok/trunk/src/grok/tests/view/explicitimplicittemplate.py
===================================================================
--- grok/trunk/src/grok/tests/view/explicitimplicittemplate.py 2006-10-16 07:48:36 UTC (rev 70672)
+++ grok/trunk/src/grok/tests/view/explicitimplicittemplate.py 2006-10-16 08:10:03 UTC (rev 70673)
@@ -0,0 +1,24 @@
+"""
+It is too confusing to have a template that would be implicitly
+associated with a view while that view already refers to another
+template using grok.template. Therefore there is an error:
+
+ >>> grok.grok(__name__)
+ Traceback (most recent call last):
+ ...
+ GrokError: Multiple possible templates for view
+ <class 'grok.tests.view.explicitimplicittemplate.Painting'>.
+ It uses grok.template('cavepainting'), but there is also a template
+ called 'painting'.
+
+"""
+import grok
+
+class Mammoth(grok.Model):
+ pass
+
+class Painting(grok.View):
+ grok.template('cavepainting')
+
+cavepainting = grok.PageTemplate("GROK CAVEPAINT MAMMOTH!")
+painting = grok.PageTemplate("GROK PAINT MAMMOTH!")
Property changes on: grok/trunk/src/grok/tests/view/explicitimplicittemplate.py
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Checkins
mailing list