[Zope3-checkins] CVS: Zope3/src/zope/app/utilities - content.py:1.1.2.1 configure.zcml:1.1.2.8 instance.py:1.1.2.5 schema.py:1.1.2.16 add.pt:NONE definition.py:NONE definition.zcml:NONE edit.pt:NONE instance.zcml:NONE permission_edit.pt:NONE

Stephan Richter srichter at cosmos.phy.tufts.edu
Fri Aug 15 11:05:12 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/utilities
In directory cvs.zope.org:/tmp/cvs-serv12471/utilities

Modified Files:
      Tag: dreamcatcher-ttwschema-branch
	configure.zcml instance.py schema.py 
Added Files:
      Tag: dreamcatcher-ttwschema-branch
	content.py 
Removed Files:
      Tag: dreamcatcher-ttwschema-branch
	add.pt definition.py definition.zcml edit.pt instance.zcml 
	permission_edit.pt 
Log Message:
Check point. Refactored all of the new code and moved it to the right places.

Everything still broken though. But they are just import problems from the
move.


=== Added File Zope3/src/zope/app/utilities/content.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Content Component Definition and Instance

$Id: content.py,v 1.1.2.1 2003/08/15 14:04:56 srichter Exp $
"""
__metaclass__ = type

from persistence import Persistent
from persistence.dict import PersistentDict
from zope.app import zapi
from zope.app.interfaces.container import IAdding 
from zope.app.interfaces.utilities.content import \
     IContentComponentDefinition, IContentComponentInstance
from zope.app.services.menu import LocalBrowserMenuItem
from zope.app.services.utility import UtilityRegistration
from zope.context import ContextMethod
from zope.interface import directlyProvides, implements
from zope.schema import getFields, getFieldsInOrder
from zope.security.checker import CheckerPublic, Checker, defineChecker
from zope.security.proxy import trustedRemoveSecurityProxy


class ContentComponentDefinition(Persistent):

    implements(IContentComponentDefinition)

    def __init__(self, name=u'', schema=None):
        self.name = name
        self.schema = schema
        self.permissions = PersistentDict()


class ContentComponentDefinitionRegistration(UtilityRegistration):
    """Content Component Registration"""

    menuitem_id = None
    menu = None
    
    def activated(self):
        """Once activated, we have to register the new Content Object with the
        appropriate menu.
        """
        service = zapi.getService(self, "BrowserMenu")
        # XXX: Should use queryInheritedMenu()
        self.menu = service.queryLocalMenu('add_content')
        # Creating the menu item
        # XXX: Should be configurable
        item = LocalBrowserMenuItem()
        item.interface = IAdding
        item.action = 'AddContentComponent/' + self.name
        item.title = self.name
        item.permission = 'zope.ManageContent'
        self.menuitem_id = self.menu.setObject('something', item)
        component = self.getComponent()
        component.name = self.name
    activated = ContextMethod(activated)
        
    def deactivated(self):
        """Once activated, we have to unregister the new Content Object with
        the appropriate menu."""
        self.menu.__delitem__(self.menuitem_id)
        self.menu = None
        self.menuitem_id = None 
        component = self.getComponent()
        component.name = '<component not activated>'
    deactivated = ContextMethod(deactivated)

    
class ContentComponentInstance(Persistent):

    implements(IContentComponentInstance)

    def __init__(self, name, schema, schemaPermissions=None):
        super(ContentComponentInstance, self).__init__()

        # Save the name of the object
        self.__name__ = name

        # XXX: We really should make a copy of the schema first, so that it
        #      cannot be changed.
        self.__schema = schema
        # Add the new attributes, if there was a schema passed in
        if schema is not None:
            for name, field in getFields(schema).items():
                setattr(self, name, field.default)
            directlyProvides(self, schema)

            # Build up a Checker rules and store it for later
            if schemaPermissions is None:
                schemaPermissions = {}
            self.__checker_getattr = PersistentDict()
            self.__checker_setattr = PersistentDict()
            for name in getFields(schema):
                get_perm, set_perm = schemaPermissions.get(name, (None, None))
                self.__checker_getattr[name] = get_perm or CheckerPublic
                self.__checker_setattr[name] = set_perm or CheckerPublic

            # Always permit our class's public methods
            self.__checker_getattr['getSchema'] = CheckerPublic


    def __setattr__(self, key, value):
        if (key in ('getSchema',) or
            key.startswith('_p_') or
            key.startswith('__') or
            key.startswith('_ContentComponentInstance__')):
            return super(ContentComponentInstance, self).__setattr__(key,
                                                                     value)

        is_schema_field = self.__schema is not None and \
                          key in getFields(self.__schema).keys()

        if is_schema_field:
            super(ContentComponentInstance, self).__setattr__(key, value)
        else:
            raise AttributeError, 'Attribute not available'

    __setattr__ = ContextMethod(__setattr__)


    def getSchema(self):
        return self.__schema

    def __repr__(self):
        return '<ContentComponentInstance called %s>' %self.__name__


def ContentComponentInstanceChecker(instance):
    """A function that can be registered as a Checker in defineChecker()"""
    return Checker(instance.__checker_getattr.get,
                   instance.__checker_setattr.get)

defineChecker(ContentComponentInstance, ContentComponentInstanceChecker)




=== Zope3/src/zope/app/utilities/configure.zcml 1.1.2.7 => 1.1.2.8 ===
--- Zope3/src/zope/app/utilities/configure.zcml:1.1.2.7	Wed Aug 13 15:53:46 2003
+++ Zope3/src/zope/app/utilities/configure.zcml	Fri Aug 15 10:04:56 2003
@@ -1,160 +1,86 @@
-<configure
-  xmlns="http://namespaces.zope.org/zope"
-  xmlns:browser="http://namespaces.zope.org/browser">
-
-  <browser:menu
-      id="add_schema_field"
-      title="Menu of Fields to be added to a schema."/>
-
-  <browser:view
-      name="+"
-      for="zope.app.interfaces.utilities.IMutableSchema"
-      class=".schema.SchemaAdding"
-      permission="zope.ManageContent"
-      allowed_attributes="addingInfo"
-      menu="zmi_actions"
-      title="Add"
-      >
-        <browser:page name="index.html"  template="add.pt" />
-        <browser:page name="action.html" attribute="action" />
-  </browser:view>
+<configure xmlns="http://namespaces.zope.org/zope">
 
+<!-- Mutable Schema -->
 
   <content class=".schema.SchemaUtility">
 
     <factory
-      permission="zope.ManageServices"
-      title="Persistent Schema Utility"
-      description="A Persistent Schema that can be edited through the web"
-      />
+        permission="zope.ManageServices"
+        title="Persistent Schema Utility"
+        description="A Persistent Schema that can be edited through the web"/>
 
     <implements
-      interface="zope.app.interfaces.services.utility.ILocalUtility" />
+        interface="zope.app.interfaces.services.utility.ILocalUtility" />
 
     <implements
-      interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />
+        interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />
 
     <require
-      permission="zope.ManageServices"
-      interface="zope.app.interfaces.utilities.IMutableSchema"
-      />
+        permission="zope.ManageServices"
+        interface="zope.app.interfaces.utilities.IMutableSchema" />
 
     <require
-      permission="zope.ManageServices"
-      interface="zope.app.interfaces.utilities.ISchemaUtility"
-      set_schema="zope.app.interfaces.utilities.ISchemaUtility"
-      />
+        permission="zope.ManageServices"
+        interface="zope.app.interfaces.utilities.ISchemaUtility"
+        set_schema="zope.app.interfaces.utilities.ISchemaUtility" />
 
   </content>
 
-  
   <content class=".schema.SchemaRegistration">
     <require
       permission="zope.ManageServices"
       interface="zope.app.interfaces.services.utility.IUtilityRegistration
                  zope.app.interfaces.container.IAddNotifiable
                  zope.app.interfaces.container.IDeleteNotifiable"
-      set_schema="zope.app.interfaces.services.utility.IUtilityRegistration"
-      />
+      set_schema="zope.app.interfaces.services.utility.IUtilityRegistration" />
   </content>
 
-  <browser:addform
-      label="New Mutable Schema Registration"
-      for="zope.app.interfaces.utilities.ISchemaUtility"
-      name="addRegistration.html"
-      schema="zope.app.interfaces.services.utility.IUtilityRegistration"
-      class="zope.app.browser.services.utility.AddRegistration"
-      permission="zope.ManageServices"
-      content_factory=".schema.SchemaRegistration"
-      arguments="name interface componentPath"
-      set_after_add="status"
-      fields="name interface componentPath permission status" />
+  <adapter
+      factory=".traversal.SchemaFieldTraversable"
+      provides="zope.app.interfaces.traversing.ITraversable"
+      for="zope.app.interfaces.utilities.IMutableSchema" />
 
 
-  <!-- Menu entry for "add component" menu -->
-  <browser:menuItem
-      for="zope.app.interfaces.container.IAdding"
-      menu="add_component"
-      action="zope.app.utilities.schema.SchemaUtility"
-      title="Persistent Schema Utility"
-      description="A Persistent Schema that can be edited through the web"
-      permission="zope.ManageServices"
-      />
+<!-- Content Component Definition -->
 
-  <!-- Menu entry for "add utility" menu -->
-  <browser:menuItem
-      for="zope.app.interfaces.container.IAdding"
-      menu="add_utility"
-      action="zope.app.utilities.schema.SchemaUtility"
-      title="Persistent Schema Utility"
-      description="A Persistent Schema that can be edited through the web"
+  <content class=".contentcomponent.ContentComponentDefinition">
+
+    <factory
+      id="utility.ContentComponentDefinition"
       permission="zope.ManageServices"
-      />
+      title="Content Component Definition"
+      description="A Persistent Content Component Definition" />
 
+    <implements
+      interface="zope.app.interfaces.services.utility.ILocalUtility" />
 
-  <browser:defaultView
-      for="zope.app.interfaces.utilities.IMutableSchema"
-      name="editschema.html" />
-
-  <browser:page
-      name="editschema.html"
-      menu="zmi_views" title="Edit Schema"
-      for="zope.app.interfaces.utilities.IMutableSchema"
+    <implements
+      interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />
+
+    <require
       permission="zope.ManageServices"
-      class="zope.app.utilities.schema.EditSchema"
-      attribute="edit"
-   />
-
-  <!-- Widgets for the MutableSchemaField -->
-
-  <browser:page
-      class="zope.app.browser.component.interfacewidget.InterfaceWidget"
-      for="zope.app.interfaces.utilities.IMutableSchemaField"
-      name="edit"
-      permission="zope.Public" />
-
-  <browser:page
-      class="zope.app.browser.component.interfacewidget.InterfaceDisplayWidget"
-      for="zope.app.interfaces.utilities.IMutableSchemaField"
-      name="display"
-      permission="zope.Public" />
-
-  <browser:page
-      class="zope.app.browser.component.interfacewidget.MultiInterfaceWidget"
-      for="zope.app.interfaces.utilities.IMutableSchemasField"
-      name="edit"
-      permission="zope.Public" />
-
-  <browser:page
-      class="
-      zope.app.browser.component.interfacewidget.MultiInterfaceDisplayWidget"
-      for="zope.app.interfaces.utilities.IMutableSchemasField"
-      name="display"
-      permission="zope.Public" />
-
-  <browser:editform
-     schema="zope.app.utilities.interfaces.IMutableSchemaContent"
-     name="setschema.html"
-     menu="zmi_views"
-     label="Set Schema"
-     title="Set Schema"
-     permission="zope.ManageContent"
-   />
+      interface=".definition.IContentComponent"
+      set_schema=".definition.IContentComponent" />
 
-  <adapter
-      factory=".traversal.SchemaFieldTraversable"
-      provides="zope.app.interfaces.traversing.ITraversable"
-      for="zope.app.interfaces.utilities.IMutableSchema" />
+  </content>
+
+  
+  <content class=".definition.ContentComponentDefinitionRegistration">
+    <require
+      permission="zope.ManageServices"
+      interface="zope.app.interfaces.services.utility.IUtilityRegistration
+                 zope.app.interfaces.container.IAddNotifiable
+                 zope.app.interfaces.container.IDeleteNotifiable"
+      set_schema="zope.app.interfaces.services.utility.IUtilityRegistration"
+      />
+  </content>
 
-  <!-- Register a browser-specific traverser -->
+<!-- Content Component Instance -->
 
-  <browser:page
-      name="_traverse"
-      for="zope.app.interfaces.utilities.IMutableSchema"
-      class=".traversal.SchemaFieldTraverser"
-      permission="zope.Public" />
+  <content class=".contentcomponent.ContentComponentInstance">
+    <implements
+      interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />
+  </content>
 
-  <include file="definition.zcml" />
-  <include file="instance.zcml" />
 
 </configure>


=== Zope3/src/zope/app/utilities/instance.py 1.1.2.4 => 1.1.2.5 ===
--- Zope3/src/zope/app/utilities/instance.py:1.1.2.4	Thu Aug 14 18:46:38 2003
+++ Zope3/src/zope/app/utilities/instance.py	Fri Aug 15 10:04:57 2003
@@ -107,69 +107,3 @@
 defineChecker(ContentComponentInstance, ContentComponentInstanceChecker)
 
 
-from zope.app import zapi
-from zope.app.browser.form.add import AddView
-from zope.publisher.interfaces import IPublishTraverse
-from zope.app.services.servicenames import Utilities
-from zope.app.utilities.definition import IContentComponent
-from zope.component.exceptions import ComponentLookupError
-
-class AddContentComponentView(AddView):
-
-    implements(IPublishTraverse)
-
-    def __init__(self, context, request):
-        self.context = context
-        self.request = request
-
-    def publishTraverse(self, request, name):
-        """See zope.app.interfaces.container.IAdding"""
-        if '=' in name:
-            type_name, content_name = name.split("=", 1)
-            self.context.contentName = content_name
-
-        utilities = zapi.getService(self.context, Utilities)
-        matching = utilities.getRegisteredMatching(IContentComponent,
-                                                   type_name)
-        if not (matching and matching[0][2].active()):
-            raise ComponentLookupError, \
-                  "No Content Component Definition named '%s' found" %type_name
-
-        self.definition = matching[0][2].active().getComponent()
-        self.schema = self.definition.schema
-        self.label = 'Add %s' %self.definition.name
-        super(AddContentComponentView, self).__init__(self.context, request)
-
-        return self.generated_form
-
-    def createAndAdd(self, data):
-        """Create a Content Component Instance and add it to the container."""
-        content = ContentComponentInstance(self.definition.name,
-                                           self.definition.schema,
-                                           self.definition.permissions)
-        errors = []
-        for name, value in data.items():
-            field = self.schema[name]
-            try:
-                field.set(content, data[name])
-            except ValidationError:
-                errors.append(sys.exc_info()[1])
-
-        content = self.add(content)
-
-        if errors:
-            raise WidgetsError(*errors)
-
-        return content        
-
-
-from zope.app.browser.form.editview import EditView
-
-class EditContentComponentView(EditView):
-
-    def __init__(self, context, request):
-        self.schema = context.getSchema()
-        self.label = 'Edit %s' %context.__name__
-        super(EditContentComponentView, self).__init__(context, request)
-
-


=== Zope3/src/zope/app/utilities/schema.py 1.1.2.15 => 1.1.2.16 ===
--- Zope3/src/zope/app/utilities/schema.py:1.1.2.15	Thu Aug 14 17:50:30 2003
+++ Zope3/src/zope/app/utilities/schema.py	Fri Aug 15 10:04:57 2003
@@ -16,34 +16,22 @@
 $Id$
 """
 from persistence.dict import PersistentDict
