[Zope3-checkins] CVS: Zope3/src/zope/app/browser/utilities - __init__.py:1.1.2.1 add.pt:1.1.2.1 configure.zcml:1.1.2.1 content.py:1.1.2.1 edit.pt:1.1.2.1 permission_edit.pt:1.1.2.1 schema.py:1.1.2.1

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


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

Added Files:
      Tag: dreamcatcher-ttwschema-branch
	__init__.py add.pt configure.zcml content.py edit.pt 
	permission_edit.pt schema.py 
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/browser/utilities/__init__.py ===


=== Added File Zope3/src/zope/app/browser/utilities/add.pt ===
<html metal:use-macro="views/standard_macros/dialog">
<body>
<div metal:fill-slot="body">

  <form action="action.html" method="post">
    <table class="TypeListing" cellpadding="3">

      <caption i18n:translate="">Add Content</caption>

      <tbody tal:define="infos view/addingInfo">

        <tr tal:repeat="info infos">

          <td class="Selector">
            <input type="radio" name="type_name"
                   tal:attributes="value   info/action;
                                   id      info/action;
                                   checked python:len(infos)==1" />
          </td>

          <td class="TypeName">
            <label style="font-weight: bold;"
                   tal:attributes="for info/action">
              <span tal:replace="info/title" >Folder</span>
            </label>
            <div class="TypeDescription" tal:content="info/description">
              Folders are generic containers for content, including other
              folders.
            </div>
          </td>
        </tr>

      <tr>
        <td><br /></td>
        <td>
            <input type="text" name="id"
                   tal:condition="view/namesAccepted"
                   tal:attributes="value request/id | nothing" />
            <input type="submit" value=" Add " 
                   i18n:attributes="value add-button" />
        </td>
      </tr>

      </tbody>

    </table>
  </form>

</div>
</body>
</html>


=== Added File Zope3/src/zope/app/browser/utilities/configure.zcml ===
<configure
  xmlns:zope="http://namespaces.zope.org/zope"
  xmlns="http://namespaces.zope.org/browser">

<!-- Mutable Schema -->

  <menu
      id="add_schema_field"
      title="Menu of Fields to be added to a schema."/>

  <view
      name="+"
      for="zope.app.interfaces.utilities.IMutableSchema"
      class=".schema.SchemaAdding"
      permission="zope.ManageContent"
      allowed_attributes="addingInfo"
      menu="zmi_actions" title="Add">

    <page name="index.html"  template="add.pt" />
    <page name="action.html" attribute="action" />

  </browser:view>

  <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" />


  <!-- Menu entry for "add component" menu -->
  <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"
      />

  <!-- Menu entry for "add utility" menu -->
  <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"
      permission="zope.ManageServices"
      />


  <defaultView
      for="zope.app.interfaces.utilities.IMutableSchema"
      name="editschema.html" />

  <page
      name="editschema.html"
      menu="zmi_views" title="Edit Schema"
      for="zope.app.interfaces.utilities.IMutableSchema"
      permission="zope.ManageServices"
      class="zope.app.utilities.schema.EditSchema"
      attribute="edit"
   />

  <!-- Widgets for the MutableSchemaField -->

  <page
      class="zope.app.browser.component.interfacewidget.InterfaceWidget"
      for="zope.app.interfaces.utilities.IMutableSchemaField"
      name="edit"
      permission="zope.Public" />

  <page
      class="zope.app.browser.component.interfacewidget.InterfaceDisplayWidget"
      for="zope.app.interfaces.utilities.IMutableSchemaField"
      name="display"
      permission="zope.Public" />

  <page
      class="zope.app.browser.component.interfacewidget.MultiInterfaceWidget"
      for="zope.app.interfaces.utilities.IMutableSchemasField"
      name="edit"
      permission="zope.Public" />

  <page
      class="
      zope.app.browser.component.interfacewidget.MultiInterfaceDisplayWidget"
      for="zope.app.interfaces.utilities.IMutableSchemasField"
      name="display"
      permission="zope.Public" />

  <editform
     schema="zope.app.utilities.interfaces.IMutableSchemaContent"
     name="setschema.html"
     label="Set Schema"
     permission="zope.ManageContent"
     menu="zmi_views" title="Set Schema" />

  <!-- Register a browser-specific traverser -->

  <page
      name="_traverse"
      for="zope.app.interfaces.utilities.IMutableSchema"
      class=".traversal.SchemaFieldTraverser"
      permission="zope.Public" />


