[Checkins] SVN: megrok.five/trunk/s First cut at bringing grok to Zope2/Five.

Philipp von Weitershausen philikon at philikon.de
Wed Feb 7 22:24:17 EST 2007


Log message for revision 72440:
  First cut at bringing grok to Zope2/Five.
  

Changed:
  A   megrok.five/trunk/setup.py
  A   megrok.five/trunk/src/
  A   megrok.five/trunk/src/megrok/
  A   megrok.five/trunk/src/megrok/__init__.py
  A   megrok.five/trunk/src/megrok/five/
  A   megrok.five/trunk/src/megrok/five/__init__.py
  A   megrok.five/trunk/src/megrok/five/component.py
  A   megrok.five/trunk/src/megrok/five/configure.zcml
  A   megrok.five/trunk/src/megrok/five/grokker.py
  A   megrok.five/trunk/src/megrok/five/view.py

-=-
Added: megrok.five/trunk/setup.py
===================================================================
--- megrok.five/trunk/setup.py	2007-02-08 03:18:00 UTC (rev 72439)
+++ megrok.five/trunk/setup.py	2007-02-08 03:24:16 UTC (rev 72440)
@@ -0,0 +1,23 @@
+from setuptools import setup, find_packages
+
+version = 0.1
+
+setup(name='megrok.five',
+      version=version,
+      description="grok integration for Zope 2",
+      long_description=open('README.txt').read(),
+      # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers
+      classifiers=[], 
+      keywords="",
+      author="Philipp von Weitershausen",
+      author_email="philipp at weitershausen.de",
+      url="",
+      license="ZPL 2.1",
+      package_dir={'': 'src'},
+      packages=find_packages('src'),
+      include_package_data=True,
+      zip_safe=False,
+      namespace_packages=['megrok'],
+      install_requires=['setuptools',
+                        'grok'],
+      )


Property changes on: megrok.five/trunk/setup.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: megrok.five/trunk/src/megrok/__init__.py
===================================================================
--- megrok.five/trunk/src/megrok/__init__.py	2007-02-08 03:18:00 UTC (rev 72439)
+++ megrok.five/trunk/src/megrok/__init__.py	2007-02-08 03:24:16 UTC (rev 72440)
@@ -0,0 +1,3 @@
+# make this directory a namespace package
+import pkg_resources
+pkg_resources.declare_namespace('megrok')


Property changes on: megrok.five/trunk/src/megrok/__init__.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: megrok.five/trunk/src/megrok/five/__init__.py
===================================================================
--- megrok.five/trunk/src/megrok/five/__init__.py	2007-02-08 03:18:00 UTC (rev 72439)
+++ megrok.five/trunk/src/megrok/five/__init__.py	2007-02-08 03:24:16 UTC (rev 72440)
@@ -0,0 +1 @@
+from megrok.five.component import Model, Application


Property changes on: megrok.five/trunk/src/megrok/five/__init__.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: megrok.five/trunk/src/megrok/five/component.py
===================================================================
--- megrok.five/trunk/src/megrok/five/component.py	2007-02-08 03:18:00 UTC (rev 72439)
+++ megrok.five/trunk/src/megrok/five/component.py	2007-02-08 03:24:16 UTC (rev 72440)
@@ -0,0 +1,9 @@
+import grok
+from OFS.SimpleItem import SimpleItem
+from OFS.ObjectManager import ObjectManager
+
+class Model(SimpleItem, grok.Model):
+    pass
+
+class Application(ObjectManager, grok.Model):
+    pass


Property changes on: megrok.five/trunk/src/megrok/five/component.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: megrok.five/trunk/src/megrok/five/configure.zcml
===================================================================
--- megrok.five/trunk/src/megrok/five/configure.zcml	2007-02-08 03:18:00 UTC (rev 72439)
+++ megrok.five/trunk/src/megrok/five/configure.zcml	2007-02-08 03:24:16 UTC (rev 72440)
@@ -0,0 +1 @@
+<grok package="." xmlns="http://namespaces.zope.org/grok" />
\ No newline at end of file


