[Checkins]
SVN: grok/trunk/src/grok/ Document form API in interface,
inspired by IFormBaseCustomization.
Philipp von Weitershausen
philikon at philikon.de
Fri Mar 16 15:06:18 EDT 2007
Log message for revision 73233:
Document form API in interface, inspired by IFormBaseCustomization.
Changed:
U grok/trunk/src/grok/components.py
U grok/trunk/src/grok/interfaces.py
-=-
Modified: grok/trunk/src/grok/components.py
===================================================================
--- grok/trunk/src/grok/components.py 2007-03-16 18:47:44 UTC (rev 73232)
+++ grok/trunk/src/grok/components.py 2007-03-16 19:06:18 UTC (rev 73233)
@@ -414,6 +414,10 @@
return False
class Form(GrokForm, form.FormBase, View):
+ # We're only reusing the form implementation from zope.formlib, we
+ # explicitly don't want to inherit the interface semantics (mostly
+ # for the different meanings of update/render).
+ interface.implementsOnly(interfaces.IGrokForm)
template = default_form_template
@@ -421,9 +425,17 @@
pass
class EditForm(GrokForm, form.EditFormBase, View):
+ # We're only reusing the form implementation from zope.formlib, we
+ # explicitly don't want to inherit the interface semantics (mostly
+ # for the different meanings of update/render).
+ interface.implementsOnly(interfaces.IGrokForm)
template = default_form_template
class DisplayForm(GrokForm, form.DisplayFormBase, View):
+ # We're only reusing the form implementation from zope.formlib, we
+ # explicitly don't want to inherit the interface semantics (mostly
+ # for the different meanings of update/render).
+ interface.implementsOnly(interfaces.IGrokForm)
template = default_display_template
Modified: grok/trunk/src/grok/interfaces.py
===================================================================
--- grok/trunk/src/grok/interfaces.py 2007-03-16 18:47:44 UTC (rev 73232)
+++ grok/trunk/src/grok/interfaces.py 2007-03-16 19:06:18 UTC (rev 73233)
@@ -13,8 +13,9 @@
##############################################################################
"""Grok interfaces
"""
-from zope import interface
+from zope import interface, schema
from zope.publisher.interfaces.browser import IBrowserPage
+from zope.formlib.interfaces import reConstraint
class IGrokBaseClasses(interface.Interface):
ClassGrokker = interface.Attribute("Base class to define a class "
@@ -144,6 +145,7 @@
method. The method receives the form data as keyword
parameters."""
+
class IGrokEvents(interface.Interface):
IObjectCreatedEvent = interface.Attribute("")
@@ -261,6 +263,97 @@
filled in from the request (in that case they *must* be
present in the request)."""
+
+class IGrokForm(IGrokView):
+ """Grok form API, inspired by zope.formlib's IFormBaseCustomization.
+
+ We explicitly don't inherit from IFormBaseCustomization because
+ that would imply ISubPage with another definition of update() and
+ render() than IGrokView has.
+ """
+
+ prefix = schema.ASCII(
+ constraint=reConstraint(
+ '[a-zA-Z][a-zA-Z0-9_]*([.][a-zA-Z][a-zA-Z0-9_]*)*',
+ "Must be a sequence of not-separated identifiers"),
+ description=u"""Page-element prefix
+
+ All named or identified page elements in a subpage should have
+ names and identifiers that begin with a subpage prefix
+ followed by a dot.
+ """,
+ readonly=True,
+ )
+
+ def setPrefix(prefix):
+ """Update the subpage prefix
+ """
+
+ label = interface.Attribute("A label to display at the top of a form")
+
+ status = interface.Attribute(
+ """An update status message
+
+ This is normally generated by success or failure handlers.
+ """)
+
+ errors = interface.Attribute(
+ """Sequence of errors encountered during validation
+ """)
+
+ form_result = interface.Attribute(
+ """Return from action result method
+ """)
+
+ form_reset = interface.Attribute(
+ """Boolean indicating whether the form needs to be reset
+ """)
+
+ form_fields = interface.Attribute(
+ """The form's form field definitions
+
+ This attribute is used by many of the default methods.
+ """)
+
+ widgets = interface.Attribute(
+ """The form's widgets
+
+ - set by setUpWidgets
+
+ - used by validate
+ """)
+
+ def setUpWidgets(ignore_request=False):
+ """Set up the form's widgets.
+
+ The default implementation uses the form definitions in the
+ form_fields attribute and setUpInputWidgets.
+
+ The function should set the widgets attribute.
+ """
+
+ def validate(action, data):
+ """The default form validator
+
+ If an action is submitted and the action doesn't have it's own
+ validator then this function will be called.
+ """
+
+ template = interface.Attribute(
+ """Template used to display the form
+ """)
+
+ def resetForm():
+ """Reset any cached data because underlying content may have changed
+ """
+
+ def error_views():
+ """Return views of any errors.
+
+ The errors are returned as an iterable.
+ """
+
+
class IApplication(interface.Interface):
"""Marker-interface for grok application factories.
More information about the Checkins
mailing list