[Checkins] SVN: grok/trunk/src/grok/ The template grokkers now also emit actions.

Lennart Regebro regebro at gmail.com
Wed Nov 7 09:44:35 EST 2007


Log message for revision 81587:
  The template grokkers now also emit actions.
  The check for multiple templates or no rendering method has been moved to the template 
  registry and is now also an action in the ViewGrokker.
  
  

Changed:
  U   grok/trunk/src/grok/meta.py
  U   grok/trunk/src/grok/templatereg.py
  U   grok/trunk/src/grok/tests/error/error.py
  U   grok/trunk/src/grok/tests/view/dirandinlinetemplate.py
  U   grok/trunk/src/grok/tests/view/dirtemplateandrender.py
  U   grok/trunk/src/grok/tests/view/eithertemplateorrender.py
  U   grok/trunk/src/grok/tests/view/explicitimplicittemplate.py
  U   grok/trunk/src/grok/tests/view/inline_unassociated.py
  U   grok/trunk/src/grok/tests/view/notemplateorrender.py
  U   grok/trunk/src/grok/tests/view/templatenotfound.py
  U   grok/trunk/src/grok/tests/view/unassociated.py

-=-
Modified: grok/trunk/src/grok/meta.py
===================================================================
--- grok/trunk/src/grok/meta.py	2007-11-07 13:57:25 UTC (rev 81586)
+++ grok/trunk/src/grok/meta.py	2007-11-07 14:44:35 UTC (rev 81587)
@@ -209,7 +209,7 @@
                 )
         return True
     
-
+    
 class ViewGrokker(martian.ClassGrokker):
     component_class = grok.View
 
@@ -233,40 +233,14 @@
                     factory)
 
         # find templates
-        template_name = util.class_annotation(factory, 'grok.template',
-                                              factory_name)
-        template = None
         templates = module_info.getAnnotation('grok.templates', None)
         if templates is not None:
-            template = templates.get(template_name)
+            config.action(
+                discriminator=None,
+                callable=templates.checkTemplates,
+                args=(module_info, factory, factory_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),
-                                factory)
-
-        if template:
-            if (getattr(factory, 'render', None) and not
-                util.check_subclass(factory, components.GrokForm)):
-                # we do not accept render and template both for a view
-                # (unless it's a form, they happen to have render.
-                raise GrokError(
-                    "Multiple possible ways to render view %r. "
-                    "It has both a 'render' method as well as "
-                    "an associated template." % factory, factory)
-
-            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)
-
         # safety belt: make sure that the programmer didn't use
         # @grok.require on any of the view's methods.
         methods = util.methods_from_class(factory)
@@ -382,8 +356,16 @@
         templates = module_info.getAnnotation('grok.templates', None)
         if templates is None:
             return False
-        templates.register(name, instance)
-        instance._annotateGrokInfo(name, module_info.dotted_name)
+        config.action(
+            discriminator=None,
+            callable=templates.register,
+            args=(name, instance)
+        )
+        config.action(
+            discriminator=None,
+            callable=instance._annotateGrokInfo,
+            args=(name, module_info.dotted_name)
+        )
         return True
 
 
@@ -401,7 +383,11 @@
         templates = module_info.getAnnotation('grok.templates', None)
         if templates is None:
             return False
-        templates.findFilesystem(module_info)
+        config.action(
+            discriminator=None,
+            callable=templates.findFilesystem,
+            args=(module_info,)
+        )
         return True
 
 
@@ -412,13 +398,12 @@
         templates = module_info.getAnnotation('grok.templates', None)
         if templates is None:
             return False
-        unassociated = list(templates.listUnassociated())
-        if unassociated:
-            raise GrokError("Found the following unassociated template(s) when "
-                            "grokking %r: %s.  Define view classes inheriting "
-                            "from grok.View to enable the template(s)."
-                            % (module_info.dotted_name,
-                               ', '.join(unassociated)), module_info)
+        
+        config.action(
+            discriminator=None,
+            callable=templates.checkUnassociated,
+            args=(module_info,)
+        )
         return True
 
 

Modified: grok/trunk/src/grok/templatereg.py
===================================================================
--- grok/trunk/src/grok/templatereg.py	2007-11-07 13:57:25 UTC (rev 81586)
+++ grok/trunk/src/grok/templatereg.py	2007-11-07 14:44:35 UTC (rev 81587)
@@ -1,4 +1,5 @@
 from martian.error import GrokError