Property changes on: megrok.five/trunk/src/megrok/five/configure.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: megrok.five/trunk/src/megrok/five/grokker.py
===================================================================
--- megrok.five/trunk/src/megrok/five/grokker.py	2007-02-08 03:18:00 UTC (rev 72439)
+++ megrok.five/trunk/src/megrok/five/grokker.py	2007-02-08 03:24:16 UTC (rev 72440)
@@ -0,0 +1,71 @@
+import grok
+import Acquisition
+import Products
+from Products.Five.security import protectName, initializeClass
+
+from zope import interface, component
+from zope.security.checker import CheckerPublic
+
+from grok import util, meta
+import grok.interfaces
+import megrok.five
+
+class ViewGrokker(meta.ViewGrokker):
+    priority = -1   # beat grok.meta.ViewGrokker
+    # XXX this is weird, I should have to set a *higher* priority so
+    # that I'm executed *before* grok.meta.ViewGrokker (which should
+    # *never* be called at all).  Instead, I have to set a lower
+    # priority so that I'm executed afterwards and *my* adapter
+    # registration wins over his.  This is messed up.  FIXME
+
+    def register(self, context, name, factory, module_info, templates):
+        # Five views need to inherit from Acquisition currently, so
+        # let's create a subclass of the view class and mix in
+        # acquisition (evil, I know...)
+        old_factory = factory
+        factory = type(factory.__name__, (Acquisition.Explicit, factory),
+                       # deep Zope 2 traversal voodoo here (traversed
+                       # items need to have a __name__ property, apparently
+                       {'__name__': property(lambda self: self.__view_name__)})
+        factory.__module__ = module_info.dotted_name
+
+        super(ViewGrokker, self).register(context, name, factory, module_info,
+                                          templates)
+
+        # Do the Zope 2 security declarations (public by default, just
+        # like in grok). Note that we don't need to do any sanity
+        # checks here.  They have already been done at this point by
+        # the super class.
+        permissions = util.class_annotation(factory, 'grok.require', [])
+        if not permissions or permissions[0] in ('zope.Public', 'zope2.Public'):
+            permission = CheckerPublic
+        else:
+            permission = permissions[0]
+
+        protectName(factory, '__call__', permission)
+        initializeClass(factory)
+
+
+class ApplicationGrokker(grok.ClassGrokker):
+    component_class = megrok.five.Application
+    priority = 500
+    continue_scanning = True
+
+    def register(self, context, name, factory, module_info, templates):
+        full_name = module_info.dotted_name + "." + name
+        setattr(factory, 'meta_type', full_name)
+
+        interfaces = tuple(interface.implementedBy(factory))
+        info = {'name': full_name,
+                'action': 'createapp?name=%s' % full_name,
+                'product': 'Five',
+                'permission': 'Add %s' % full_name,
+                'visibility': 'Global',
+                'interfaces': interfaces,
+                'instance': factory,
+                'container_filter': None}
+        Products.meta_types += (info,)
+
+        component.provideUtility(factory,
+                                 provides=grok.interfaces.IApplication,
+                                 name=full_name)


Property changes on: megrok.five/trunk/src/megrok/five/grokker.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: megrok.five/trunk/src/megrok/five/view.py
===================================================================
--- megrok.five/trunk/src/megrok/five/view.py	2007-02-08 03:18:00 UTC (rev 72439)
+++ megrok.five/trunk/src/megrok/five/view.py	2007-02-08 03:24:16 UTC (rev 72440)
@@ -0,0 +1,20 @@
+from zope import component
+from zope.app.container.interfaces import INameChooser
+from OFS.interfaces import IObjectManager
+import grok.interfaces
+
+class CreateApp(grok.View):
+    """
+    Instantiates megrok.five.Application objects.  Meant to be invoked
+    from the ZMI add menu.
+    """
+    grok.context(IObjectManager)
+
+    def render(self, name):
+        factory = component.getUtility(grok.interfaces.IApplication, name=name)
+        obj = factory()
+        name = INameChooser(self.context).chooseName('', obj)
+        obj.id = name # Zope 2 wants objects to have an id attribute
+        self.context._setObject(name, obj)
+
+        self.redirect(self.url('manage_main'))


Property changes on: megrok.five/trunk/src/megrok/five/view.py
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Checkins mailing list