[Checkins] SVN: grok/trunk/src/grok/ raise an error if a template is defined both inline and in the resource directory

Wolfgang Schnerring wosc at wosc.de
Mon Oct 16 08:54:26 EDT 2006


Log message for revision 70688:
  raise an error if a template is defined both inline and in the resource directory

Changed:
  U   grok/trunk/src/grok/_grok.py
  A   grok/trunk/src/grok/tests/view/resourceandinlinetemplate/
  A   grok/trunk/src/grok/tests/view/resourceandinlinetemplate/cavepainting.pt
  A   grok/trunk/src/grok/tests/view/resourceandinlinetemplate.py

-=-
Modified: grok/trunk/src/grok/_grok.py
===================================================================
--- grok/trunk/src/grok/_grok.py	2006-10-16 12:48:34 UTC (rev 70687)
+++ grok/trunk/src/grok/_grok.py	2006-10-16 12:54:24 UTC (rev 70688)
@@ -102,7 +102,12 @@
 
             contents = resource_string(dotted_name, os.path.join(directory_name, resource))
             template = PageTemplate(contents)
-            templates.register(resource[:-3], template)
+            template_name = resource[:-3]
+            if templates.get(template_name):
+                raise GrokError("Conflicting templates found for name '%s' in module %r, "
+                                "both inline and in resource directory '%s'."
+                                % (template_name, module, directory_name))
+            templates.register(template_name, template)
 
     if getattr(module, '__grok_context__', None):
         context = module.__grok_context__

Added: grok/trunk/src/grok/tests/view/resourceandinlinetemplate/cavepainting.pt
===================================================================
--- grok/trunk/src/grok/tests/view/resourceandinlinetemplate/cavepainting.pt	2006-10-16 12:48:34 UTC (rev 70687)
+++ grok/trunk/src/grok/tests/view/resourceandinlinetemplate/cavepainting.pt	2006-10-16 12:54:24 UTC (rev 70688)
@@ -0,0 +1 @@
+nothing

Added: grok/trunk/src/grok/tests/view/resourceandinlinetemplate.py
===================================================================
--- grok/trunk/src/grok/tests/view/resourceandinlinetemplate.py	2006-10-16 12:48:34 UTC (rev 70687)
+++ grok/trunk/src/grok/tests/view/resourceandinlinetemplate.py	2006-10-16 12:54:24 UTC (rev 70688)
@@ -0,0 +1,21 @@
+"""
+If multiple templates can be found, one in the module and one in the
+resource directory, there is an error:
+
+  >>> grok.grok(__name__)
+  Traceback (most recent call last):
+    ...
+  GrokError: Conflicting templates found for name 'cavepainting' in module
+  <module 'grok.tests.view.resourceandinlinetemplate' from '...'>,
+  both inline and in resource directory 'resourceandinlinetemplate'.
+
+"""
+import grok
+
+class Mammoth(grok.Model):
+    pass
+
+class CavePainting(grok.View):
+    pass
+
+cavepainting = grok.PageTemplate("nothing")



More information about the Checkins mailing list