-
-from zope.context import ContextMethod
-from zope.interface import implements
-from zope.interface import directlyProvides, directlyProvidedBy
-from zope.proxy import removeAllProxies
-from zope.publisher.browser import BrowserView
-from zope.schema import getFieldsInOrder, getFieldNamesInOrder
-from zope.security.proxy import trustedRemoveSecurityProxy
-from zope.component.exceptions import ComponentLookupError
-
 from zope.app import zapi
 from zope.app.introspector import nameToInterface, interfaceToName
 from zope.app.browser.container.adding import Adding
-from zope.app.browser.form.editview import EditView
-from zope.app.form.utility import \
-     setUpEditWidgets, applyWidgetsChanges, setUpWidget
-from zope.app.security.permission import PermissionField
-from zope.security.checker import CheckerPublic, Checker
-from zope.security.proxy import Proxy, trustedRemoveSecurityProxy
-from zope.app.browser.form.submit import Update
 from zope.app.i18n import ZopeMessageIDFactory as _
-from zope.app.interfaces.utilities import ISchemaAdding
-from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+from zope.app.interfaces.utilities.schema import \
+     ISchemaAdding, IMutableSchema, ISchemaUtility, IMutableSchemaContent
 from zope.app.services.interface import PersistentInterfaceClass
 from zope.app.services.interface import PersistentInterface
 from zope.app.services.utility import UtilityRegistration