<!-- Content Component Definition -->

  <addform
      label="Content Component Definition Registration"
      for= "zope.app.interfaces.utilities.content.IContentComponentDefinition"
      name="addRegistration.html"
      schema="zope.app.interfaces.services.utility.IUtilityRegistration"
      class="zope.app.browser.services.utility.AddRegistration"
      permission="zope.ManageServices"
      content_factory="zope.app.utilities.content.ContentComponentRegistration"
      arguments="name interface componentPath"
      set_after_add="status"
      fields="name interface componentPath permission status" />


  <!-- Menu entry for "add component" menu -->
  <menuItem
      for="zope.app.interfaces.container.IAdding"
      menu="add_component"
      action="utility.ContentComponentDefinition"
      title="Content Component Definition"
      description="A Persistent Content Component Definition"
      permission="zope.ManageServices"
      />

  <!-- Menu entry for "add utility" menu -->
  <menuItem
      for="zope.app.interfaces.container.IAdding"
      menu="add_utility"
      action="utility.ContentComponentDefinition"
      title="Content Component Definition"
      description="A Persistent Content Component Definition"
      permission="zope.ManageServices"
      />

  <editform
      for=".definition.IContentComponent"
      schema=".definition.IContentComponent"
      name="edit.html"
      fields="schema"
      menu="zmi_views" title="Edit"
      permission="zope.ManageContent"/>

  <editform
      for="zope.app.interfaces.utilities.content.IContentComponentDefinition"
      schema="zope.app.interfaces.utilities.content.IContentComponentDefinition"
      name="editpermissions.html"
      template="permission_edit.pt"
      class=".content.ContentComponentPermissionEdit"
      menu="zmi_views" title="Define Permissions"
      permission="zope.ManageContent"/>

  <defaultView
      for="zope.app.interfaces.utilities.content.IContentComponentDefinition"
      name="edit.html" />


<!-- Content Component Instance -->

  <page
      name="AddContentComponent"
      for="zope.app.interfaces.container.IAdding"
      permission="zope.ManageContent"
      class=".content.AddContentComponentInstanceView"
      attribute="generated_form" />

  <page
      name="edit.html"
      menu="zmi_views" title="Edit"
      for="zope.app.interfaces.utilities.content.IContentComponentInstance"
      permission="zope.ManageContent"
      class=".content.EditContentComponentView"
      attribute="generated_form" />

  <!-- Directives to test the Content Component Instance -->
  <addform
      label="New Content Component Instance"
      name="AddDirectContentComponent"
      schema="zope.app.interfaces.utilities.content.IContentComponentInstance"
      permission="zope.ManageContent"
      content_factory="zope.app.utilities.content.ContentComponentInstance"
      arguments="__name__ __schema__"
      fields="__name__ __schema__" 
      menu="add_content" title="Schema-based Content"/>

</configure>


=== Added File Zope3/src/zope/app/browser/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 Views

