[Checkins] SVN: grok/trunk/ merged ksmith_mcweekly-layers-011 branch, all tests pass

Kevin Smith kevin at mcweekly.com
Wed Sep 19 13:36:49 EDT 2007


Log message for revision 79754:
  merged ksmith_mcweekly-layers-011 branch, all tests pass

Changed:
  U   grok/trunk/CHANGES.txt
  U   grok/trunk/CREDITS.txt
  U   grok/trunk/src/grok/__init__.py
  U   grok/trunk/src/grok/components.py
  U   grok/trunk/src/grok/directive.py
  U   grok/trunk/src/grok/interfaces.py
  U   grok/trunk/src/grok/meta.py

-=-
Modified: grok/trunk/CHANGES.txt
===================================================================
--- grok/trunk/CHANGES.txt	2007-09-19 17:18:07 UTC (rev 79753)
+++ grok/trunk/CHANGES.txt	2007-09-19 17:36:49 UTC (rev 79754)
@@ -6,6 +6,7 @@
 
 Feature changes
 ---------------
+* Integrated skins and layers. grok.layer, grok.IGrokLayer, grok.Skin 
 
 * Removed grok.define_permission in favor of the grok.Permission
   component base class

Modified: grok/trunk/CREDITS.txt
===================================================================
--- grok/trunk/CREDITS.txt	2007-09-19 17:18:07 UTC (rev 79753)
+++ grok/trunk/CREDITS.txt	2007-09-19 17:36:49 UTC (rev 79754)
@@ -27,6 +27,8 @@
 
 * Wim Boucqaert (admin interface layout improvements)
 
+* Kevin M. Smith (skins and layers support)
+
 * ME GROK (team mascot)
 
 Thank you

Modified: grok/trunk/src/grok/__init__.py
===================================================================
--- grok/trunk/src/grok/__init__.py	2007-09-19 17:18:07 UTC (rev 79753)
+++ grok/trunk/src/grok/__init__.py	2007-09-19 17:36:49 UTC (rev 79754)
@@ -36,9 +36,10 @@
 from grok.components import Application, Form, AddForm, EditForm, DisplayForm
 from grok.components import Indexes
 from grok.components import Permission, Role
+from grok.components import Skin, IGrokLayer
 from grok.directive import (context, name, title, template, templatedir,
                             provides, baseclass, global_utility, local_utility,
-                            permissions, require, site)
+                            permissions, require, site, layer)
 from grok._grok import do_grok as grok  # Avoid name clash within _grok
 from grok._grok import grok_component
 from grok._grok import SubscribeDecorator as subscribe

Modified: grok/trunk/src/grok/components.py
===================================================================
--- grok/trunk/src/grok/components.py	2007-09-19 17:18:07 UTC (rev 79753)
+++ grok/trunk/src/grok/components.py	2007-09-19 17:36:49 UTC (rev 79754)
@@ -30,6 +30,7 @@
 from zope.publisher.browser import BrowserPage
 from zope.publisher.interfaces import NotFound
 from zope.publisher.interfaces.browser import (IBrowserPublisher,
+                                               IDefaultBrowserLayer,
                                                IBrowserRequest)
 from zope.publisher.publish import mapply
 from zope.pagetemplate import pagetemplate, pagetemplatefile
@@ -485,3 +486,9 @@
 
 class Role(object):
     pass
+
+class IGrokLayer(interface.Interface):
+    pass
+
+class Skin(object):
+    pass

Modified: grok/trunk/src/grok/directive.py
===================================================================
--- grok/trunk/src/grok/directive.py	2007-09-19 17:18:07 UTC (rev 79753)
+++ grok/trunk/src/grok/directive.py	2007-09-19 17:36:49 UTC (rev 79754)
@@ -120,3 +120,5 @@
 title = SingleTextDirective('grok.title', ClassDirectiveContext())
 permissions = MultiValueOnceDirective(
     'grok.permissions', ClassDirectiveContext())
+layer = InterfaceOrClassDirective('grok.layer',
+                           ClassOrModuleDirectiveContext())