+from martian import util
 
 import os
 import grok
@@ -61,3 +62,43 @@
         for name, entry in self._reg.iteritems():
             if not entry['associated']:
                 yield name
+
+    def checkUnassociated(self, module_info):
+        unassociated = list(self.listUnassociated())
+        if unassociated:
+            raise GrokError("Found the following unassociated template(s) when "
+                            "grokking %r: %s.  Define view classes inheriting "
+                            "from grok.View to enable the template(s)."
+                            % (module_info.dotted_name,
+                               ', '.join(unassociated)), module_info)
+
+    def checkTemplates(self, module_info, factory, factory_name):
+        template_name = util.class_annotation(factory, 'grok.template',
+                                              factory_name)
+            
+        if factory_name != template_name:
+            # grok.template is being used
+    
+            if self.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),
+                                factory)
+        template = self.get(template_name)
+        if template:
+            if (getattr(factory, 'render', None) and not
+                util.check_subclass(factory, grok.components.GrokForm)):
+                # we do not accept render and template both for a view
+                # (unless it's a form, they happen to have render.
+                raise GrokError(
+                    "Multiple possible ways to render view %r. "
+                    "It has both a 'render' method as well as "
+                    "an associated template." % factory, factory)
+            self.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)

Modified: grok/trunk/src/grok/tests/error/error.py
===================================================================
--- grok/trunk/src/grok/tests/error/error.py	2007-11-07 13:57:25 UTC (rev 81586)
+++ grok/trunk/src/grok/tests/error/error.py	2007-11-07 14:44:35 UTC (rev 81587)
@@ -4,14 +4,15 @@
 
   >>> try:
   ...     grok.testing.grok(__name__)
-  ... except grok.GrokError, error:
+  ... except ConfigurationExecutionError, error:
   ...     pass
-  >>> error.component
+  >>> error.evalue.component
   <class 'grok.tests.error.error.CavePainting'>
 
 """
 
 import grok
+from zope.configuration.config import ConfigurationExecutionError
 
 class Mammoth(grok.Model):
     pass

Modified: grok/trunk/src/grok/tests/view/dirandinlinetemplate.py
===================================================================
--- grok/trunk/src/grok/tests/view/dirandinlinetemplate.py	2007-11-07 13:57:25 UTC (rev 81586)
+++ grok/trunk/src/grok/tests/view/dirandinlinetemplate.py	2007-11-07 14:44:35 UTC (rev 81587)
@@ -5,9 +5,10 @@
   >>> grok.testing.grok(__name__)
   Traceback (most recent call last):
     ...
-  GrokError: Conflicting templates found for name 'cavepainting' in module
+  ConfigurationExecutionError: martian.error.GrokError: Conflicting templates found for name 'cavepainting' in module
   <module 'grok.tests.view.dirandinlinetemplate' from '...'>,
   both inline and in template directory '...dirandinlinetemplate_templates'.
+  in:
 
 """
 import grok

Modified: grok/trunk/src/grok/tests/view/dirtemplateandrender.py
===================================================================
--- grok/trunk/src/grok/tests/view/dirtemplateandrender.py	2007-11-07 13:57:25 UTC (rev 81586)
+++ grok/trunk/src/grok/tests/view/dirtemplateandrender.py	2007-11-07 14:44:35 UTC (rev 81587)
@@ -5,10 +5,11 @@
   >>> grok.testing.grok(__name__)
   Traceback (most recent call last):
     ...
-  GrokError: Multiple possible ways to render view
+  ConfigurationExecutionError: martian.error.GrokError: Multiple possible ways to render view
   <class 'grok.tests.view.dirtemplateandrender.CavePainting'>.
   It has both a 'render' method as well as an associated template.
-
+  in:
+  
 """
 import grok
 

Modified: grok/trunk/src/grok/tests/view/eithertemplateorrender.py
===================================================================
--- grok/trunk/src/grok/tests/view/eithertemplateorrender.py	2007-11-07 13:57:25 UTC (rev 81586)
+++ grok/trunk/src/grok/tests/view/eithertemplateorrender.py	2007-11-07 14:44:35 UTC (rev 81587)
@@ -4,9 +4,10 @@
   >>> grok.testing.grok(__name__)
   Traceback (most recent call last):
     ...
-  GrokError: Multiple possible ways to render view
+  ConfigurationExecutionError: martian.error.GrokError: Multiple possible ways to render view
   <class 'grok.tests.view.eithertemplateorrender.CavePainting'>.
   It has both a 'render' method as well as an associated template.
+  in:
 """
 import grok
 

