[Checkins] SVN: five.grok/branches/regebro-grokcore.view/src/five/grok/ Moving template handling to grokcore.view.

Lennart Regebro regebro at gmail.com
Fri Jul 18 08:43:47 EDT 2008


Log message for revision 88498:
  Moving template handling to grokcore.view.
  

Changed:
  U   five.grok/branches/regebro-grokcore.view/src/five/grok/__init__.py
  U   five.grok/branches/regebro-grokcore.view/src/five/grok/components.py
  U   five.grok/branches/regebro-grokcore.view/src/five/grok/configure.zcml
  D   five.grok/branches/regebro-grokcore.view/src/five/grok/directive.py
  U   five.grok/branches/regebro-grokcore.view/src/five/grok/meta.py
  D   five.grok/branches/regebro-grokcore.view/src/five/grok/templatereg.py
  U   five.grok/branches/regebro-grokcore.view/src/five/grok/testing.py

-=-
Modified: five.grok/branches/regebro-grokcore.view/src/five/grok/__init__.py
===================================================================
--- five.grok/branches/regebro-grokcore.view/src/five/grok/__init__.py	2008-07-18 12:41:22 UTC (rev 88497)
+++ five.grok/branches/regebro-grokcore.view/src/five/grok/__init__.py	2008-07-18 12:43:46 UTC (rev 88498)
@@ -5,10 +5,10 @@
 
 from grokcore.component import Adapter, MultiAdapter, GlobalUtility
 from grokcore.component import context, name, provides, subscribe
-from grokcore.view.components import PageTemplate
+from grokcore.view import PageTemplate
+from grokcore.view import template, require, layer, templatedir
 
 from five.grok.components import View, Model, IGrokLayer, Skin
-from five.grok.directive import require, layer, template, templatedir
 
 # I don't know why this is necessary:
 from five.grok import testing
\ No newline at end of file

Modified: five.grok/branches/regebro-grokcore.view/src/five/grok/components.py
===================================================================
--- five.grok/branches/regebro-grokcore.view/src/five/grok/components.py	2008-07-18 12:41:22 UTC (rev 88497)
+++ five.grok/branches/regebro-grokcore.view/src/five/grok/components.py	2008-07-18 12:43:46 UTC (rev 88498)
@@ -33,4 +33,4 @@
     pass
 
 class Skin(object):
-    pass
+    pass
\ No newline at end of file

Modified: five.grok/branches/regebro-grokcore.view/src/five/grok/configure.zcml
===================================================================
--- five.grok/branches/regebro-grokcore.view/src/five/grok/configure.zcml	2008-07-18 12:41:22 UTC (rev 88497)
+++ five.grok/branches/regebro-grokcore.view/src/five/grok/configure.zcml	2008-07-18 12:43:46 UTC (rev 88498)
@@ -16,6 +16,7 @@
     title="View"
     />
 
+  <include package="grokcore.view" file="meta.zcml" />
   <include package="zope.app.basicskin" />
   <include package="zope.app.rotterdam" />
   

Deleted: five.grok/branches/regebro-grokcore.view/src/five/grok/directive.py
===================================================================
--- five.grok/branches/regebro-grokcore.view/src/five/grok/directive.py	2008-07-18 12:41:22 UTC (rev 88497)
+++ five.grok/branches/regebro-grokcore.view/src/five/grok/directive.py	2008-07-18 12:43:46 UTC (rev 88498)
@@ -1,50 +0,0 @@
-import martian
-from martian.directive import StoreMultipleTimes
-
-class RequireDirectiveStore(StoreMultipleTimes):
-
-    def get(self, directive, component, default):
-        permissions = getattr(component, directive.dotted_name(), default)
-        if (permissions is default) or not permissions:
-            return default
-        if len(permissions) > 1:
-            raise GrokError('grok.require was called multiple times in '
-                            '%r. It may only be set once for a class.'
-                            % component, component)
-        return permissions[0]
-
-    def pop(self, locals_, directive):
-        return locals_[directive.dotted_name()].pop()
-
-
-class require(martian.Directive):
-    scope = martian.CLASS
-    store = RequireDirectiveStore()
-    validate = martian.validateText
-
-    def __call__(self, func):
-        # grok.require can be used both as a class-level directive and
-        # as a decorator for methods.  Therefore we return a decorator
-        # here, which may be used for methods, or simply ignored when
-        # used as a directive.
-        frame = sys._getframe(1)
-        permission = self.store.pop(frame.f_locals, self)
-        self.set(func, [permission])
-        return func
-
-    
-class layer(martian.Directive):
-    scope = martian.CLASS_OR_MODULE
-    store = martian.ONCE
-    validate = martian.validateInterfaceOrClass
-
-class template(martian.Directive):
-    scope = martian.CLASS
-    store = martian.ONCE
-    validate = martian.validateText
-
-class templatedir(martian.Directive):
-    scope = martian.MODULE
-    store = martian.ONCE
-    validate = martian.validateText
-    
\ No newline at end of file

