[Zope3-checkins] CVS: Zope3/src/zope/app/schema/browser - __init__.py:1.1 configure.zcml:1.1 schema_add.pt:1.1 schema_edit.pt:1.1 traversal.py:1.1

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Mar 9 19:57:59 EST 2004


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

Added Files:
	__init__.py configure.zcml schema_add.pt schema_edit.pt 
	traversal.py 
Log Message:


Moved mutable schemas out of zope.app.utilities to zope.app.schema. Also,
seperated it from the mutable schema content definition/instance code, which
now lives in zope.app.schemacontent.




=== Added File Zope3/src/zope/app/schema/browser/__init__.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: __init__.py,v 1.1 2004/03/10 00:57:57 srichter Exp $
"""
from zope.app import zapi
from zope.app.browser.form.editview import EditView
from zope.app.form.utility import setUpEditWidgets
from zope.app.i18n import ZopeMessageIDFactory as _
from zope.app.schema.interfaces import IMutableSchema
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.publisher.browser import BrowserView
from zope.schema import getFieldNamesInOrder, getFieldsInOrder

class EditSchema(BrowserView):

    edit = ViewPageTemplateFile('schema_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': field,
                 'type': field.__class__.__name__}
                for name, field in getFieldsInOrder(self.context)]

    def update(self):
        status = ''
        container = IMutableSchema(self.context)
        request = self.request

        if 'DELETE' in request:
            if not 'ids' in request:
                self.errors = (_("Must select a field to delete"),)
                status = _("An error occured.")
            for id in request.get('ids', []):
                del container[id]
        elif 'MOVE_UP' in request or 'MOVE_DOWN' in request:
            up = request.get('MOVE_UP')
            down = request.get('MOVE_DOWN')
            name = up or down
            delta = up and -1 or 1
            names = self.fieldNames()
            if name not in names:
                self.errors = (_("Invalid field name: %s" % name),)
                status = _("An error occured.")
            p = names.index(name) + delta
            try:
                self.context.moveField(name, p)
            except IndexError:
                self.errors = (_("Invalid position: %s" % p),)
                status = _("An error occured.")
        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 = self.schema(self.context)
        if adapted is not self.context:
            adapted.__parent__ = self.context
        setUpEditWidgets(self, self.schema, source=self.adapted,
                         names=self.fieldNames)


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

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

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

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

  </view>

  <addform
      label="New Mutable Schema Registration"
      for="zope.app.schema.interfaces.ISchemaUtility"
      name="addRegistration.html"
      schema="zope.app.interfaces.services.utility.IUtilityRegistration"
      class="zope.app.browser.services.utility.AddRegistration"
      permission="zope.ManageServices"
      content_factory="zope.app.schema.schema.SchemaRegistration"
      arguments="name interface componentPath"
      set_after_add="status"
      fields="name interface componentPath permission status"
      usage="addingdialog" />

  <addMenuItem
      title="Mutable Schema"
      description="A Persistent Schema that can be edited through the web"
      class="zope.app.schema.schema.SchemaUtility"
      permission="zope.ManageServices"
    />


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

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

  <!-- Widgets for the MutableSchemaField -->

  <zope:view
      for="zope.app.schema.interfaces.IMutableSchemaField"
      type="zope.publisher.interfaces.browser.IBrowserRequest"
      provides="zope.app.interfaces.form.IInputWidget"
      factory="zope.app.browser.component.interfacewidget.InterfaceWidget"
      permission="zope.Public"
      />

  <zope:view
      for="zope.app.schema.interfaces.IMutableSchemaField"
      type="zope.publisher.interfaces.browser.IBrowserRequest"
      provides="zope.app.interfaces.form.IDisplayWidget"
      factory="
           zope.app.browser.component.interfacewidget.InterfaceDisplayWidget"
      permission="zope.Public"
      />

  <zope:view
      for="zope.app.schema.interfaces.IMutableSchemasField"
      type="zope.publisher.interfaces.browser.IBrowserRequest"
      provides="zope.app.interfaces.form.IInputWidget"
      factory="zope.app.browser.component.interfacewidget.MultiInterfaceWidget"
      permission="zope.Public"
      />

  <zope:view
      for="zope.app.schema.interfaces.IMutableSchemasField"
      type="zope.publisher.interfaces.browser.IBrowserRequest"
      provides="zope.app.interfaces.form.IDisplayWidget"
      factory="
      zope.app.browser.component.interfacewidget.MultiInterfaceDisplayWidget"
      permission="zope.Public"
      />

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

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


  <zope:adapter
      factory=".traversal.SchemaFieldTraversable"
      provides="zope.app.interfaces.traversing.ITraversable"
      for="zope.app.schema.interfaces.IMutableSchema" />

</zope:configure>


=== Added File Zope3/src/zope/app/schema/browser/schema_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 Utility</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/schema/browser/schema_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/schema/browser/traversal.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.
##############################################################################
"""Specific HTTP

$Id: traversal.py,v 1.1 2004/03/10 00:57:57 srichter Exp $
"""
from zope.interface import implements
from zope.component import getDefaultViewName, queryView
from zope.publisher.interfaces import IPublishTraverse
from zope.app.schema.interfaces import IMutableSchema

from zope.exceptions import NotFoundError

from zope.app.interfaces.traversing import ITraversable
from zope.app.traversing.namespace import UnexpectedParameters
from zope.app.location.interfaces import ILocation

_marker = object()

class SchemaFieldTraverser:

    implements(IPublishTraverse)
    __used_for__ = IMutableSchema

    def __init__(self, context, request):
        self.context = context
        self.request = request

    def publishTraverse(self, request, name):
        subob = self.context.get(name, None)

        # XXX: Check that subobj has self.context as parent!
        # YYY: Why?

        if subob is None:

            view = queryView(self.context, name, request)
            if view is not None:
                if ILocation.providedBy(view):
                    view.__parent__ = self.context
                    view.__name__ = name

                return view

            raise NotFoundError(self.context, name, request)

        return subob

    def browserDefault(self, request):
        c = self.context
        view_name = getDefaultViewName(c, request)
        view_uri = "@@%s" % view_name
        return c, (view_uri,)

class SchemaFieldTraversable:
    """Traverses Schema Fields.
    """

    implements(ITraversable)
    __used_for__ = IMutableSchema

    def __init__(self, context):
        self._context = context

    def traverse(self, name, parameters, original_name, furtherPath):
        if parameters:
            raise UnexpectedParameters(parameters)

        subobj = self._context.get(name, _marker)
        if subobj is _marker:
            raise NotFoundError, original_name

        return subobj




More information about the Zope3-Checkins mailing list