[Zope3-checkins] SVN: zope.formlib/trunk/src/zope/formlib/ - add
some notes about advanced usage in form.txt. Needs to be elaborated.
Gary Poster
gary at zope.com
Thu Jul 21 14:01:02 EDT 2005
Log message for revision 37371:
- add some notes about advanced usage in form.txt. Needs to be elaborated.
- corrected behavior of resetForm method
- reordered some code so that success actions can explicitly set reset_form to
False if they want to.
- add some slots we needed in the pageform template.
- remove duplicate error display in subpageform template.
Changed:
U zope.formlib/trunk/src/zope/formlib/form.py
U zope.formlib/trunk/src/zope/formlib/form.txt
U zope.formlib/trunk/src/zope/formlib/pageform.pt
U zope.formlib/trunk/src/zope/formlib/subpageform.pt
-=-
Modified: zope.formlib/trunk/src/zope/formlib/form.py
===================================================================
--- zope.formlib/trunk/src/zope/formlib/form.py 2005-07-21 17:39:33 UTC (rev 37370)
+++ zope.formlib/trunk/src/zope/formlib/form.py 2005-07-21 18:01:02 UTC (rev 37371)
@@ -699,7 +699,7 @@
return availableActions(self, self.actions)
def resetForm(self):
- self.setUpWidgets(ignore_request=False)
+ self.setUpWidgets(ignore_request=True)
form_result = None
form_reset = True
@@ -716,8 +716,8 @@
self.status = _('There were errors')
result = action.failure(data, errors)
elif errors is not None:
+ self.form_reset = True
result = action.success(data)
- self.form_reset = True
else:
result = None
Modified: zope.formlib/trunk/src/zope/formlib/form.txt
===================================================================
--- zope.formlib/trunk/src/zope/formlib/form.txt 2005-07-21 17:39:33 UTC (rev 37370)
+++ zope.formlib/trunk/src/zope/formlib/form.txt 2005-07-21 18:01:02 UTC (rev 37371)
@@ -1530,3 +1530,60 @@
`setUpWidgets` function takes an optional 'form' argument, which
**must** be passed if any fields use the get_rendered option. The
form base classes always pass the form to `setUpWidgets`.
+
+Advanced Usage Hints
+====================
+
+This section documents patterns for advanced usage of the formlib package.
+
+Multiple button groups
+----------------------
+
+Multiple button groups can be accomplished many ways, but the way we've found
+that reuses the most code is the following:
+
+ >>> import zope.cachedescriptors.property
+ >>> class MyForm(form.Form):
+ ... form_fields = form.Fields(IOrder)
+ ... primary_actions = form.Actions()
+ ... secondary_actions = form.Actions()
+ ... @zope.cachedescriptors.property.Lazy
+ ... def actions(self):
+ ... return list(self.primary_actions) + list(self.secondary_actions)
+ ... @form.action(u'Edit', primary_actions)
+ ... def handle_edit_action(self, action, data):
+ ... if form.applyChanges(self.context, self.form_fields, data):
+ ... self.status = 'Object updated'
+ ... else:
+ ... self.status = 'No changes'
+ ... @form.action(u'Submit for review...', secondary_actions)
+ ... def handle_review_action(self, action, data):
+ ... print "do something here"
+ ...
+
+The template then can render the button groups separately--something like the
+following, for instance:
+
+ <input tal:repeat="action view/primary_actions"
+ tal:replace="structure action/render"
+ />
+
+and
+
+ <input tal:repeat="action view/secondary_actions"
+ tal:replace="structure action/render"
+ />
+
+But the form machinery can still find the correct button. # TODO: demo
+
+Dividing display of widget errors and invariant errors
+------------------------------------------------------
+
+Even though the form machinery only has a single errors attribute, if designers
+wish to render widget errors differently than invariant errors, they can be
+separated reasonably easily. The separation takes advantage of the fact that
+all widget errors should implement zope.app.form.interfaces.IWidgetInputError,
+and invariant errors shouldn't, because they don't come from a widget.
+Therefore, a simple division such as the following should suffice.
+
+# TODO
Modified: zope.formlib/trunk/src/zope/formlib/pageform.pt
===================================================================
--- zope.formlib/trunk/src/zope/formlib/pageform.pt 2005-07-21 17:39:33 UTC (rev 37370)
+++ zope.formlib/trunk/src/zope/formlib/pageform.pt 2005-07-21 18:01:02 UTC (rev 37371)
@@ -41,7 +41,7 @@
//-->
</script>
-<div id="viewspace">
+<div id="viewspace" metal:define-slot="viewspace">
<h1 i18n:translate=""
tal:condition="view/label"
@@ -49,35 +49,30 @@
metal:define-slot="heading"
>Do something</h1>
- <div class="form-status"
- tal:define="status view/status"
- tal:condition="status">
+ <metal:block define-macro="header">
- <div class="summary"
- i18n:translate=""
- tal:content="view/status">
- Form status summary
+ <div class="form-status"
+ tal:define="status view/status"
+ tal:condition="status">
+
+ <div class="summary"
+ i18n:translate=""
+ tal:content="view/status">
+ Form status summary
+ </div>
+
+ <ul class="errors" tal:condition="view/errors">
+ <li tal:repeat="error view/error_views">
+ <span tal:replace="structure error">Error Type</span>
+ </li>
+ </ul>
</div>
- <ul class="errors" tal:condition="view/errors">
- <li tal:repeat="error view/error_views">
- <span tal:replace="structure error">Error Type</span>
- </li>
- </ul>
- </div>
+ </metal:block>
<div metal:define-slot="extra_info" tal:replace="nothing">
</div>
-<!--
- <div class="form-controls" tal:condition="view/availableActions"
- metal:define-slot="top_buttons">
- <input tal:repeat="action view/actions"
- tal:replace="structure action/render"
- />
- </div>
--->
-
<table class="form-fields">
<tr class="row" metal:define-slot="extra_top" tal:replace="nothing">
<td class="label">Extra top</td>
Modified: zope.formlib/trunk/src/zope/formlib/subpageform.pt
===================================================================
--- zope.formlib/trunk/src/zope/formlib/subpageform.pt 2005-07-21 17:39:33 UTC (rev 37370)
+++ zope.formlib/trunk/src/zope/formlib/subpageform.pt 2005-07-21 18:01:02 UTC (rev 37371)
@@ -49,11 +49,6 @@
<span tal:replace="structure error">Error Type</span>
</li>
</ul>
- <ul class="errors" tal:condition="view/errors">
- <li tal:repeat="error view/error_views">
- <span tal:replace="structure error">Error Type</span>
- </li>
- </ul>
</div>
<div metal:define-slot="extra_info" tal:replace="nothing">
More information about the Zope3-Checkins
mailing list