[Checkins] SVN: grokcore.view/trunk/ Change how static resources are found, in order to work properly with inheritance.

Sylvain Viollow cvs-admin at zope.org
Sun Apr 29 12:51:01 UTC 2012


Log message for revision 125375:
  Change how static resources are found, in order to work properly with inheritance.
  

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

-=-
Modified: grokcore.view/trunk/CHANGES.txt
===================================================================
--- grokcore.view/trunk/CHANGES.txt	2012-04-29 12:50:06 UTC (rev 125374)
+++ grokcore.view/trunk/CHANGES.txt	2012-04-29 12:50:57 UTC (rev 125375)
@@ -4,9 +4,12 @@
 2.6.2 (unreleased)
 ------------------
 
-- Nothing changed yet.
+- 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
+  component. This fix missing resources when you extend the component
+  and don't redefined the template.
 
-
 2.6.1 (2011-06-28)
 ------------------
 

Modified: grokcore.view/trunk/src/grokcore/view/components.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/components.py	2012-04-29 12:50:06 UTC (rev 125374)
+++ grokcore.view/trunk/src/grokcore/view/components.py	2012-04-29 12:50:57 UTC (rev 125375)
@@ -119,12 +119,12 @@
     def __init__(self, context, request):
         super(View, self).__init__(context, request)
         self.__name__ = getattr(self, '__view_name__', None)
-
-        if getattr(self, 'module_info', None) is not None:
+        static_name = getattr(self, '__static_name__', None)
+        if static_name is not None:
             self.static = component.queryAdapter(
                 self.request,
                 interface.Interface,
-                name=self.module_info.package_dotted_name)
+                name=static_name)
         else:
             self.static = None
 

Modified: grokcore.view/trunk/src/grokcore/view/templatereg.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/templatereg.py	2012-04-29 12:50:06 UTC (rev 125374)
+++ grokcore.view/trunk/src/grokcore/view/templatereg.py	2012-04-29 12:50:57 UTC (rev 125375)
@@ -303,18 +303,29 @@
     try:
         factory.template = lookup(
             module_info, template_name, mark_as_associated=True)
+
+        # If we associate a template, set the static_name to use to
+        # the same package name as where the template is found.
+        factory.__static_name__ = module_info.package_dotted_name
+
+        # We now have a template.
         factory_have_template = True
     except TemplateLookupError:
         pass
 
-    # Check for have both render and template
-    if factory_have_template and has_render(factory):
-        raise GrokError(
-            "Multiple possible ways to render %s %r. "
-            "It has both a 'render' method as well as "
-            "an associated template." %
-            (component_name, factory), factory)
+    if has_render(factory):
+        # Check for have both render and template
+        if factory_have_template:
+            raise GrokError(
+                "Multiple possible ways to render %s %r. "
+                "It has both a 'render' method as well as "
+                "an associated template." %
+                (component_name, factory), factory)
 
+        # Set static_name to use if no template are found.
+        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 "



More information about the checkins mailing list