[Zope-Checkins] SVN: Products.Five/branches/1.4/ - made some Zope 3
formlib fixes available
Yvo Schubbe
y.2006_ at wcm-solutions.de
Wed Oct 25 07:56:09 EDT 2006
Log message for revision 70910:
- made some Zope 3 formlib fixes available
Changed:
U Products.Five/branches/1.4/CHANGES.txt
UU Products.Five/branches/1.4/formlib/configure.zcml
UU Products.Five/branches/1.4/formlib/formbase.py
UU Products.Five/branches/1.4/formlib/pageform.pt
D Products.Five/branches/1.4/formlib/subpageform.pt
-=-
Modified: Products.Five/branches/1.4/CHANGES.txt
===================================================================
--- Products.Five/branches/1.4/CHANGES.txt 2006-10-25 11:37:25 UTC (rev 70909)
+++ Products.Five/branches/1.4/CHANGES.txt 2006-10-25 11:56:08 UTC (rev 70910)
@@ -8,6 +8,9 @@
Bugfixes
--------
+* formlib: Removed redundant subpageform.pt and backported pageform.pt fixes
+ from Zope 3. Added missing error view and i18n configuration.
+
* Made the __call__ method of ViewMixinForAttributes have the same signature
as the original attribute. This aids some pathological request parameter
marshalling.
Modified: Products.Five/branches/1.4/formlib/configure.zcml
===================================================================
--- Products.Five/branches/1.4/formlib/configure.zcml 2006-10-25 11:37:25 UTC (rev 70909)
+++ Products.Five/branches/1.4/formlib/configure.zcml 2006-10-25 11:56:08 UTC (rev 70910)
@@ -1,6 +1,20 @@
<configure
+ package="zope.formlib"
xmlns="http://namespaces.zope.org/zope"
- xmlns:zc="http://namespaces.zope.com/zc"
+ xmlns:i18n="http://namespaces.zope.org/i18n"
i18n_domain="zope.formlib">
- <adapter factory="zope.formlib.form.render_submit_button" name="render" />
+
+ <i18n:registerTranslations directory="locales"/>
+
+ <adapter
+ factory=".form.render_submit_button"
+ name="render"
+ />
+
+ <!-- Error view for 'Invalid' -->
+ <adapter
+ factory=".errors.InvalidErrorView"
+ permission="zope.Public"
+ />
+
</configure>
Property changes on: Products.Five/branches/1.4/formlib/configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: Products.Five/branches/1.4/formlib/formbase.py
===================================================================
--- Products.Five/branches/1.4/formlib/formbase.py 2006-10-25 11:37:25 UTC (rev 70909)
+++ Products.Five/branches/1.4/formlib/formbase.py 2006-10-25 11:56:08 UTC (rev 70910)
@@ -15,39 +15,49 @@
$Id$
"""
+import os.path
+
from datetime import datetime
import Acquisition
import zope.event
+import zope.formlib
import zope.app.event.objectevent
from zope import interface
from zope.formlib import interfaces, form, namedtemplate
from zope.app.i18n import ZopeMessageFactory as _
-from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile
+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 = 'pageform.pt'
+_SUBPAGEFORM_PATH = os.path.join(_FORMLIB_DIR, 'subpageform.pt')
+
+
class FiveFormlibMixin(Acquisition.Explicit):
# 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 = ZopeTwoPageTemplateFile('pageform.pt')
-
+
+ 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):
# Overrides formlib.form.EditFormBase.handle_edit_action, to remove
@@ -57,7 +67,7 @@
def handle_edit_action(self, action, data):
if form.applyChanges(
self.context, self.form_fields, data, self.adapters):
-
+
zope.event.notify(
zope.app.event.objectevent.ObjectModifiedEvent(self.context)
)
@@ -68,51 +78,60 @@
)
else:
self.status = _('No changes')
-
+
+
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 = ZopeTwoPageTemplateFile('subpageform.pt')
-
+ template = ViewPageTemplateFile(_SUBPAGEFORM_PATH)
+
interface.implements(interfaces.ISubPageForm)
+
class SubPageEditForm(EditFormBase):
- template = ZopeTwoPageTemplateFile('subpageform.pt')
-
+ template = ViewPageTemplateFile(_SUBPAGEFORM_PATH)
+
interface.implements(interfaces.ISubPageForm)
+
class SubPageDisplayForm(DisplayFormBase):
- template = ZopeTwoPageTemplateFile('subpageform.pt')
-
+ template = ViewPageTemplateFile(_SUBPAGEFORM_PATH)
+
interface.implements(interfaces.ISubPageForm)
Property changes on: Products.Five/branches/1.4/formlib/formbase.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: Products.Five/branches/1.4/formlib/pageform.pt
===================================================================
--- Products.Five/branches/1.4/formlib/pageform.pt 2006-10-25 11:37:25 UTC (rev 70909)
+++ Products.Five/branches/1.4/formlib/pageform.pt 2006-10-25 11:56:08 UTC (rev 70910)
@@ -1,8 +1,4 @@
-<html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:metal="http://xml.zope.org/namespaces/metal"
- xmlns:tal="http://xml.zope.org/namespaces/tal"
- xmlns:i18n="http://xml.zope.org/namespaces/i18n"
- metal:use-macro="context/@@standard_macros/page">
+<html metal:use-macro="context/@@standard_macros/view">
<head>
</head>
@@ -15,31 +11,47 @@
tal:attributes="action request/URL" method="post"
class="edit-form" enctype="multipart/form-data"
id="zc.page.browser_form">
-
+
<script type="text/javascript"><!--
- function toggleFormFieldHelp(ob,state) {
+function toggleFormFieldHelp(ob,state) {
// ob is the label element
- var field = ob.form[ob.htmlFor];
+ var field = findWidgetDiv(ob);
if (field) {
- var viz = state && 'hidden' || 'visible';
- if (field.length == null) {
- field.style.visibility = viz;
+ field.style.visibility = state && 'hidden' || 'visible';
+ var help = document.getElementById("field-help-for-" + ob.htmlFor);
+ if (help) {
+ help.style.visibility = state && 'visible' || 'hidden';
+ }
}
- else {
- for (var i = 0; i < field.length; ++i) {
- var e = field.item(i);
- e.style.visibility = viz;
+}
+
+function findWidgetDiv(label) {
+ var element = findFormField(label);
+ while (element) {
+ element = element.parentNode;
+ if (element.tagName == 'DIV' && element.getAttribute('class') == 'widget')
+ return element;
}
+}
+
+function findFormField(label) {
+ var name = label.htmlFor;
+ var field = label.form[name];
+ // Multiple fields with the same name, such as radiobuttons
+ if (field) {
+ if (field.length)
+ field = field[0];
+ return field;
}
- var help = document.getElementById("field-help-for-" + field.name);
- if (help) {
- help.style.visibility = state && 'visible' || 'hidden';
+ // No field with the exact name; find one that starts with the name
+ for (var i = 0; field = label.form[i++];) {
+ if (field.name.substr(0, name.length) == name)
+ return field;
}
- }
- }
+}
- //-->
+//-->
</script>
<div id="viewspace" metal:define-slot="viewspace">
@@ -142,9 +154,6 @@
</div>
</form>
-<script type="text/javascript" metal:define-slot="trackChanges">
- zc_trackChanges(document.getElementById('zc.page.browser_form'));
-</script>
<script type="text/javascript"
tal:define="extra_script view/extra_script | nothing"
Property changes on: Products.Five/branches/1.4/formlib/pageform.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Deleted: Products.Five/branches/1.4/formlib/subpageform.pt
===================================================================
--- Products.Five/branches/1.4/formlib/subpageform.pt 2006-10-25 11:37:25 UTC (rev 70909)
+++ Products.Five/branches/1.4/formlib/subpageform.pt 2006-10-25 11:56:08 UTC (rev 70910)
@@ -1,106 +0,0 @@
-<div metal:define-macro="form">
-
- <h1
- i18n:translate=""
- tal:condition="view/label"
- tal:content="view/label"
- metal:define-slot="heading"
- >Do something</h1>
-
- <div class="form-status"
- tal:define="status view/status"
- tal:condition="status">
-
- <div class="summary" tal:content="view/status" i18n:translate="">
- 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>
-
- <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>
- <td class="label"><input type="text" /></td>
- </tr>
- <tbody metal:define-slot="formbody" tal:omit-tag="">
- <tr tal:repeat="widget view/widgets">
- <td class="label" tal:define="hint widget/hint"
- metal:define-macro="labelcell">
- <label tal:condition="python:hint"
- tal:attributes="for widget/name"
- onmousedown="toggleFormFieldHelp(this,1)"
- onmouseup="toggleFormFieldHelp(this,0)"
- onmouseout="toggleFormFieldHelp(this,0)"
- style="cursor: help">
- <span class="required" tal:condition="widget/required"
- >*</span><span i18n:translate=""
- tal:content="widget/label">label</span>
- </label>
- <label tal:condition="python:not hint"
- tal:attributes="for widget/name">
- <span class="required" tal:condition="widget/required"
- >*</span><span i18n:translate=""
- tal:content="widget/label">label</span>
- </label>
- </td>
- <td class="field" tal:define="hint widget/hint"
- metal:define-macro="widgetcell">
- <div class="form-fields-help"
- tal:content="hint"
- tal:condition="hint"
- tal:attributes="id string:field-help-for-${widget/name}"
- onclick="this.style.visibility='hidden';"
- i18n:translate=""
- style="visibility: hidden; position: absolute;"
- >Title of this content object.</div>
- <div class="widget" tal:content="structure widget">
- <input type="text" /></div>
- <div class="error"
- define="error widget/error"
- tal:condition="widget/error"
- >
- <!-- TODO Put this back, the Zope3 way.
- <img src="alert.gif" alt="Error"
- tal:replace="structure context/alert.gif" />
- -->
- <span tal:replace="structure widget/error">error</span>
- </div>
- </td>
- </tr>
- </tbody>
- <tr class="row" metal:define-slot="extra_bottom" tal:replace="nothing">
- <td class="label">Extra bottom</td>
- <td class="label"><input type="text" /></td>
- </tr>
- </table>
-
- <div class="form-controls" tal:condition="view/availableActions"
- metal:define-slot="bottom_buttons">
- <input tal:repeat="action view/actions"
- tal:replace="structure action/render"
- />
- </div>
-
-<script type="text/javascript"
- tal:define="extra_script view/extra_script | nothing"
- tal:condition="extra_script"
- tal:content="structure extra_script" />
-
-</div>
More information about the Zope-Checkins
mailing list