-from zope.app.interfaces.utilities import IMutableSchema, ISchemaUtility
-from zope.app.utilities.interfaces import IMutableSchemaContent
+from zope.context import ContextMethod
+from zope.interface import implements
+from zope.interface import directlyProvides, directlyProvidedBy
+from zope.proxy import removeAllProxies
+from zope.schema import getFieldsInOrder, getFieldNamesInOrder
+from zope.component.exceptions import ComponentLookupError
+
 
 class SchemaUtility(PersistentInterfaceClass):
 
@@ -133,57 +121,6 @@
 
     def _delField(self, name):
         del self._InterfaceClass__attrs[name]
-
-
-class EditSchema(BrowserView):
-
-    edit = ViewPageTemplateFile('edit.pt')
-    errors = ()
-    update_status = None
-
-    def name(self):
-        return self.context.getName()
-
-    def fieldNames(self):
-        return getFieldNamesInOrder(self.context)
-
-    def fields(self):
-        return [{'name':name,
-                 'field':zapi.ContextWrapper(field, self.context),
-                 'type':field.__class__.__name__}
-                for name, field in getFieldsInOrder(self.context)]
-
-    def update(self):
-
-        status = ''
-
-        container = zapi.getAdapter(self.context, IMutableSchema)
-
-        if 'DELETE' in self.request:
-            if not 'ids' in self.request:
-                self.errors = ("Must select a field to delete",)
-                status = "An error occured"
-            for id in self.request.get('ids', []):
-                container.removeField(id)
-
-        self.update_status = status
-        return status
-
-
-class EditMutableSchema(EditView):
-
-    def _get_schema(self):
-        return self.context.mutableschema
-
-    schema = property(_get_schema)
-
-    def _setUpWidgets(self):
-        adapted = zapi.getAdapter(self.context, self.schema)
-        if adapted is not self.context:
-            adapted = zapi.ContextWrapper(adapted, self.context,
-                                          name='(adapted)')
-        setUpEditWidgets(self, self.schema, names=self.fieldNames,
-                         content=self.adapted)
 
 
 class SchemaAdding(Adding):

=== Removed File Zope3/src/zope/app/utilities/add.pt ===

=== Removed File Zope3/src/zope/app/utilities/definition.py ===

=== Removed File Zope3/src/zope/app/utilities/definition.zcml ===

=== Removed File Zope3/src/zope/app/utilities/edit.pt ===

=== Removed File Zope3/src/zope/app/utilities/instance.zcml ===

=== Removed File Zope3/src/zope/app/utilities/permission_edit.pt ===




More information about the Zope3-Checkins mailing list