Modified: grok/trunk/src/grok/tests/view/explicitimplicittemplate.py
===================================================================
--- grok/trunk/src/grok/tests/view/explicitimplicittemplate.py	2007-11-07 13:57:25 UTC (rev 81586)
+++ grok/trunk/src/grok/tests/view/explicitimplicittemplate.py	2007-11-07 14:44:35 UTC (rev 81587)
@@ -6,11 +6,12 @@
   >>> grok.testing.grok(__name__)
   Traceback (most recent call last):
     ...
-  GrokError: Multiple possible templates for view
+  ConfigurationExecutionError: martian.error.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'.
-
+  in:
+  
 """
 import grok
 

Modified: grok/trunk/src/grok/tests/view/inline_unassociated.py
===================================================================
--- grok/trunk/src/grok/tests/view/inline_unassociated.py	2007-11-07 13:57:25 UTC (rev 81586)
+++ grok/trunk/src/grok/tests/view/inline_unassociated.py	2007-11-07 14:44:35 UTC (rev 81587)
@@ -5,10 +5,11 @@
   >>> grok.testing.grok(__name__)
   Traceback (most recent call last):
   ...
-  GrokError: Found the following unassociated template(s) when grokking
+  ConfigurationExecutionError: martian.error.GrokError: Found the following unassociated template(s) when grokking
   'grok.tests.view.inline_unassociated': club.  Define view classes inheriting
   from grok.View to enable the template(s).
-
+  in:
+  
 """
 import grok
 

Modified: grok/trunk/src/grok/tests/view/notemplateorrender.py
===================================================================
--- grok/trunk/src/grok/tests/view/notemplateorrender.py	2007-11-07 13:57:25 UTC (rev 81586)
+++ grok/trunk/src/grok/tests/view/notemplateorrender.py	2007-11-07 14:44:35 UTC (rev 81587)
@@ -4,8 +4,9 @@
   >>> grok.testing.grok(__name__)
   Traceback (most recent call last):
     ...
-  GrokError: View <class 'grok.tests.view.notemplateorrender.CavePainting'>
+  ConfigurationExecutionError: martian.error.GrokError: View <class 'grok.tests.view.notemplateorrender.CavePainting'>
   has no associated template or 'render' method.
+  in:
 
 """
 

Modified: grok/trunk/src/grok/tests/view/templatenotfound.py
===================================================================
--- grok/trunk/src/grok/tests/view/templatenotfound.py	2007-11-07 13:57:25 UTC (rev 81586)
+++ grok/trunk/src/grok/tests/view/templatenotfound.py	2007-11-07 14:44:35 UTC (rev 81587)
@@ -5,9 +5,9 @@
   >>> grok.testing.grok(__name__)
   Traceback (most recent call last):
     ...
-  GrokError: View <class 'grok.tests.view.templatenotfound.Painting'>
+  ConfigurationExecutionError: martian.error.GrokError: View <class 'grok.tests.view.templatenotfound.Painting'>
   has no associated template or 'render' method.
-
+  in:
 """
 import grok
 

Modified: grok/trunk/src/grok/tests/view/unassociated.py
===================================================================
--- grok/trunk/src/grok/tests/view/unassociated.py	2007-11-07 13:57:25 UTC (rev 81586)
+++ grok/trunk/src/grok/tests/view/unassociated.py	2007-11-07 14:44:35 UTC (rev 81587)
@@ -5,11 +5,11 @@
   >>> grok.testing.grok(__name__)
   Traceback (most recent call last):
   ...
-  GrokError: Found the following unassociated template(s) when grokking
+  ConfigurationExecutionError: martian.error.GrokError: Found the following unassociated template(s) when grokking
   'grok.tests.view.unassociated': index.  Define view classes inheriting
   from grok.View to enable the template(s).
+  in:
 
-
 """
 import grok
 



More information about the Checkins mailing list