[Checkins] SVN: grokcore.view/trunk/s get rid of form stuff in
grokcore.view. there's now grokcore.formlib
Philipp von Weitershausen
philikon at philikon.de
Tue Jul 29 18:45:05 EDT 2008
Log message for revision 89007:
get rid of form stuff in grokcore.view. there's now grokcore.formlib
Changed:
U grokcore.view/trunk/setup.py
U grokcore.view/trunk/src/grokcore/view/__init__.py
D grokcore.view/trunk/src/grokcore/view/formlib.py
U grokcore.view/trunk/src/grokcore/view/meta.py
-=-
Modified: grokcore.view/trunk/setup.py
===================================================================
--- grokcore.view/trunk/setup.py 2008-07-29 22:43:02 UTC (rev 89006)
+++ grokcore.view/trunk/setup.py 2008-07-29 22:45:04 UTC (rev 89007)
@@ -34,7 +34,6 @@
'zope.app.pagetemplate',
'zope.traversing',
'zope.schema',
- 'zope.formlib',
# for ftests:
# TODO move these to extra_requires?
'zope.testbrowser',
Modified: grokcore.view/trunk/src/grokcore/view/__init__.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/__init__.py 2008-07-29 22:43:02 UTC (rev 89006)
+++ grokcore.view/trunk/src/grokcore/view/__init__.py 2008-07-29 22:45:04 UTC (rev 89007)
@@ -19,7 +19,7 @@
from grokcore.view.directive import layer, view, template, templatedir
from grokcore.view.util import url
-from grokcore.view.components import View, GrokForm, Skin
+from grokcore.view.components import View, Skin
from grokcore.view.components import PageTemplate, PageTemplateFile
from grokcore.view.components import IGrokLayer
Deleted: grokcore.view/trunk/src/grokcore/view/formlib.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/formlib.py 2008-07-29 22:43:02 UTC (rev 89006)
+++ grokcore.view/trunk/src/grokcore/view/formlib.py 2008-07-29 22:45:04 UTC (rev 89007)
@@ -1,138 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006-2007 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.
-#
-##############################################################################
-"""Grok formlib support
-"""
-from zope import interface, event, lifecycleevent
-from zope.interface.interfaces import IInterface
-from zope.formlib import form
-from zope.schema.interfaces import IField
-
-class action(form.action):
- """We override the action decorator we pass in our custom Action.
- """
- def __call__(self, success):
- action = Action(self.label, success=success, **self.options)
- self.actions.append(action)
- return action
-
-class Action(form.Action):
- def success(self, data):
- if self.success_handler is not None:
- return self.success_handler(self.form, **data)
-
-def Fields(*args, **kw):
- fields = []
- for key, value in kw.items():
- if IField.providedBy(value):
- value.__name__ = key
- fields.append(value)
- del kw[key]
- fields.sort(key=lambda field: field.order)
- return form.Fields(*(args + tuple(fields)), **kw)
-
-def get_auto_fields(context):
- """Get the form fields for context.
- """
- # for an interface context, we generate them from that interface
- if IInterface.providedBy(context):
- return form.Fields(context)
- # if we have a non-interface context, we're autogenerating them
- # from any schemas defined by the context
- fields = form.Fields(*most_specialized_interfaces(context))
- # we pull in this field by default, but we don't want it in our form
- fields = fields.omit('__name__')
- return fields
-
-AutoFields = get_auto_fields
-
-def most_specialized_interfaces(context):
- """Get interfaces for an object without any duplicates.
-
- Interfaces in a declaration for an object may already have been seen
- because it is also inherited by another interface. Don't return the
- interface twice, as that would result in duplicate names when creating
- the form.
- """
- declaration = interface.implementedBy(context)
- seen = []
- for iface in declaration.flattened():
- if interface_seen(seen, iface):
- continue
- seen.append(iface)
- return seen
-
-def interface_seen(seen, iface):
- """Return True if interface already is seen.
- """
- for seen_iface in seen:
- if seen_iface.extends(iface):
- return True
- return False
-
-def apply_data(context, form_fields, data, adapters=None, update=False):
- """Save form data (``data`` dict) on a ``context`` object.
-
- This is a beefed up version of zope.formlib.form.applyChanges().
- It allows you to specify whether values should be compared with
- the attributes on already existing objects or not, using the
- ``update`` parameter.
-
- Unlike zope.formlib.form.applyChanges(), it will return a
- dictionary of interfaces and their fields that were changed. This
- is necessary to appropriately send IObjectModifiedEvents.
- """
- if adapters is None:
- adapters = {}
-
- changes = {}
-
- for form_field in form_fields:
- field = form_field.field
- # Adapt context, if necessary
- interface = form_field.interface
- adapter = adapters.get(interface)
- if adapter is None:
- if interface is None:
- adapter = context
- else:
- adapter = interface(context)
- adapters[interface] = adapter
-
- name = form_field.__name__
- newvalue = data.get(name, form_field) # using form_field as marker
-
- if update:
- if ((newvalue is not form_field) and
- (field.get(adapter) != newvalue)):
- field.set(adapter, newvalue)
- changes.setdefault(interface, []).append(name)
- else:
- if newvalue is not form_field:
- field.set(adapter, newvalue)
- changes.setdefault(interface, []).append(name)
-
- return changes
-
-def apply_data_event(context, form_fields, data, adapters=None, update=False):
- """Like apply_data, but also sends an IObjectModifiedEvent.
- """
- changes = apply_data(context, form_fields, data, adapters, update)
-
- if changes:
- descriptions = []
- for interface, names in changes.items():
- descriptions.append(lifecycleevent.Attributes(interface, *names))
- event.notify(lifecycleevent.ObjectModifiedEvent(context, *descriptions))
-
- return changes
Modified: grokcore.view/trunk/src/grokcore/view/meta.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/meta.py 2008-07-29 22:43:02 UTC (rev 89006)
+++ grokcore.view/trunk/src/grokcore/view/meta.py 2008-07-29 22:45:04 UTC (rev 89007)
@@ -30,7 +30,6 @@
import grokcore.security
from grokcore.view import components
-from grokcore.view import formlib
from grokcore.view import templatereg
from grokcore.security.util import protect_name
@@ -123,25 +122,6 @@
return True
-class FormGrokker(martian.ClassGrokker):
- martian.component(components.GrokForm)
- martian.directive(grokcore.component.context)
-
- def execute(self, factory, config, context, **kw):
- # Set up form_fields from context class if they haven't been
- # configured manually already.
- if getattr(factory, 'form_fields', None) is None:
- factory.form_fields = formlib.get_auto_fields(context)
-
- if not getattr(factory.render, 'base_method', False):
- raise GrokError(
- "It is not allowed to specify a custom 'render' "
- "method for form %r. Forms either use the default "
- "template or a custom-supplied one." % factory,
- factory)
- return True
-
-
class TemplateGrokker(martian.GlobalGrokker):
# this needs to happen before any other grokkers execute that use
# the template registry
More information about the Checkins
mailing list