r13312 - in archetypes.configure: . trunk trunk/archetypes trunk/archetypes/configure

"Malthe Borch" <[email protected]>
Newsgroups gmane.comp.web.zope.plone.archetypes.cvs
Message-ID <[email protected]>
Author: mborch
Date: Wed Dec  1 15:53:17 2010
New Revision: 13312

Added:
   archetypes.configure/
   archetypes.configure/trunk/
   archetypes.configure/trunk/README.txt
   archetypes.configure/trunk/archetypes/
   archetypes.configure/trunk/archetypes/__init__.py
   archetypes.configure/trunk/archetypes/configure/
   archetypes.configure/trunk/archetypes/configure/__init__.py
   archetypes.configure/trunk/archetypes/configure/meta.zcml
   archetypes.configure/trunk/archetypes/configure/registry.py
   archetypes.configure/trunk/archetypes/configure/zcml.py
   archetypes.configure/trunk/setup.py
Log:
Initial import.

Added: archetypes.configure/trunk/README.txt
==============================================================================
--- (empty file)
+++ archetypes.configure/trunk/README.txt	Wed Dec  1 15:53:17 2010
@@ -0,0 +1,37 @@
+Introduction
+============
+
+This package adds a declarative interface for the registration of
+Archetypes content classes.
+
+Usage
+-----
+
+Use an ``at:register`` directive to register each of your content
+classes.
+
+Example configuration::
+
+    <configure
+        xmlns="http://namespaces.zope.org/zope"
+        xmlns:five="http://namespaces.zope.org/five"
+        xmlns:at="http://namespaces.plone.org/archetypes">
+
+      <five:registerPackage package="." />
+
+      <permission id="example.Add" title="collective.example: Add example" />
+
+      <at:register
+          class=".content.Example"
+          permission="example.Add"
+          />
+
+    </configure>
+
+You do not need to (and should not) call ``atapi.registerType`` on
+your content classes. This is done automatically by the framework.
+
+Credits
+-------
+
+Malthe Borch <[email protected]>

Added: archetypes.configure/trunk/archetypes/__init__.py
==============================================================================
--- (empty file)
+++ archetypes.configure/trunk/archetypes/__init__.py	Wed Dec  1 15:53:17 2010
@@ -0,0 +1,7 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+    from pkgutil import extend_path
+    __path__ = extend_path(__path__, __name__)
+

Added: archetypes.configure/trunk/archetypes/configure/__init__.py
==============================================================================
--- (empty file)
+++ archetypes.configure/trunk/archetypes/configure/__init__.py	Wed Dec  1 15:53:17 2010
@@ -0,0 +1 @@
+#

Added: archetypes.configure/trunk/archetypes/configure/meta.zcml
==============================================================================
--- (empty file)
+++ archetypes.configure/trunk/archetypes/configure/meta.zcml	Wed Dec  1 15:53:17 2010
@@ -0,0 +1,15 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:meta="http://namespaces.zope.org/meta">
+
+  <meta:directives namespace="http://namespaces.plone.org/archetypes">
+
+    <meta:directive
+        name="register"
+        schema=".zcml.IRegisterDirective"
+        handler=".zcml.register"
+        />
+
+  </meta:directives>
+
+</configure>

Added: archetypes.configure/trunk/archetypes/configure/registry.py
==============================================================================
--- (empty file)
+++ archetypes.configure/trunk/archetypes/configure/registry.py	Wed Dec  1 15:53:17 2010
@@ -0,0 +1,39 @@
+import zope.security.interfaces
+import zope.component
+
+from Products.Archetypes import atapi
+from Products.CMFCore import utils
+
+
+class Registration(object):
+    def __init__(self, product, class_, permission_id):
+        self.product = product
+        self.class_ = class_
+        self.permission_id = permission_id
+
+    def __call__(self, context):
+        # Load type information
+        content_types, constructors, ftis = atapi.process_types(
+            atapi.listTypes(self.product), self.product
+            )
+
+        # Loop through all content types for this product
+        for atype, constructor in zip(content_types, constructors):
+            # Bad API impedance!
+            if not atype is self.class_:
+                continue
+
+            # Look up Zope 3 permission component
+            permission = zope.component.getUtility(
+                zope.security.interfaces.IPermission,
+                self.permission_id
+                )
+
+            # Set default roles to register permission
+            #setDefaultRoles(permission.title, ())
+
+            utils.ContentInit('%s: %s' % (self.product, atype.portal_type),
+                content_types=(atype, ),
+                permission=permission.title,
+                extra_constructors=(constructor,),
+                ).initialize(context)

