[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/app/
Merged r26931 and r26932 from trunk.
Garrett Smith
garrett at mojave-corp.com
Wed Aug 11 12:08:41 EDT 2004
Log message for revision 27000:
Merged r26931 and r26932 from trunk.
Changed:
U Zope3/branches/ZopeX3-3.0/src/zope/app/configure.zcml
U Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/boolwidgets.py
U Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/support.py
A Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/test_booleanradiowidget.py
U Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/itemswidgets.py
U Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/metaconfigure.py
U Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_itemswidget.py
U Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_radiowidget.py
U Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_selectwidget.py
-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/configure.zcml
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/configure.zcml 2004-08-11 15:55:55 UTC (rev 26999)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/configure.zcml 2004-08-11 16:08:41 UTC (rev 27000)
@@ -55,6 +55,18 @@
<include package="zope.app.utility" />
<include package="zope.app.principalannotation" />
+<<<<<<< .working
+=======
+ <!-- Utilities -->
+ <include package="zope.app.schema" />
+ <include package="zope.app.uniqueid" />
+
+ <!-- Misc. Service Manager objects -->
+ <!-- Aktari delete - we don't want this
+ <include package="zope.app.module" />
+ -->
+
+>>>>>>> .merge-right.r26932
<!-- Broken-object support -->
<include package="zope.app.broken" />
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/boolwidgets.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/boolwidgets.py 2004-08-11 15:55:55 UTC (rev 26999)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/boolwidgets.py 2004-08-11 16:08:41 UTC (rev 27000)
@@ -89,17 +89,17 @@
def BooleanRadioWidget(field, request, true=_('on'), false=_('off')):
- vocabulary = SimpleVocabulary.fromItems( ((True, true), (False, false)) )
+ vocabulary = SimpleVocabulary.fromItems( ((true, True), (false, False)) )
return RadioWidget(field, vocabulary, request)
def BooleanSelectWidget(field, request, true=_('on'), false=_('off')):
- vocabulary = SimpleVocabulary.fromItems( ((True, true), (False, false)) )
+ vocabulary = SimpleVocabulary.fromItems( ((true, True), (false, False)) )
widget = SelectWidget(field, vocabulary, request)
widget.size = 2
return widget
def BooleanDropdownWidget(field, request, true=_('on'), false=_('off')):
- vocabulary = SimpleVocabulary.fromItems( ((True, true), (False, false)) )
+ vocabulary = SimpleVocabulary.fromItems( ((true, True), (false, False)) )
return DropdownWidget(field, vocabulary, request)
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/support.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/support.py 2004-08-11 15:55:55 UTC (rev 26999)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/support.py 2004-08-11 16:08:41 UTC (rev 27000)
@@ -18,16 +18,30 @@
import re
from zope.configuration import xmlconfig
-def registerEditForm(schema):
+def registerEditForm(schema, widgets={}):
+ """Registers an edit form for the specified schema.
+
+ widgets is a mapping of field name to dict. The dict for each field must
+ contain a 'class' item, which is the widget class, and any additional
+ widget attributes (e.g. text field size, rows, cols, etc.)
+ """
+ widgetsXml = []
+ for field in widgets:
+ widgetsXml.append('<widget field="%s"' % field)
+ for attr in widgets[field]:
+ widgetsXml.append(' %s="%s"' % (attr, widgets[field][attr]))
+ widgetsXml.append(' />')
xmlconfig.string("""
<configure xmlns="http://namespaces.zope.org/browser">
<include package="zope.app.form.browser" file="meta.zcml" />
<editform
name="edit.html"
schema="%s"
- permission="zope.View" />
+ permission="zope.View">
+ %s
+ </editform>
</configure>
- """ % schema.__identifier__)
+ """ % (schema.__identifier__, ''.join(widgetsXml)))
def defineSecurity(class_, schema):
Copied: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/test_booleanradiowidget.py (from rev 26932, Zope3/trunk/src/zope/app/form/browser/ftests/test_booleanradiowidget.py)
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/itemswidgets.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/itemswidgets.py 2004-08-11 15:55:55 UTC (rev 26999)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/itemswidgets.py 2004-08-11 16:08:41 UTC (rev 27000)
@@ -25,7 +25,8 @@
from zope.app.form.browser.widget import SimpleInputWidget, renderElement
from zope.app.form.browser.interfaces import IVocabularyQueryView
from zope.app.form.interfaces import IInputWidget, IDisplayWidget
-from zope.app.form.interfaces import WidgetInputError
+from zope.app.form.interfaces import ConversionError
+
from zope.app.i18n import ZopeMessageIDFactory as _
@@ -123,29 +124,6 @@
values.append(term.value)
return values
- def getInputValue(self):
- """Get the value that was inputed."""
- input = self.request.form.get(self.name, self._data_marker)
- field = self.context
-
- # missing value is okay if field is not required
- if input == self._data_marker and not field.required and \
- self.empty_marker_name in self.request.form:
- return field.missing_value
-
- # Now let's see whether we have a valid input value
- try:
- value = self._toFieldValue(input)
- except ValidationError, error:
- self._error = WidgetInputError(
- self.context.__name__,
- self.context.title,
- error)
-
- raise self._error
-
- return value
-
def _emptyMarker(self):
"""Mark the form so that empty selections are also valid."""
return '<input name="%s" type="hidden" value="1" />' % (
@@ -156,10 +134,6 @@
return (self.name in self.request.form or
self.empty_marker_name in self.request.form)
- def setRenderedValue(self, value):
- """Store the ready-for-HTML value."""
- self._data = value
-
def _toFieldValue(self, input):
"""See SimpleInputWidget"""
raise NotImplementedError(
@@ -167,21 +141,7 @@
"It may be inherited from the mix-in classes SingleDataHelper\n"
"or MultiDataHelper")
- def _getFormValue(self):
- if self._data is self._data_marker:
- # The data has not been retrieved from the form, so let's do that
- if self.hasInput():
- try:
- value = self.getInputValue()
- except WidgetInputError:
- value = self.request.form.get(self.name, self._missing)
- else:
- value = self._getDefault()
- else:
- value = self._data
- return value
-
class SingleDataHelper(object):
"""Mix-in helper class for getting the term from the HTML form.
@@ -190,9 +150,12 @@
def _toFieldValue(self, input):
if input:
- return self.convertTokensToValues([input])[0]
+ try:
+ return self.convertTokensToValues([input])[0]
+ except InvalidValue, e:
+ raise ConversionError("Invalid value", e)
else:
- return None
+ return self.context.missing_value
def hidden(self):
return renderElement(u'input',
@@ -218,7 +181,10 @@
return []
if not isinstance(input, list):
input = [input]
- return self.convertTokensToValues(input)
+ try:
+ return self.convertTokensToValues(input)
+ except InvalidValue, e:
+ raise ConversionError("Invalid value", e)
def _getDefault(self):
# Return the default value for this widget;
@@ -239,7 +205,7 @@
def __call__(self):
"""See IBrowserWidget."""
value = self._getFormValue()
- if value is None:
+ if not value:
return self.translate(self._messageNoValue)
else:
term = self.vocabulary.getTerm(value)
@@ -359,8 +325,7 @@
have_results = True
contents.append(self._div('value', self.renderValue(value)))
- if not self.context.required:
- contents.append(self._emptyMarker())
+ contents.append(self._emptyMarker())
if self.queryview is not None and not have_results:
html = self.queryview.renderInput()
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/metaconfigure.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/metaconfigure.py 2004-08-11 15:55:55 UTC (rev 26999)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/metaconfigure.py 2004-08-11 16:08:41 UTC (rev 27000)
@@ -62,16 +62,16 @@
def widget(self, _context, field, class_, **kw):
attrs = kw
- ifaces = implementedBy(class_)
# Try to do better than accepting the string value by looking through
# the interfaces and trying to find the field, so that we can use
# 'fromUnicode()'
- for name, value in kw.items():
- for iface in ifaces:
- if name in iface:
- attrs[name] = iface[name].fromUnicode(value)
- break
-
+ if isinstance(class_, type):
+ ifaces = implementedBy(class_)
+ for name, value in kw.items():
+ for iface in ifaces:
+ if name in iface:
+ attrs[name] = iface[name].fromUnicode(value)
+ break
self._widgets[field+'_widget'] = CustomWidgetFactory(class_, **attrs)
def _processWidgets(self):
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_itemswidget.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_itemswidget.py 2004-08-11 15:55:55 UTC (rev 26999)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_itemswidget.py 2004-08-11 16:08:41 UTC (rev 27000)
@@ -22,7 +22,7 @@
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
from zope.publisher.browser import TestRequest
-from zope.app.form.interfaces import WidgetInputError
+from zope.app.form.interfaces import ConversionError
from zope.app.form.browser.itemswidgets import ItemsWidgetBase
from zope.app.form.browser.itemswidgets import ItemDisplayWidget
from zope.app.form.browser.itemswidgets import ItemsMultiDisplayWidget
@@ -201,7 +201,7 @@
widget = self._makeWidget(form={'field.choice': 'ten'})
widget.setPrefix('field.')
widget._getFormValue()
- self.assert_(isinstance(widget._error, WidgetInputError))
+ self.assert_(isinstance(widget._error, ConversionError))
def test_hidden(self):
widget = self._makeWidget(form={'field.choice': 'token2'})
@@ -397,7 +397,7 @@
widget = self._makeWidget(form={'field.numbers': ['ten']})
widget.setPrefix('field.')
widget._getFormValue()
- self.assert_(isinstance(widget._error, WidgetInputError))
+ self.assert_(isinstance(widget._error, ConversionError))
def test_hidden(self):
widget = self._makeWidget(
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_radiowidget.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_radiowidget.py 2004-08-11 15:55:55 UTC (rev 26999)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_radiowidget.py 2004-08-11 16:08:41 UTC (rev 27000)
@@ -102,6 +102,25 @@
self.verifyResult(self._widget.hidden(), check_list)
+ def testHasInput(self):
+ self._widget.request.form.clear()
+ self.assert_(not self._widget.hasInput())
+ self._widget.request.form['field.foo-empty-marker'] = '1'
+ self.assert_(self._widget.hasInput())
+ self._widget.request.form['field.foo'] = u'Foo Value'
+ self.assert_(self._widget.hasInput())
+ del self._widget.request.form['field.foo-empty-marker']
+ self.assert_(self._widget.hasInput())
+
+
+ def testRenderEmptyMarker(self):
+ self.verifyResult(self._widget(), ('field.foo-empty-marker',))
+ self._widget.setRenderedValue(u'bar')
+ self.verifyResult(self._widget(), ('field.foo-empty-marker',))
+ self._widget.setRenderedValue(u'not a legal value')
+ self.verifyResult(self._widget(), ('field.foo-empty-marker',))
+
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(RadioWidgetTest),
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_selectwidget.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_selectwidget.py 2004-08-11 15:55:55 UTC (rev 26999)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/tests/test_selectwidget.py 2004-08-11 16:08:41 UTC (rev 27000)
@@ -32,12 +32,22 @@
class SelectWidgetTest(unittest.TestCase):
-
+
def _makeWidget(self, form):
request = TestRequest(form=form)
- return SelectWidget(sequence, request)
+ return SelectWidget(sequence, request)
+select_html = '''<div id="field.terms">
+<div class="value">
+<select name="field.terms" size="5" >
+<option value="< foo">< foo</option>
+<option value="bar/>">bar/></option>
+<option value="&blah&">&blah&</option>
+</select>
+</div>
+<input name="field.terms-empty-marker" type="hidden" value="1" />
+</div>'''
def test_suite():
More information about the Zope3-Checkins
mailing list