$Id: content.py,v 1.1.2.1 2003/08/15 14:04:41 srichter Exp $
"""
from zope.app import zapi
from zope.app.browser.form.add import AddView
from zope.app.browser.form.editview import EditView
from zope.app.browser.form.submit import Update
from zope.app.form.utility import setUpWidget
from zope.app.security.permission import PermissionField
from zope.app.services.servicenames import Utilities
from zope.app.utilities.definition import IContentComponent
from zope.component.exceptions import ComponentLookupError
from zope.publisher.interfaces import IPublishTraverse


class ContentComponentPermissionEdit(EditView):

    def __init__(self, context, request):
        super(ContentComponentPermissionEdit, self).__init__(context, request)
        self.buildPermissionWidgets()

    def buildPermissionWidgets(self):
        schema = self.context.schema
        for name, field in getFieldsInOrder(schema):
            # Try to get current settings
            if self.context.permissions.has_key(name):
                get_perm, set_perm = self.context.permissions[name]
            else:
                get_perm, set_perm = None, None

            # Create the Accessor Permission Widget for this field
            permField = PermissionField(
                __name__=name+'_get_perm',
                title=u"Accessor Permission",
                default=CheckerPublic,
                required=False)
            setUpWidget(self, name+'_get_perm', permField, value=get_perm)

            # Create the Mutator Permission Widget for this field
            permField = PermissionField(
                __name__=name+'_set_perm',
                title=u"Mutator Permission",
                default=CheckerPublic,
                required=False)
            setUpWidget(self, name+'_set_perm', permField, value=set_perm)

    def update(self):
        status = ''

        if Update in self.request:
            status = super(ContentComponentPermissionEdit, self).update()
            self.buildPermissionWidgets()
        elif 'CHANGE' in self.request:
            schema = self.context.schema
            perms = trustedRemoveSecurityProxy(self.context.permissions)
            for name, field in getFieldsInOrder(schema):
                getPerm = getattr(self, name+'_get_perm_widget').getData()
                setPerm = getattr(self, name+'_set_perm_widget').getData()
                perms[name] = (getPerm, setPerm)
            status = 'Fields permissions mapping updated.'

        return status

    def getPermissionWidgets(self):
        schema = self.context.schema
        info = []
        for name, field in getFieldsInOrder(schema):
            field = trustedRemoveSecurityProxy(field)
            info.append(
                {'fieldName': name,
                 'fieldTitle': field.title,
                 'getter': getattr(self, name+'_get_perm_widget'),
                 'setter': getattr(self, name+'_set_perm_widget')} )
        return info


class AddContentComponentInstanceView(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        


class EditContentComponentInstanceView(EditView):

    def __init__(self, context, request):
        self.schema = context.getSchema()
        self.label = 'Edit %s' %context.__name__
        super(EditContentComponentView, self).__init__(context, request)




=== Added File Zope3/src/zope/app/browser/utilities/edit.pt ===
<html metal:use-macro="views/standard_macros/page">
  <body>
  <div metal:fill-slot="body">

  <div metal:define-macro="body">

    <h3 i18n:translate="">
      Schema Name: 
      <span tal:content="view/name" i18n:name="schema_name"/>
    </h3>

    <form action="." tal:attributes="action request/URL" method="POST"
          enctype="multipart/form-data">

    <p tal:define="status view/update"
       tal:condition="status"
       tal:content="status" />

    <p tal:condition="view/errors" i18n:translate="">
           There are  <strong tal:content="python:len(view.errors)"
                              i18n:name="num_errors">6</strong> input errors.
    </p>

    <tal:block repeat="error view/errors">
       <div class="error" tal:content="error">error</div>
    </tal:block>

    <div metal:define-macro="formbody">

      <table id="sortable" class="listing" summary="Content listing"
             i18n:attributes="summary">

        <thead>
          <tr>
            <th>&nbsp;</th>
            <th i18n:translate="">Name</th>
            <th i18n:translate="">Type</th>
            <th i18n:translate="">Title</th>
            <th i18n:translate="">Required</th>
            <th i18n:translate="">Read-Only</th>
          </tr>
        </thead>

        <tbody>

        <tr tal:repeat="row view/fields">
          <td><input type="checkbox" name="ids:list"
                     value=""
                     tal:attributes="value row/name" /></td>
          <td><a href="#"
                 tal:attributes="href string:${request/URL/-1}/${row/name}/@@edit.html"
                 tal:content="row/name">Name</a></td>
          <td tal:content="row/type">Type</td>
          <tal:block define="field row/field">
          <td tal:content="field/title">Title</td>
          <td tal:content="field/required">Required</td>
          <td tal:content="field/readonly">Read-Only</td>
          </tal:block>
        </tr>

        </tbody>
      </table>

      </div>

      <div class="row">
        <div class="controls">
          <input type="submit" name="DELETE" value="Delete"
              i18n:attributes="value delete-field-button" />
        </div>
      </div>

  </form>

  </div>

  </div>
  </body>

</html>


=== Added File Zope3/src/zope/app/browser/utilities/permission_edit.pt ===
<html metal:use-macro="views/standard_macros/page">
<body>
<div metal:fill-slot="body">

  <p tal:define="status view/update"
     tal:condition="status"
     tal:content="status" />

  <form action="./@@edit.html"
        tal:attributes="action request/URL" method="POST">

    <tal:block define="widgets view/getPermissionWidgets"
               condition="widgets">
      <h4 i18n:translate="">Map permissions to Schema fields</h4>

      <tal:block repeat="widget widgets">
        <h5 tal:content="string:${widget/fieldTitle} (${widget/fieldName})">
          FieldName (Field Title)
        </h5>
        <div class="row" tal:replace="structure widget/getter/row">
          <div class="label" i18n:translate="">Get Permission</div>
          <div class="field">

          </div>
        </div>
        <div class="row" tal:replace="structure widget/setter/row">
          <div class="label" i18n:translate="">Set Permission</div>
          <div class="field">

          </div>
        </div>
        <br />
      </tal:block>
      <div class="row">
        <div class="controls" style="width: 100%">
          <input type="submit" value="Refresh"
                 i18n:attributes="value refresh-button" />
          <input type="submit" value="Change" name="CHANGE"
                 i18n:attributes="value change-button" />
         </div>
      </div>
    </tal:block>

  </form>

</div>
</body>
</html>

=== Added File Zope3/src/zope/app/browser/utilities/schema.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.
#
##############################################################################
"""Mutable Schema (as Utility) Views

$Id: schema.py,v 1.1.2.1 2003/08/15 14:04:41 srichter Exp $
"""
from zope.app.browser.form.editview import EditView
from zope.app.form.utility import setUpEditWidgets
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.app.security.permission import PermissionField
from zope.app.utilities.schema import SchemaAdding
from zope.publisher.browser import BrowserView
from zope.app.i18n import ZopeMessageIDFactory as _

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)




More information about the Zope3-Checkins mailing list