Modified: grok/trunk/src/grok/interfaces.py
===================================================================
--- grok/trunk/src/grok/interfaces.py	2007-09-19 17:18:07 UTC (rev 79753)
+++ grok/trunk/src/grok/interfaces.py	2007-09-19 17:36:49 UTC (rev 79754)
@@ -42,6 +42,8 @@
     EditForm = interface.Attribute("Base class for edit forms.")
     DisplayForm = interface.Attribute("Base class for display forms.")
     Indexes = interface.Attribute("Base class for catalog index definitions.")
+    Layer = interface.Attribute("Base interface for layers.")
+    Skin = interface.Attribute("Base class for skin.")
 
 
 class IGrokErrors(interface.Interface):
@@ -76,6 +78,17 @@
 
         This directive can only be used on class level."""
 
+    def layer(layer):
+        """Declare the layer for the view.
+
+        This directive acts as a contraint on the 'request' of
+        grok.View. This directive can only be used on class level."""
+
+    def skin(skin):
+        """Declare this layer as a named skin.
+
+        This directive can only be used on class level."""
+
     def template(template):
         """Declare the template name for a view.
 

Modified: grok/trunk/src/grok/meta.py
===================================================================
--- grok/trunk/src/grok/meta.py	2007-09-19 17:18:07 UTC (rev 79753)
+++ grok/trunk/src/grok/meta.py	2007-09-19 17:36:49 UTC (rev 79754)
@@ -19,7 +19,8 @@
 from zope import interface, component
 from zope.publisher.interfaces.browser import (IDefaultBrowserLayer,
                                                IBrowserRequest,
-                                               IBrowserPublisher)
+                                               IBrowserPublisher,
+                                               IBrowserSkinType)
 from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest
 from zope.security.permission import Permission
 from zope.security.interfaces import IPermission
@@ -142,6 +143,7 @@
     component_class = grok.View
 
     def grok(self, name, factory, context, module_info, templates):
+
         view_context = util.determine_class_context(factory, context)
 
         factory.module_info = module_info
@@ -191,12 +193,15 @@
                 raise GrokError("View %r has no associated template or "
                                 "'render' method." % factory, factory)
 
+        # grab layer from class or module
+        view_layer = determine_class_directive('grok.layer', factory, module_info, default=IDefaultBrowserLayer)
+        
         view_name = util.class_annotation(factory, 'grok.name',
                                           factory_name)
         # __view_name__ is needed to support IAbsoluteURL on views
         factory.__view_name__ = view_name
         component.provideAdapter(factory,
-                                 adapts=(view_context, IDefaultBrowserLayer),
+                                 adapts=(view_context, view_layer),
                                  provides=interface.Interface,
                                  name=view_name)
 
@@ -631,6 +636,7 @@
         """Create the catalog if needed and return it.
 
         If the catalog already exists, return that.
+
         """
         catalog = zope.component.queryUtility(
             ICatalog, name=self.catalog_name, context=site, default=None)
@@ -650,3 +656,28 @@
         intids = IntIds()
         setupUtility(site, intids, IIntIds)
         return intids
+
+
+class ILayerGrokker(martian.ClassGrokker):
+    component_class = grok.IGrokLayer
+
+
+class SkinGrokker(martian.ClassGrokker):
+    component_class = grok.Skin
+
+    def grok(self, name, factory, context, module_info, templates):
+
+        layer = determine_class_directive('grok.layer', factory, module_info, default=IBrowserRequest)
+        name = grok.util.class_annotation(factory, 'grok.name', factory.__name__.lower())
+        zope.component.interface.provideInterface(name, layer, IBrowserSkinType)
+        return True
+
+
+def determine_class_directive(directive_name, factory, module_info, default=None):
+    directive = util.class_annotation(factory, directive_name, None)
+    if directive is None:
+        directive = module_info.getAnnotation(directive_name, None)
+    if directive is not None:
+        return directive
+    else:
+        return default



More information about the Checkins mailing list