Added: archetypes.configure/trunk/archetypes/configure/zcml.py
==============================================================================
--- (empty file)
+++ archetypes.configure/trunk/archetypes/configure/zcml.py	Wed Dec  1 15:53:17 2010
@@ -0,0 +1,64 @@
+import Products
+import Products.Archetypes.atapi
+
+import zope.interface
+import zope.schema
+import zope.configuration.fields
+import zope.i18nmessageid
+
+from registry import Registration
+
+_ = zope.i18nmessageid.MessageFactory('archetypes')
+
+_add_permission = "cmf.AddPortalContent"
+
+
+class IRegisterDirective(zope.interface.Interface):
+    class_ = zope.configuration.fields.GlobalObject(
+        title=_("Archetypes content class"),
+        description=_("Python name of the implementation object.  This"
+                      " must identify an object in a module using the"
+                      " full dotted name."),
+        required=True,
+        )
+
+    package = zope.configuration.fields.GlobalObject(
+        title=_(u"Target package"),
+        description=_(u"Defaults to the configuration context's package."),
+        required=False,
+        )
+
+    product = zope.schema.TextLine(
+        title=_("Product name"),
+        description=_("Zope 2 product name. This defaults to the "
+                      "configuration context's module name."),
+        required=False,
+        )
+
+    permission = zope.security.zcml.Permission(
+        title=_("Permission"),
+        description=_("Permission required to add this content object."),
+        required=False,
+        )
+
+
+def handler(product, package, class_, permission_id):
+    Products.Archetypes.atapi.registerType(class_, product)
+    registration = Registration(product, class_, permission_id)
+    to_initialize = Products.__dict__.setdefault('_packages_to_initialize', [])
+    to_initialize.append((package, registration))
+
+
+def register(_context, class_, product=None,
+             package=None, permission=_add_permission):
+    if package is None:
+        package = _context.package
+
+    if product is None:
+        product = package.__name__
+
+    _context.action(
+        discriminator=('register', class_),
+        callable=handler,
+        args=(product, package, class_, permission),
+        )

Added: archetypes.configure/trunk/setup.py
==============================================================================
--- (empty file)
+++ archetypes.configure/trunk/setup.py	Wed Dec  1 15:53:17 2010
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+import os
+from setuptools import setup, find_packages
+
+version = "0.1"
+here = os.path.abspath(os.path.dirname(__file__))
+long_description = open(os.path.join(here, 'README.txt')).read()
+
+setup(name='archetypes.configure',
+      version=version,
+      description="Declarative content type configuration for Archetypes."
+      long_description=long_description,
+      # Get more strings from
+      # http://pypi.python.org/pypi?%3Aaction=list_classifiers
+      classifiers=[
+        'Framework :: Plone',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: GNU General Public License (GPL)',
+        ],
+      keywords='',
+      author='Plone Foundation',
+      author_email='[email protected]',
+      license='GPL',
+      packages=find_packages(exclude=['ez_setup']),
+      namespace_packages=['archetypes', ],
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=[
+          'setuptools',
+          # -*- Extra requirements: -*-,
+          ],
+      entry_points="""
+      # -*- entry_points -*-
+      [z3c.autoinclude.plugin]
+      target = plone
+      """
+      )

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.