Modified: five.grok/branches/regebro-grokcore.view/src/five/grok/meta.py
===================================================================
--- five.grok/branches/regebro-grokcore.view/src/five/grok/meta.py	2008-07-18 12:41:22 UTC (rev 88497)
+++ five.grok/branches/regebro-grokcore.view/src/five/grok/meta.py	2008-07-18 12:43:46 UTC (rev 88498)
@@ -10,7 +10,7 @@
 from Products.Five.security import protectClass
 from Globals import InitializeClass as initializeClass
 
-import templatereg
+from grokcore.view import templatereg
 
 def default_view_name(factory, module=None, **data):
     return factory.__name__.lower()
@@ -85,72 +85,7 @@
             return not getattr(factory, 'render', None)
         templates.checkTemplates(module_info, factory, 'view',
                                  has_render, has_no_render)
-        
-        
-class FilesystemPageTemplateGrokker(martian.GlobalGrokker):
-    # do this early on, but after ModulePageTemplateGrokker, as
-    # findFilesystem depends on module-level templates to be
-    # already grokked for error reporting
-    martian.priority(999)
 
-    def grok(self, name, module, module_info, config, **kw):
-        templates = module_info.getAnnotation('grok.templates', None)
-        if templates is None:
-            return False
-        config.action(
-            discriminator=None,
-            callable=templates.findFilesystem,
-            args=(module_info,)
-            )
-        return True
-
-class TemplateGrokker(martian.GlobalGrokker):
-    # this needs to happen before any other grokkers execute that use
-    # the template registry
-    martian.priority(1001)
-
-    def grok(self, name, module, module_info, config, **kw):
-        module.__grok_templates__ = templatereg.TemplateRegistry()
-        return True
-    
-import grokcore.view
-class ModulePageTemplateGrokker(martian.InstanceGrokker):
-    martian.component(grokcore.view.components.BaseTemplate)
-    # this needs to happen before any other grokkers execute that actually
-    # use the templates
-    martian.priority(1000)
-    
-    def grok(self, name, instance, module_info, config, **kw):
-        templates = module_info.getAnnotation('grok.templates', None)
-        if templates is None:
-            return False
-        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
-    
-class UnassociatedTemplatesGrokker(martian.GlobalGrokker):
-    martian.priority(-1001)
-
-    def grok(self, name, module, module_info, config, **kw):
-        templates = module_info.getAnnotation('grok.templates', None)
-        if templates is None:
-            return False
-
-        config.action(
-            discriminator=None,
-            callable=templates.checkUnassociated,
-            args=(module_info,)
-            )
-        return True
-
 class SkinGrokker(martian.ClassGrokker):
     martian.component(grok.Skin)
     martian.directive(grok.layer, default=IBrowserRequest)
@@ -163,3 +98,13 @@
             args=(name, layer, IBrowserSkinType)
             )
         return True
+
+
+import grokcore.component
+class PageTemplateFileFactory(grokcore.component.GlobalUtility):
+
+    grokcore.component.implements(grokcore.view.interfaces.ITemplateFileFactory)
+    grokcore.component.name('pt')
+
+    def __call__(self, filename, _prefix=None):
+        return grokcore.view.components.PageTemplate(filename=filename, _prefix=_prefix)

