[Checkins] SVN: grokcore.view/trunk/ Improve error message if you specify a template that doesn't exists.

Sylvain Viollow cvs-admin at zope.org
Sun Apr 29 15:13:13 UTC 2012


Log message for revision 125394:
  Improve error message if you specify a template that doesn't exists.
  

Changed:
  U   grokcore.view/trunk/CHANGES.txt
  U   grokcore.view/trunk/src/grokcore/view/templatereg.py
  U   grokcore.view/trunk/src/grokcore/view/tests/view/templatenotfound.py

-=-
Modified: grokcore.view/trunk/CHANGES.txt
===================================================================
--- grokcore.view/trunk/CHANGES.txt	2012-04-29 14:46:27 UTC (rev 125393)
+++ grokcore.view/trunk/CHANGES.txt	2012-04-29 15:13:09 UTC (rev 125394)
@@ -4,6 +4,9 @@
 2.6.2 (unreleased)
 ------------------
 
+- Improve error message when a template is required for a component
+  but cannot be found.
+
 - Fix how the static resource are found. Instead of using as name the
   package name where the component is defined, using as name the
   package where the template for the component is defined, or the base

Modified: grokcore.view/trunk/src/grokcore/view/templatereg.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/templatereg.py	2012-04-29 14:46:27 UTC (rev 125393)
+++ grokcore.view/trunk/src/grokcore/view/templatereg.py	2012-04-29 15:13:09 UTC (rev 125394)
@@ -265,6 +265,7 @@
     """Associate a template to a factory located in the module
     described by module_info.
     """
+    explicit_template = False
     factory_name = factory.__name__.lower()
     module_name, template_name = grokcore.view.template.bind(
         default=(None, None)).get(factory)
@@ -279,6 +280,7 @@
         assert module_name is not None, \
             u"module_name cannot be None if template_name is specified."
         module_info = module_info_from_dotted_name(module_name)
+        explicit_template = True
 
     # We used grok.template, to specify a template which is different
     # than the class name. Check if there is no template with the same
@@ -313,6 +315,19 @@
     except TemplateLookupError:
         pass
 
+    if not factory_have_template:
+        # If a template was explicitly asked, error.
+        if explicit_template:
+            raise GrokError(
+                "Template %s for %s %r cannot be found." %
+                (template_name, component_name.title(), factory), factory)
+
+        # Check for render or error.
+        if  has_no_render(factory):
+            raise GrokError(
+                "%s %r has no associated template or 'render' method." %
+                (component_name.title(), factory), factory)
+
     if has_render(factory):
         # Check for have both render and template
         if factory_have_template:
@@ -326,12 +341,6 @@
         if getattr(factory, '__static_name__', None) is None:
             factory.__static_name__ = module_info.package_dotted_name
 
-    # Check for no render and no template
-    if not factory_have_template and has_no_render(factory):
-        raise GrokError("%s %r has no associated template or "
-                        "'render' method." %
-                        (component_name.title(), factory), factory)
-
     if factory_have_template:
         factory.template._initFactory(factory)
 

Modified: grokcore.view/trunk/src/grokcore/view/tests/view/templatenotfound.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/tests/view/templatenotfound.py	2012-04-29 14:46:27 UTC (rev 125393)
+++ grokcore.view/trunk/src/grokcore/view/tests/view/templatenotfound.py	2012-04-29 15:13:09 UTC (rev 125394)
@@ -5,8 +5,7 @@
   >>> grok.testing.grok(__name__)
   Traceback (most recent call last):
     ...
-  ConfigurationExecutionError: martian.error.GrokError: View <class 'grokcore.view.tests.view.templatenotfound.Painting'>
-  has no associated template or 'render' method.
+  ConfigurationExecutionError: martian.error.GrokError: Template cavepainting for View <class 'grokcore.view.tests.view.templatenotfound.Painting'> cannot be found.
   in:
 """
 import grokcore.view as grok



More information about the checkins mailing list