[Zope3-checkins] SVN: Zope3/trunk/ Re-committing revisions 65782
and 65783 reverted in 65826, after fixing a
Albertas Agejevas
alga at pov.lt
Mon Mar 6 07:58:25 EST 2006
Log message for revision 65831:
Re-committing revisions 65782 and 65783 reverted in 65826, after fixing a
failing ftest.
Moved HTML generation of SequenceWidgets from Python to a page template.
Updated CHANGES.txt about bugfixes done in revisions 65778 and 65781.
Changed:
U Zope3/trunk/doc/CHANGES.txt
A Zope3/trunk/src/zope/app/form/browser/sequencewidget.pt
U Zope3/trunk/src/zope/app/form/browser/sequencewidget.py
U Zope3/trunk/src/zope/app/form/browser/tests/test_sequencewidget.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2006-03-06 12:48:23 UTC (rev 65830)
+++ Zope3/trunk/doc/CHANGES.txt 2006-03-06 12:58:25 UTC (rev 65831)
@@ -52,6 +52,9 @@
Bug Fixes
+ - Fixed two bugs in SequenceWidgets: an exception was raised
+ on rendering and the errors of the subwidgets weren't displayed.
+
- Fixed issue 560: Bug in default AddView class.
- Fixed issue 546: non-ASCII docstring cause
Copied: Zope3/trunk/src/zope/app/form/browser/sequencewidget.pt (from rev 65825, Zope3/trunk/src/zope/app/form/browser/sequencewidget.pt)
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/sequencewidget.pt 2006-03-05 16:32:34 UTC (rev 65825)
+++ Zope3/trunk/src/zope/app/form/browser/sequencewidget.pt 2006-03-06 12:58:25 UTC (rev 65831)
@@ -0,0 +1,28 @@
+<table border="0" class="sequencewidget">
+ <tr tal:repeat="widget view/widgets">
+ <td>
+ <input class="editcheck" type="checkbox"
+ tal:attributes="
+ name string:${view/name}.remove_${repeat/widget/index}"
+ tal:condition="view/need_delete" />
+ </td>
+ <td>
+ <span tal:define="error widget/error"
+ tal:replace="structure error" tal:condition="error" />
+ <input tal:replace="structure widget" />
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2">
+ <input type="submit" value="Remove selected items"
+ tal:condition="view/need_delete"
+ tal:attributes="name string:${view/name}.remove"
+ i18n:attributes="value remove-selected-items" />
+ <input type="submit" value="Add foo"
+ tal:condition="view/need_add"
+ tal:attributes="name string:${view/name}.add;
+ value view/addButtonLabel" />
+ </td>
+ </tr>
+</table>
+<input tal:replace="structure view/marker" />
Modified: Zope3/trunk/src/zope/app/form/browser/sequencewidget.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/sequencewidget.py 2006-03-06 12:48:23 UTC (rev 65830)
+++ Zope3/trunk/src/zope/app/form/browser/sequencewidget.py 2006-03-06 12:58:25 UTC (rev 65831)
@@ -26,6 +26,7 @@
from zope.app.form import InputWidget
from zope.app.form.browser.widget import BrowserWidget
from zope.app.form.browser.widget import DisplayWidget, renderElement
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.app.i18n import ZopeMessageFactory as _
@@ -38,6 +39,8 @@
implements(IInputWidget)
+ template = ViewPageTemplateFile('sequencewidget.pt')
+
_type = tuple
def __init__(self, context, field, request, subwidget=None):
@@ -50,55 +53,34 @@
def __call__(self):
"""Render the widget"""
- assert self.context.value_type is not None
+ self._update()
+ return self.template()
- render = []
-
- # length of sequence info
+ def _update(self):
+ """Set various attributes for the template"""
sequence = self._getRenderedValue()
num_items = len(sequence)
- min_length = self.context.min_length
- max_length = self.context.max_length
+ self.need_add = (not self.context.max_length
+ or num_items < self.context.max_length)
+ self.need_delete = num_items and num_items > self.context.min_length
+ self.marker = self._getPresenceMarker(num_items)
- # generate each widget from items in the sequence - adding a
- # "remove" button for each one
- for i in range(num_items):
- value = sequence[i]
- render.append('<tr><td>')
- if num_items > min_length:
- render.append(
- '<input class="editcheck" type="checkbox" '
- 'name="%s.remove_%d" />\n' % (self.name, i)
- )
+ def widgets(self):
+ """Return a list of widgets to display"""
+ sequence = self._getRenderedValue()
+ result = []
+ for i, value in enumerate(sequence):
widget = self._getWidget(i)
widget.setRenderedValue(value)
- error = widget.error()
- if error:
- render.append(error)
- render.append('\n')
- render.append(widget() + '</td></tr>\n')
+ result.append(widget)
+ return result
- # possibly generate the "remove" and "add" buttons
- buttons = ''
- if render and num_items > min_length:
- button_label = _('remove-selected-items', "Remove selected items")
- button_label = translate(button_label, context=self.request,
- default=button_label)
- buttons += ('<input type="submit" value="%s" name="%s.remove"/>'
- % (button_label, self.name))
- if max_length is None or num_items < max_length:
- field = self.context.value_type
- button_label = _('Add %s')
- button_label = translate(button_label, context=self.request,
- default=button_label)
- button_label = button_label % (field.title or field.__name__)
- buttons += '<input type="submit" name="%s.add" value="%s" />\n' % (
- self.name, button_label)
- if buttons:
- render.append('<tr><td>%s</td></tr>\n' % buttons)
+ def addButtonLabel(self):
+ button_label = _('Add %s')
+ button_label = translate(button_label, context=self.request,
+ default=button_label)
+ return button_label % (self.context.title or self.context.__name__)
- return ('<table border="0">\n%s</table>\n%s'
- % (''.join(render), self._getPresenceMarker(num_items)))
def _getWidget(self, i):
"""Return a widget for the i-th number of the sequence.
Modified: Zope3/trunk/src/zope/app/form/browser/tests/test_sequencewidget.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/tests/test_sequencewidget.py 2006-03-06 12:48:23 UTC (rev 65830)
+++ Zope3/trunk/src/zope/app/form/browser/tests/test_sequencewidget.py 2006-03-06 12:58:25 UTC (rev 65831)
@@ -58,6 +58,10 @@
self._widget = self._WidgetFactory(
self.field, self.field.value_type, self.request)
+ def setUp(self):
+ setup.placefulSetUp()
+ self.setUpContent()
+
def _FieldFactory(self, **kw):
kw.update({
'__name__': u'foo',
@@ -301,10 +305,17 @@
>>> print widget()
<BLANKLINE>
...
- <tr><td><input class="editcheck" type="checkbox"
- name="field.foo.remove_0" />
- <input class="textType" id="field.foo.0.bar" name="field.foo.0.bar"
- size="20" type="text" value="" /></td></tr>
+ <tr>
+ <td>
+ <input class="editcheck" type="checkbox"
+ name="field.foo.remove_0" />
+ </td>
+ <td>
+ <input class="textType" id="field.foo.0.bar"
+ name="field.foo.0.bar"
+ size="20" type="text" value="" />
+ </td>
+ </tr>
...
However, if we call getInputValue or hasValidInput, the
@@ -316,11 +327,18 @@
>>> print widget()
<BLANKLINE>
...
- <tr><td><input class="editcheck" type="checkbox"
- name="field.foo.remove_0" />
- <span class="error">Required input is missing.</span>
- <input class="textType" id="field.foo.0.bar" name="field.foo.0.bar"
- size="20" type="text" value="" /></td></tr>
+ <tr>
+ <td>
+ <input class="editcheck" type="checkbox"
+ name="field.foo.remove_0" />
+ </td>
+ <td>
+ <span class="error">Required input is missing.</span>
+ <input class="textType" id="field.foo.0.bar"
+ name="field.foo.0.bar"
+ size="20" type="text" value="" />
+ </td>
+ </tr>
...
"""
@@ -390,14 +408,14 @@
def setUp(test):
- setup.placelessSetUp()
+ setup.placefulSetUp()
ztapi.browserViewProviding(ITextLine, TextWidget, IInputWidget)
ztapi.browserViewProviding(IWidgetInputError, WidgetInputErrorView,
IWidgetInputErrorView)
def tearDown(test):
- setup.placelessTearDown()
+ setup.placefulTearDown()
def test_suite():
More information about the Zope3-Checkins
mailing list