Deleted: five.grok/branches/regebro-grokcore.view/src/five/grok/templatereg.py
===================================================================
--- five.grok/branches/regebro-grokcore.view/src/five/grok/templatereg.py	2008-07-18 12:41:22 UTC (rev 88497)
+++ five.grok/branches/regebro-grokcore.view/src/five/grok/templatereg.py	2008-07-18 12:43:46 UTC (rev 88498)
@@ -1,132 +0,0 @@
-from martian.error import GrokError
-from martian import util
-
-import os
-import zope.component
-from five import grok
-import warnings
-
-class TemplateRegistry(object):
-
-    def __init__(self):
-        self._reg = {}
-
-    def register(self, name, template):
-        self._reg[name] = dict(template=template, associated=False)
-
-    def markAssociated(self, name):
-        self._reg[name]['associated'] = True
-
-    def get(self, name):
-        entry = self._reg.get(name)
-        if entry is None:
-            return None
-        return entry['template']
-
-    def findFilesystem(self, module_info):
-        template_dir_name = grok.templatedir.bind().get(
-            module=module_info.getModule())
-        if template_dir_name is None:
-            template_dir_name = module_info.name + '_templates'
-
-        template_dir = module_info.getResourcePath(template_dir_name)
-
-        if not os.path.isdir(template_dir):
-            return
-
-        if module_info.isPackage():
-            return
-
-        for template_file in os.listdir(template_dir):
-            if template_file.startswith('.') or template_file.endswith('~'):
-                continue
-
-            template_name, extension = os.path.splitext(template_file)
-            extension = extension[1:] # Get rid of the leading dot.
-            template_factory = zope.component.queryUtility(
-                grok.interfaces.ITemplateFileFactory,
-                name=extension)
-
-            if template_factory is None:
-                # Warning when importing files. This should be
-                # allowed because people may be using editors that generate
-                # '.bak' files and such.
-                warnings.warn("File '%s' has an unrecognized extension in "
-                              "directory '%s'" %
-                              (template_file, template_dir), UserWarning, 2)
-                continue
-
-            inline_template = self.get(template_name)
-            if inline_template:
-                raise GrokError("Conflicting templates found for name '%s' "
-                                "in module %r, either inline and in template "
-                                "directory '%s', or two templates with the "
-                                "same name and different extensions."
-                                % (template_name, module_info.getModule(),
-                                   template_dir), inline_template)
-
-            template = template_factory(template_file, template_dir)
-            template_path = os.path.join(template_dir, template_file)
-            template._annotateGrokInfo(template_name, template_path)
-
-            self.register(template_name, template)
-
-    def listUnassociated(self):
-        for name, entry in self._reg.iteritems():
-            if not entry['associated']:
-                yield name
-
-    def checkUnassociated(self, module_info):
-        unassociated = list(self.listUnassociated())
-        if unassociated:
-            msg = (
-                "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)))
-            warnings.warn(msg, UserWarning, 1)
-
-    def checkTemplates(self, module_info, factory, component_name,
-                       has_render, has_no_render):
-        factory_name = factory.__name__.lower()
-        template_name = grok.template.bind().get(factory)
-        if template_name is None:
-            template_name = factory_name
-
-        if factory_name != template_name:
-            # grok.template is being used
-
-            if self.get(factory_name):
-                raise GrokError("Multiple possible templates for %s %r. It "
-                                "uses grok.template('%s'), but there is also "
-                                "a template called '%s'."
-                                % (component_name, factory, template_name,
-                                   factory_name), factory)
-        template = self.get(template_name)
-        if template is not None:
-            if has_render(factory):
-                # 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 %s %r. "
-                    "It has both a 'render' method as well as "
-                    "an associated template." %
-                    (component_name, factory), factory)
-            self.markAssociated(template_name)
-            factory.template = template
-            template._initFactory(factory)
-        else:
-            if has_no_render(factory):
-                # we do not accept a view without any way to render it
-                raise GrokError("%s %r has no associated template or "
-                                "'render' method." %
-                                (component_name.title(), factory), factory)
-
-import grokcore.view
-class PageTemplateFileFactory(grok.GlobalUtility):
-
-    grok.implements(grok.interfaces.ITemplateFileFactory)
-    grok.name('pt')
-
-    def __call__(self, filename, _prefix=None):
-        return grokcore.view.components.PageTemplate(filename=filename, _prefix=_prefix)

Modified: five.grok/branches/regebro-grokcore.view/src/five/grok/testing.py
===================================================================
--- five.grok/branches/regebro-grokcore.view/src/five/grok/testing.py	2008-07-18 12:41:22 UTC (rev 88497)
+++ five.grok/branches/regebro-grokcore.view/src/five/grok/testing.py	2008-07-18 12:43:46 UTC (rev 88498)
@@ -23,7 +23,6 @@
     config = ConfigurationMachine()
     zcml.do_grok('grokcore.component.meta', config)
     zcml.do_grok('five.grok.meta', config)
-    zcml.do_grok('five.grok.templatereg', config)
     zcml.do_grok(module_name, config)
     config.execute_actions()
 



More information about the Checkins mailing list