Log message for revision 107345: Backported c107134 from trunk Changed: U Zope/branches/2.12/buildout.cfg U Zope/branches/2.12/doc/CHANGES.rst U Zope/branches/2.12/setup.py U Zope/branches/2.12/src/Products/Five/TODO.txt U Zope/branches/2.12/src/Products/Five/browser/tests/pages.txt U Zope/branches/2.12/src/Products/Five/browser/tests/pages.zcml U Zope/branches/2.12/src/Products/Five/browser/tests/pages_ftest.txt D Zope/branches/2.12/src/Products/Five/doc/formlib.txt U Zope/branches/2.12/src/Products/Five/form/__init__.py D Zope/branches/2.12/src/Products/Five/form/add.pt U Zope/branches/2.12/src/Products/Five/form/configure.zcml D Zope/branches/2.12/src/Products/Five/form/edit.pt U Zope/branches/2.12/src/Products/Five/form/macros.py U Zope/branches/2.12/src/Products/Five/form/meta.zcml U Zope/branches/2.12/src/Products/Five/form/metaconfigure.py D Zope/branches/2.12/src/Products/Five/form/objectwidget.pt U Zope/branches/2.12/src/Products/Five/form/objectwidget.py D Zope/branches/2.12/src/Products/Five/form/tests/ U Zope/branches/2.12/src/Products/Five/formlib/__init__.py U Zope/branches/2.12/src/Products/Five/formlib/configure.zcml U Zope/branches/2.12/src/Products/Five/formlib/formbase.py D Zope/branches/2.12/src/Products/Five/formlib/tests/ U Zope/branches/2.12/versions.cfg
-=- Modified: Zope/branches/2.12/buildout.cfg =================================================================== --- Zope/branches/2.12/buildout.cfg 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/buildout.cfg 2009-12-30 02:16:45 UTC (rev 107345) @@ -43,6 +43,7 @@ ExtensionClass Persistence RestrictedPython + five.formlib tempstorage zLOG zope.annotation @@ -66,7 +67,6 @@ zope.event zope.exceptions zope.filerepresentation - zope.formlib zope.hookable zope.i18n zope.i18nmessageid Modified: Zope/branches/2.12/doc/CHANGES.rst =================================================================== --- Zope/branches/2.12/doc/CHANGES.rst 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/doc/CHANGES.rst 2009-12-30 02:16:45 UTC (rev 107345) @@ -13,6 +13,12 @@ - Fixed a SyntaxError in utilities/load_site.py script. +Features Added +++++++++++++++ + +- Moved zope.formlib / zope.app.form integration into a separate package + called five.formlib. + Zope 2.12.2 (2009-12-22) ------------------------ Modified: Zope/branches/2.12/setup.py =================================================================== --- Zope/branches/2.12/setup.py 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/setup.py 2009-12-30 02:16:45 UTC (rev 107345) @@ -94,6 +94,7 @@ 'ZConfig', 'ZODB3', 'docutils', + 'five.formlib', 'pytz', 'setuptools', 'tempstorage', @@ -108,7 +109,6 @@ 'zope.deferredimport', 'zope.event', 'zope.exceptions', - 'zope.formlib', 'zope.i18n [zcml]', 'zope.i18nmessageid', 'zope.interface', @@ -131,7 +131,6 @@ 'zope.testing', 'zope.traversing', 'zope.viewlet', - 'zope.app.form', 'zope.app.publication', 'zope.app.publisher', 'zope.app.schema', Modified: Zope/branches/2.12/src/Products/Five/TODO.txt =================================================================== --- Zope/branches/2.12/src/Products/Five/TODO.txt 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/src/Products/Five/TODO.txt 2009-12-30 02:16:45 UTC (rev 107345) @@ -32,8 +32,6 @@ v1.4 ---- -- namedtemplate in Five.formlib? - - l10n (philikon) - Figure out where add-view redirects should go. Modified: Zope/branches/2.12/src/Products/Five/browser/tests/pages.txt =================================================================== --- Zope/branches/2.12/src/Products/Five/browser/tests/pages.txt 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/src/Products/Five/browser/tests/pages.txt 2009-12-30 02:16:45 UTC (rev 107345) @@ -258,7 +258,7 @@ >>> protected_view_names = [ ... 'eagle.txt', 'falcon.html', 'owl.html', 'flamingo.html', - ... 'condor.html', 'protectededitform.html'] + ... 'condor.html'] >>> >>> public_view_names = [ ... 'public_attribute_page', Modified: Zope/branches/2.12/src/Products/Five/browser/tests/pages.zcml =================================================================== --- Zope/branches/2.12/src/Products/Five/browser/tests/pages.zcml 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/src/Products/Five/browser/tests/pages.zcml 2009-12-30 02:16:45 UTC (rev 107345) @@ -232,16 +232,7 @@ class=".pages.SimpleView" permission="zope2.Public" /> - - <!-- XXX this should really be in Five.form.tests --> - <!-- protected edit form for permission check --> - <browser:editform - schema="Products.Five.tests.testing.simplecontent.ISimpleContent" - name="protectededitform.html" - permission="zope2.ViewManagementScreens" - /> - <!-- stuff that we'll override in overrides.zcml --> <browser:page for="Products.Five.tests.testing.simplecontent.ISimpleContent" Modified: Zope/branches/2.12/src/Products/Five/browser/tests/pages_ftest.txt =================================================================== --- Zope/branches/2.12/src/Products/Five/browser/tests/pages_ftest.txt 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/src/Products/Five/browser/tests/pages_ftest.txt 2009-12-30 02:16:45 UTC (rev 107345) @@ -60,7 +60,7 @@ >>> protected_view_names = [ ... 'eagle.txt', 'falcon.html', 'owl.html', 'flamingo.html', - ... 'condor.html', 'protectededitform.html'] + ... 'condor.html'] >>> >>> public_view_names = [ ... 'public_attribute_page', Deleted: Zope/branches/2.12/src/Products/Five/doc/formlib.txt =================================================================== --- Zope/branches/2.12/src/Products/Five/doc/formlib.txt 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/src/Products/Five/doc/formlib.txt 2009-12-30 02:16:45 UTC (rev 107345) @@ -1,18 +0,0 @@ -============================ -zope.formlib support in Five -============================ - -Five supports zope.formlib, an alternative for constructing add, edit, and -other forms based on schema. See zope/formlib/form.txt for a thorough -description of the functionality provided by formlib. - -Formlib forms are normal view classes, registered as browser pages. Where -in a pure Zope-3 context you would derive from one of the zope.formlib.form -baseclasses, you now need to derive from one of the baseclasses provided by -Products.Five.formlib.formbase. - -In almost all cases you need to import from zope.formlib.from as well - -e.g. Fields and Actions in order to define and select fields and to add -actions to your form. - -See Products.Five.formlib.tests for a minimal example. Modified: Zope/branches/2.12/src/Products/Five/form/__init__.py =================================================================== --- Zope/branches/2.12/src/Products/Five/form/__init__.py 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/src/Products/Five/form/__init__.py 2009-12-30 02:16:45 UTC (rev 107345) @@ -1,231 +1,3 @@ -############################################################################## -# -# Copyright (c) 2004, 2005 Zope Corporation and Contributors. -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (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. -# -############################################################################## -"""Add and edit views - -$Id$ -""" -import sys -from datetime import datetime - -import transaction -from zope.event import notify -from zope.lifecycleevent import ObjectCreatedEvent, ObjectModifiedEvent -from zope.lifecycleevent import Attributes -from zope.location.interfaces import ILocation -from zope.location import LocationProxy -from zope.schema.interfaces import ValidationError -from zope.i18nmessageid import MessageFactory -_ = MessageFactory('zope') - -from zope.app.form.browser.submit import Update -from zope.app.form.interfaces import IInputWidget -from zope.app.form.interfaces import WidgetsError -from zope.app.form.utility import setUpEditWidgets, applyWidgetsChanges -from zope.app.form.utility import setUpWidgets, getWidgetsData - -from Products.Five.browser import BrowserView -from Products.Five.browser.decode import processInputs, setPageEncoding -from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile - -class EditView(BrowserView): - """Simple edit-view base class - - Subclasses should provide a schema attribute defining the schema - to be edited. - """ - - errors = () - update_status = None - label = '' - charsets = None - - # Fall-back field names computes from schema - fieldNames = property(lambda self: getFieldNamesInOrder(self.schema)) - # Fall-back template - generated_form = ZopeTwoPageTemplateFile('edit.pt') - - def __init__(self, context, request): - BrowserView.__init__(self, context, request) - processInputs(self.request, self.charsets) - setPageEncoding(self.request) - self._setUpWidgets() - - def _setUpWidgets(self): - adapted = self.schema(self.context) - if adapted is not self.context: - if not ILocation.providedBy(adapted): - adapted = LocationProxy(adapted) - adapted.__parent__ = self.context - self.adapted = adapted - setUpEditWidgets(self, self.schema, source=self.adapted, - names=self.fieldNames) - - def setPrefix(self, prefix): - for widget in self.widgets(): - widget.setPrefix(prefix) - - def widgets(self): - return [getattr(self, name+'_widget') - for name in self.fieldNames] - - def changed(self): - # This method is overridden to execute logic *after* changes - # have been made. - pass - - def update(self): - if self.update_status is not None: - # We've been called before. Just return the status we previously - # computed. - return self.update_status - - status = '' - - content = self.adapted - - if Update in self.request.form.keys(): - changed = False - try: - changed = applyWidgetsChanges(self, self.schema, - target=content, names=self.fieldNames) - # We should not generate events when an adapter is used. - # That's the adapter's job. We need to unwrap the objects to - # compare them, as they are wrapped differently. - # Additionally, we can't use Acquisition.aq_base() because - # it strangely returns different objects for these two even - # when they are identical. In particular - # aq_base(self.adapted) != self.adapted.aq_base :-( - if changed and getattr(self.context, 'aq_base', self.context)\ - is getattr(self.adapted, 'aq_base', self.adapted): - description = Attributes(self.schema, *self.fieldNames) - notify(ObjectModifiedEvent(content, description)) - except WidgetsError, errors: - self.errors = errors - status = _("An error occurred.") - transaction.abort() - else: - setUpEditWidgets(self, self.schema, source=self.adapted, - ignoreStickyValues=True, - names=self.fieldNames) - if changed: - self.changed() - formatter = self.request.locale.dates.getFormatter( - 'dateTime', 'medium') - status = _("Updated on ${date_time}", - mapping={'date_time': - formatter.format(datetime.utcnow())}) - - self.update_status = status - return status - -class AddView(EditView): - """Simple edit-view base class. - - Subclasses should provide a schema attribute defining the schema - to be edited. - """ - - def _setUpWidgets(self): - setUpWidgets(self, self.schema, IInputWidget, names=self.fieldNames) - - def update(self): - if self.update_status is not None: - # We've been called before. Just return the previous result. - return self.update_status - - if self.request.form.has_key(Update): - - self.update_status = '' - try: - data = getWidgetsData(self, self.schema, names=self.fieldNames) - self.createAndAdd(data) - except WidgetsError, errors: - self.errors = errors - self.update_status = _("An error occurred.") - return self.update_status - - self.request.response.redirect(self.nextURL()) - - return self.update_status - - def create(self, *args, **kw): - """Do the actual instantiation.""" - # hack to please typical Zope 2 factories, which expect id and title - # Any sane schema will use a unicode title, and may fail on a - # non-unicode one. - args = ('tmp_id', u'Temporary title') + args - return self._factory(*args, **kw) - - def createAndAdd(self, data): - """Add the desired object using the data in the data argument. - - The data argument is a dictionary with the data entered in the form. - """ - - args = [] - if self._arguments: - for name in self._arguments: - args.append(data[name]) - - kw = {} - if self._keyword_arguments: - for name in self._keyword_arguments: - if name in data: - kw[str(name)] = data[name] - - content = self.create(*args, **kw) - adapted = self.schema(content) - - errors = [] - - if self._set_before_add: - for name in self._set_before_add: - if name in data: - field = self.schema[name] - try: - field.set(adapted, data[name]) - except ValidationError: - errors.append(sys.exc_info()[1]) - - if errors: - raise WidgetsError(*errors) - - notify(ObjectCreatedEvent(content)) - - content = self.add(content) - adapted = self.schema(content) - - if self._set_after_add: - for name in self._set_after_add: - if name in data: - field = self.schema[name] - try: - field.set(adapted, data[name]) - except ValidationError: - errors.append(sys.exc_info()[1]) - # We have modified the object, so we need to publish an - # object-modified event: - description = Attributes(self.schema, *self._set_after_add) - notify(ObjectModifiedEvent(content, description)) - - if errors: - raise WidgetsError(*errors) - - return content - - def add(self, content): - return self.context.add(content) - - def nextURL(self): - return self.context.nextURL() +# BBB +from five.formlib import AddView +from five.formlib import EditView Deleted: Zope/branches/2.12/src/Products/Five/form/add.pt =================================================================== --- Zope/branches/2.12/src/Products/Five/form/add.pt 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/src/Products/Five/form/add.pt 2009-12-30 02:16:45 UTC (rev 107345) @@ -1,74 +0,0 @@ -<html metal:use-macro="context/@@standard_macros/page" - i18n:domain="zope"> - <body> - <div metal:fill-slot="body"> - - <div metal:define-macro="addform"> - - <form action="." tal:attributes="action request/URL" method="post" - enctype="multipart/form-data"> - - <div metal:define-macro="formbody"> - - <h3 tal:condition="view/label" - tal:content="view/label" - metal:define-slot="heading" - >Add something</h3> - - <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> - - <div metal:define-slot="extra_info" tal:replace="nothing"> - </div> - - <div class="row" metal:define-slot="extra_top" tal:replace="nothing"> - <div class="label">Extra top</div> - <div class="label"><input type="text" style="width:100%" /></div> - </div> - - <div metal:use-macro="context/@@form_macros/widget_rows" /> - - <div class="separator"></div> - - <div class="row" - metal:define-slot="extra_bottom" tal:replace="nothing"> - <div class="label">Extra bottom</div> - <div class="field"><input type="text" style="width:100%" /></div> - </div> - - <div class="separator"></div> - - </div> - <br/><br/> - <div class="row"> - <div class="controls"><hr /> - <input type='submit' value='Refresh' - i18n:attributes='value refresh-button' /> - <input type='submit' value='Add' name='UPDATE_SUBMIT' - i18n:attributes='value add-button' /> - <span tal:condition="context/nameAllowed|nothing" tal:omit-tag=""> - <b i18n:translate="">Object Name</b> - <input type='text' name='add_input_name' - tal:attributes="value context/contentName" /> - </span> - </div> - </div> - - <div class="row" metal:define-slot="extra_buttons" tal:replace="nothing"> - </div> - - <div class="separator"></div> - </form> - </div> - - </div> - </body> - -</html> - Modified: Zope/branches/2.12/src/Products/Five/form/configure.zcml =================================================================== --- Zope/branches/2.12/src/Products/Five/form/configure.zcml 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/src/Products/Five/form/configure.zcml 2009-12-30 02:16:45 UTC (rev 107345) @@ -1,14 +1,5 @@ -<configure xmlns="http://namespaces.zope.org/zope" - xmlns:browser="http://namespaces.zope.org/browser"> +<configure xmlns="http://namespaces.zope.org/zope"> - <include package="zope.app.form.browser" /> + <include package="five.formlib" /> - <browser:page - for="*" - name="form_macros" - permission="zope2.View" - class=".macros.FormMacros" - allowed_interface="zope.interface.common.mapping.IItemMapping" - /> - </configure> \ No newline at end of file Deleted: Zope/branches/2.12/src/Products/Five/form/edit.pt =================================================================== --- Zope/branches/2.12/src/Products/Five/form/edit.pt 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/src/Products/Five/form/edit.pt 2009-12-30 02:16:45 UTC (rev 107345) @@ -1,69 +0,0 @@ -<tal:tag condition="view/update"/> -<html metal:use-macro="context/@@standard_macros/view" - i18n:domain="zope"> - <body> - <div metal:fill-slot="body"> - - <div metal:define-macro="body"> - - <form action="." tal:attributes="action request/URL" method="POST" - enctype="multipart/form-data"> - - <div metal:define-macro="formbody"> - - <h3 tal:condition="view/label" - tal:content="view/label" - metal:define-slot="heading" - >Edit something</h3> - - <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> - - <div metal:define-slot="extra_info" tal:replace="nothing"> - </div> - - <div class="row" - metal:define-slot="extra_top" tal:replace="nothing"> - <div class="label">Extra top</div> - <div class="field"><input type="text" style="width:100%" /></div> - </div> - - <div metal:use-macro="context/@@form_macros/widget_rows" /> - - <div class="separator"></div> - - <div class="row" - metal:define-slot="extra_bottom" tal:replace="nothing"> - <div class="label">Extra bottom</div> - <div class="field"><input type="text" style="width:100%" /></div> - </div> - <div class="separator"></div> - </div> - - <div class="row"> - <div class="controls"> - <input type="submit" value="Refresh" - i18n:attributes="value refresh-button" /> - <input type="submit" name="UPDATE_SUBMIT" value="Change" - i18n:attributes="value submit-button"/> - </div> - </div> - <div class="row" metal:define-slot="extra_buttons" tal:replace="nothing"> - </div> - - <div class="separator"></div> - - </form> - - </div> - - </div> - </body> - -</html> Modified: Zope/branches/2.12/src/Products/Five/form/macros.py =================================================================== --- Zope/branches/2.12/src/Products/Five/form/macros.py 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/src/Products/Five/form/macros.py 2009-12-30 02:16:45 UTC (rev 107345) @@ -1,22 +1,2 @@ -############################################################################## -# -# Copyright (c) 2004, 2005 Zope Corporation and Contributors. -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (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. -# -############################################################################## -"""Form macros - -$Id$ -""" -from Products.Five.skin.standardmacros import StandardMacros - -# copy of zope.app.form.browser.macros.FormMacros -class FormMacros(StandardMacros): - macro_pages = ('widget_macros', 'addform_macros') +# BBB +from five.formlib.macros import FormMacros Modified: Zope/branches/2.12/src/Products/Five/form/meta.zcml =================================================================== --- Zope/branches/2.12/src/Products/Five/form/meta.zcml 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/src/Products/Five/form/meta.zcml 2009-12-30 02:16:45 UTC (rev 107345) @@ -1,35 +1,5 @@ -<configure - xmlns="http://namespaces.zope.org/zope" - xmlns:meta="http://namespaces.zope.org/meta"> +<configure xmlns="http://namespaces.zope.org/zope"> - <meta:directives namespace="http://namespaces.zope.org/browser"> + <include package="five.formlib" file="meta.zcml" /> - <meta:complexDirective - name="editform" - schema="zope.app.form.browser.metadirectives.IEditFormDirective" - handler=".metaconfigure.EditFormDirective" - > - - <meta:subdirective - name="widget" - schema="zope.app.form.browser.metadirectives.IWidgetSubdirective" - /> - - </meta:complexDirective> - - <meta:complexDirective - name="addform" - schema="zope.app.form.browser.metadirectives.IAddFormDirective" - handler=".metaconfigure.AddFormDirective" - > - - <meta:subdirective - name="widget" - schema="zope.app.form.browser.metadirectives.IWidgetSubdirective" - /> - - </meta:complexDirective> - - </meta:directives> - </configure> Modified: Zope/branches/2.12/src/Products/Five/form/metaconfigure.py =================================================================== --- Zope/branches/2.12/src/Products/Five/form/metaconfigure.py 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/src/Products/Five/form/metaconfigure.py 2009-12-30 02:16:45 UTC (rev 107345) @@ -1,218 +1,6 @@ -############################################################################## -# -# Copyright (c) 2004, 2005 Zope Corporation and Contributors. -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (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. -# -############################################################################## -"""Edit form directives - -$Id$ -""" -from App.class_init import InitializeClass -from ExtensionClass import Base - -import zope.component -from zope.interface import Interface -from zope.i18nmessageid import MessageFactory -_ = MessageFactory('zope') - -from zope.app.publisher.browser.menumeta import menuItemDirective -from zope.app.form.browser.metaconfigure import BaseFormDirective -from zope.browser.interfaces import IAdding - -from Products.Five.form import EditView, AddView -from Products.Five.metaclass import makeClass -from Products.Five.security import protectClass -from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile -from Products.Five.browser.metaconfigure import makeClassForTemplate - -def EditViewFactory(name, schema, label, permission, layer, - template, default_template, bases, for_, fields, - fulledit_path=None, fulledit_label=None, menu=u''): - class_ = makeClassForTemplate(template, globals(), used_for=schema, - bases=bases) - class_.schema = schema - class_.label = label - class_.fieldNames = fields - - class_.fulledit_path = fulledit_path - if fulledit_path and (fulledit_label is None): - fulledit_label = "Full edit" - - class_.fulledit_label = fulledit_label - - class_.generated_form = ZopeTwoPageTemplateFile(default_template) - - if layer is None: - layer = IDefaultBrowserLayer - - s = zope.component.getGlobalSiteManager() - s.registerAdapter(class_, (for_, layer), Interface, name) - - # Reminder: the permission we got has already been processed by - # BaseFormDirective, that means that zope.Public has been - # translated to the CheckerPublic object - protectClass(class_, permission) - InitializeClass(class_) - -class FiveFormDirective(BaseFormDirective): - - def _processWidgets(self): - if self._widgets: - customWidgetsObject = makeClass( - 'CustomWidgetsMixin', (Base,), self._widgets) - self.bases = self.bases + (customWidgetsObject,) - -class EditFormDirective(FiveFormDirective): - - view = EditView - default_template = 'edit.pt' - title = _('Edit') - - def _handle_menu(self): - if self.menu: - menuItemDirective( - self._context, self.menu, self.for_ or self.schema, - '@@' + self.name, self.title, permission=self.permission, - layer=self.layer) - - def __call__(self): - self._processWidgets() - self._handle_menu() - self._context.action( - discriminator=self._discriminator(), - callable=EditViewFactory, - args=self._args(), - kw={'menu': self.menu}, - ) - - -def AddViewFactory(name, schema, label, permission, layer, - template, default_template, bases, for_, - fields, content_factory, arguments, - keyword_arguments, set_before_add, set_after_add, - menu=u''): - class_ = makeClassForTemplate(template, globals(), used_for=schema, - bases=bases) - - class_.schema = schema - class_.label = label - class_.fieldNames = fields - class_._factory = content_factory - class_._arguments = arguments - class_._keyword_arguments = keyword_arguments - class_._set_before_add = set_before_add - class_._set_after_add = set_after_add - - class_.generated_form = ZopeTwoPageTemplateFile(default_template) - - if layer is None: - layer = IDefaultBrowserLayer - - s = zope.component.getGlobalSiteManager() - s.registerAdapter(class_, (for_, layer), Interface, name) - - # Reminder: the permission we got has already been processed by - # BaseFormDirective, that means that zope.Public has been - # translated to the CheckerPublic object - protectClass(class_, permission) - InitializeClass(class_) - -class AddFormDirective(FiveFormDirective): - - view = AddView - default_template = 'add.pt' - for_ = IAdding - - # default add form information - description = None - content_factory = None - arguments = None - keyword_arguments = None - set_before_add = None - set_after_add = None - - def _handle_menu(self): - if self.menu or self.title: - if (not self.menu) or (not self.title): - raise ValueError("If either menu or title are specified, " - "they must both be specified") - # Add forms are really for IAdding components, so do not use - # for=self.schema. - menuItemDirective( - self._context, self.menu, self.for_, '@@' + self.name, - self.title, permission=self.permission, layer=self.layer, - description=self.description) - - def _handle_arguments(self, leftover=None): - schema = self.schema - fields = self.fields - arguments = self.arguments - keyword_arguments = self.keyword_arguments - set_before_add = self.set_before_add - set_after_add = self.set_after_add - - if leftover is None: - leftover = fields - - if arguments: - missing = [n for n in arguments if n not in fields] - if missing: - raise ValueError("Some arguments are not included in the form", - missing) - optional = [n for n in arguments if not schema[n].required] - if optional: - raise ValueError("Some arguments are optional, use" - " keyword_arguments for them", - optional) - leftover = [n for n in leftover if n not in arguments] - - if keyword_arguments: - missing = [n for n in keyword_arguments if n not in fields] - if missing: - raise ValueError( - "Some keyword_arguments are not included in the form", - missing) - leftover = [n for n in leftover if n not in keyword_arguments] - - if set_before_add: - missing = [n for n in set_before_add if n not in fields] - if missing: - raise ValueError( - "Some set_before_add are not included in the form", - missing) - leftover = [n for n in leftover if n not in set_before_add] - - if set_after_add: - missing = [n for n in set_after_add if n not in fields] - if missing: - raise ValueError( - "Some set_after_add are not included in the form", - missing) - leftover = [n for n in leftover if n not in set_after_add] - - self.set_after_add += leftover - - else: - self.set_after_add = leftover - - def __call__(self): - self._processWidgets() - self._handle_menu() - self._handle_arguments() - - self._context.action( - discriminator=self._discriminator(), - callable=AddViewFactory, - args=self._args()+(self.content_factory, self.arguments, - self.keyword_arguments, - self.set_before_add, self.set_after_add), - kw={'menu': self.menu}, - ) +# BBB +from five.formlib.metaconfigure import EditViewFactory +from five.formlib.metaconfigure import FiveFormDirective +from five.formlib.metaconfigure import EditFormDirective +from five.formlib.metaconfigure import AddViewFactory +from five.formlib.metaconfigure import AddFormDirective Deleted: Zope/branches/2.12/src/Products/Five/form/objectwidget.pt =================================================================== --- Zope/branches/2.12/src/Products/Five/form/objectwidget.pt 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/src/Products/Five/form/objectwidget.pt 2009-12-30 02:16:45 UTC (rev 107345) @@ -1,15 +0,0 @@ -<fieldset> - <legend tal:content="context/legendTitle" - i18n:translate="">The Legend</legend> - <div class="row" tal:repeat="widget context/subwidgets"> - <tal:comment condition="nothing"> - This is why we have to duplicate this template: we want to look - up the @@form_macros browser page from something that's - definitely five:traversable (it doesn't really matter where we - look it up, just *that* we look it up); we know the object we're - editing is five:traversable, so we just use that. Yes, three - times context. Weird, eh? - </tal:comment> - <metal:block use-macro="context/context/context/@@form_macros/widget_row" /> - </div> -</fieldset> Modified: Zope/branches/2.12/src/Products/Five/form/objectwidget.py =================================================================== --- Zope/branches/2.12/src/Products/Five/form/objectwidget.py 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/src/Products/Five/form/objectwidget.py 2009-12-30 02:16:45 UTC (rev 107345) @@ -1,53 +1,4 @@ -############################################################################## -# -# Copyright (c) 2005 Zope Corporation and Contributors. -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (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. -# -############################################################################## -"""Five-compatible version of ObjectWidget - -This is needed because ObjectWidget uses ViewPageTemplateFile whose -macro definition is unfortunately incompatible with ZopeTwoPageTemplateFile. -So this subclass uses ZopeTwoPageTemplateFile for the template that renders -the widget's sub-editform. - -$Id$ -""" -from AccessControl.SecurityInfo import ClassSecurityInfo -from App.class_init import InitializeClass -from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile -from zope.app.form.browser.objectwidget import ObjectWidget as OWBase -from zope.app.form.browser.objectwidget import ObjectWidgetView as OWVBase - -class ObjectWidgetView(OWVBase): - security = ClassSecurityInfo() - security.declareObjectPublic() - - template = ViewPageTemplateFile('objectwidget.pt') - -InitializeClass(ObjectWidgetView) - -class ObjectWidgetClass(OWBase): - - def setRenderedValue(self, value): - """Slightly more robust re-implementation this method.""" - # re-call setupwidgets with the content - self._setUpEditWidgets() - for name in self.names: - val = getattr(value, name, None) - if val is None: - # this is where we are more robust than Zope 3.2's - # object widget: we supply subwidgets with the default - # from the schema, not None (Zope 3.2's list widget - # breaks when the rendered value is None) - val = self.context.schema[name].default - self.getSubWidget(name).setRenderedValue(val) - -ObjectWidget = ObjectWidgetClass +# BBB +from five.formlib.objectwidget import ObjectWidgetView +from five.formlib.objectwidget import ObjectWidget +from five.formlib.objectwidget import ObjectWidgetClass Modified: Zope/branches/2.12/src/Products/Five/formlib/__init__.py =================================================================== --- Zope/branches/2.12/src/Products/Five/formlib/__init__.py 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/src/Products/Five/formlib/__init__.py 2009-12-30 02:16:45 UTC (rev 107345) @@ -1 +1 @@ -# package \ No newline at end of file +# BBB \ No newline at end of file Modified: Zope/branches/2.12/src/Products/Five/formlib/configure.zcml =================================================================== --- Zope/branches/2.12/src/Products/Five/formlib/configure.zcml 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/src/Products/Five/formlib/configure.zcml 2009-12-30 02:16:45 UTC (rev 107345) @@ -1,19 +1,5 @@ -<configure - package="zope.formlib" - xmlns="http://namespaces.zope.org/zope" - i18n_domain="zope"> +<configure xmlns="http://namespaces.zope.org/zope"> - <adapter - factory=".form.render_submit_button" - name="render" - /> + <include package="five.formlib" /> - <!-- Error view for 'Invalid' --> - <adapter - for="zope.interface.Invalid - zope.publisher.interfaces.browser.IBrowserRequest" - factory=".errors.InvalidErrorView" - permission="zope.Public" - /> - </configure> Modified: Zope/branches/2.12/src/Products/Five/formlib/formbase.py =================================================================== --- Zope/branches/2.12/src/Products/Five/formlib/formbase.py 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/src/Products/Five/formlib/formbase.py 2009-12-30 02:16:45 UTC (rev 107345) @@ -1,117 +1,17 @@ -############################################################################## -# -# Copyright (c) 2006 Zope Corporation and Contributors. -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (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. -# -############################################################################## -"""Five baseclasses for zope.formlib.form - -$Id$ -""" -import os.path - -import zope.event -import zope.formlib -import zope.lifecycleevent -from zope import interface -from zope.formlib import interfaces, form -from zope.i18nmessageid import MessageFactory -_ = MessageFactory("zope") - -from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile -from Products.Five.browser.decode import processInputs, setPageEncoding - -_FORMLIB_DIR = os.path.dirname(zope.formlib.__file__) -_PAGEFORM_PATH = os.path.join(_FORMLIB_DIR, 'pageform.pt') -_SUBPAGEFORM_PATH = os.path.join(_FORMLIB_DIR, 'subpageform.pt') - - -class FiveFormlibMixin(object): - - # Overrides the formlib.form.FormBase.template attributes implemented - # using NamedTemplates. NamedTemplates using ViewPageTemplateFile (like - # formlib does by default) cannot work in Zope2. - - # XXX Maybe we need to have Five-compatible NamedTemplates? - - template = ViewPageTemplateFile(_PAGEFORM_PATH) - - # Overrides formlib.form.FormBase.update. Make sure user input is - # decoded first and the page encoding is set before proceeding. - - def update(self): - processInputs(self.request) - setPageEncoding(self.request) - super(FiveFormlibMixin, self).update() - - -class FormBase(FiveFormlibMixin, form.FormBase): - pass - - -class EditFormBase(FiveFormlibMixin, form.EditFormBase): - pass - - -class DisplayFormBase(FiveFormlibMixin, form.DisplayFormBase): - pass - - -class AddFormBase(FiveFormlibMixin, form.AddFormBase): - pass - - -class PageForm(FormBase): - - interface.implements(interfaces.IPageForm) - -Form = PageForm - - -class PageEditForm(EditFormBase): - - interface.implements(interfaces.IPageForm) - -EditForm = PageEditForm - - -class PageDisplayForm(DisplayFormBase): - - interface.implements(interfaces.IPageForm) - -DisplayForm = PageDisplayForm - - -class PageAddForm(AddFormBase): - - interface.implements(interfaces.IPageForm) - -AddForm = PageAddForm - - -class SubPageForm(FormBase): - - template = ViewPageTemplateFile(_SUBPAGEFORM_PATH) - - interface.implements(interfaces.ISubPageForm) - - -class SubPageEditForm(EditFormBase): - - template = ViewPageTemplateFile(_SUBPAGEFORM_PATH) - - interface.implements(interfaces.ISubPageForm) - - -class SubPageDisplayForm(DisplayFormBase): - - template = ViewPageTemplateFile(_SUBPAGEFORM_PATH) - - interface.implements(interfaces.ISubPageForm) +# BBB +from five.formlib.formbase import FiveFormlibMixin +from five.formlib.formbase import FormBase +from five.formlib.formbase import EditFormBase +from five.formlib.formbase import DisplayFormBase +from five.formlib.formbase import AddFormBase +from five.formlib.formbase import PageForm +from five.formlib.formbase import Form +from five.formlib.formbase import PageEditForm +from five.formlib.formbase import EditForm +from five.formlib.formbase import PageDisplayForm +from five.formlib.formbase import DisplayForm +from five.formlib.formbase import PageAddForm +from five.formlib.formbase import AddForm +from five.formlib.formbase import SubPageForm +from five.formlib.formbase import SubPageEditForm +from five.formlib.formbase import SubPageDisplayForm Modified: Zope/branches/2.12/versions.cfg =================================================================== --- Zope/branches/2.12/versions.cfg 2009-12-30 02:12:39 UTC (rev 107344) +++ Zope/branches/2.12/versions.cfg 2009-12-30 02:16:45 UTC (rev 107345) @@ -7,6 +7,7 @@ DateTime = 2.12.0 docutils = 0.6 ExtensionClass = 2.11.3 +five.formlib = 1.0.2 lxml = 2.2 mechanize = 0.1.11 Persistence = 2.11.1 _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org https://mail.zope.org/mailman/listinfo/zope-checkins