[Zope3-checkins] SVN: Zope3/trunk/src/z Primarily a checkin about
removing XXXs from zope.app.form.
Gary Poster
gary at zope.com
Fri Jul 29 17:10:06 EDT 2005
Log message for revision 37569:
Primarily a checkin about removing XXXs from zope.app.form.
Fixed disabled test for file widget; in the process made some of the functional
tests more careful.
Ripped out unavailable (and apparently rejected) 'usage' argument in
schemadisplay factory.
Ripped out unused 'menu' argument in many form factories.
Changed appropriate XXX marks to TODO.
In a couple of removed XXX comments, someone, possibly srichter, asked:
What about the __implements__ of the bases?
The __implements__ of the bases should all be part of the created type. Not
sure from the question if that was what the writer expected or not.
Changed:
U Zope3/trunk/src/z3checkins/ftests/test_z3checkins.py
U Zope3/trunk/src/zope/app/file/browser/ftests.py
U Zope3/trunk/src/zope/app/form/browser/add.py
U Zope3/trunk/src/zope/app/form/browser/addwizard.py
U Zope3/trunk/src/zope/app/form/browser/configure.zcml
U Zope3/trunk/src/zope/app/form/browser/editview.py
U Zope3/trunk/src/zope/app/form/browser/editwizard.py
U Zope3/trunk/src/zope/app/form/browser/ftests/support.py
U Zope3/trunk/src/zope/app/form/browser/ftests/test_filewidget.py
U Zope3/trunk/src/zope/app/form/browser/metaconfigure.py
U Zope3/trunk/src/zope/app/form/browser/schemadisplay.py
U Zope3/trunk/src/zope/app/form/browser/source.py
U Zope3/trunk/src/zope/app/form/browser/source.txt
U Zope3/trunk/src/zope/app/form/browser/tests/test_filewidget.py
U Zope3/trunk/src/zope/app/form/browser/textwidgets.py
U Zope3/trunk/src/zope/app/form/interfaces.py
-=-
Modified: Zope3/trunk/src/z3checkins/ftests/test_z3checkins.py
===================================================================
--- Zope3/trunk/src/z3checkins/ftests/test_z3checkins.py 2005-07-29 21:06:40 UTC (rev 37568)
+++ Zope3/trunk/src/z3checkins/ftests/test_z3checkins.py 2005-07-29 21:10:06 UTC (rev 37569)
@@ -54,6 +54,7 @@
response = self.publish('/z3c/@@+',
basic='mgr:mgrpw',
form={'field.data': self.open('msg1.txt'),
+ 'field.data.used': '',
'UPDATE_SUBMIT': u'Submit'})
self.assertEqual(response.getStatus(), 200)
self.assertEqual(response.getBody().count("Checkin message"), 1)
@@ -61,6 +62,7 @@
response = self.publish('/z3c/+/CheckinMessage',
basic='mgr:mgrpw',
form={'field.data': self.open('msg1.txt'),
+ 'field.data.used': '',
'UPDATE_SUBMIT': u'Submit'})
self.assertEqual(response.getStatus(), 302)
@@ -85,6 +87,7 @@
response = self.publish('/z3c/+/CheckinMessage',
basic='mgr:mgrpw',
form={'field.data': self.open('msg2.txt'),
+ 'field.data.used': '',
'UPDATE_SUBMIT': u'Submit'})
self.assertEqual(response.getStatus(), 302)
Modified: Zope3/trunk/src/zope/app/file/browser/ftests.py
===================================================================
--- Zope3/trunk/src/zope/app/file/browser/ftests.py 2005-07-29 21:06:40 UTC (rev 37568)
+++ Zope3/trunk/src/zope/app/file/browser/ftests.py 2005-07-29 21:10:06 UTC (rev 37569)
@@ -53,6 +53,7 @@
'/+/zope.app.file.File=',
form={'type_name': u'zope.app.file.File',
'field.data': StringIO('A file'),
+ 'field.data.used': '',
'add_input_name': u'file',
'UPDATE_SUBMIT': u'Add'},
basic='mgr:mgrpw')
@@ -82,6 +83,7 @@
response = self.publish(
'/file/@@edit.html',
form={'field.data': u'<h1>A File</h1>',
+ 'field.data.used': '',
'field.contentType': u'text/plain',
'UPDATE_SUBMIT': u'Edit'},
basic='mgr:mgrpw')
@@ -114,6 +116,7 @@
response = self.publish(
'/file/@@upload.html',
form={'field.data': StringIO('<h1>A file</h1>'),
+ 'field.data.used': '',
'field.contentType': u'text/plain',
'UPDATE_SUBMIT': u'Change'},
basic='mgr:mgrpw')
@@ -178,6 +181,7 @@
'/+/zope.app.file.Image=',
form={'type_name': u'zope.app.image.Image',
'field.data': StringIO(self.content),
+ 'field.data.used': '',
'add_input_name': u'image',
'UPDATE_SUBMIT': u'Add'},
basic='mgr:mgrpw')
@@ -207,6 +211,7 @@
response = self.publish(
'/image/@@upload.html',
form={'field.data': StringIO(''),
+ 'field.data.used': '',
'UPDATE_SUBMIT': u'Change'},
basic='mgr:mgrpw')
self.assertEqual(response.getStatus(), 200)
Modified: Zope3/trunk/src/zope/app/form/browser/add.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/add.py 2005-07-29 21:06:40 UTC (rev 37568)
+++ Zope3/trunk/src/zope/app/form/browser/add.py 2005-07-29 21:10:06 UTC (rev 37569)
@@ -154,8 +154,7 @@
def AddViewFactory(name, schema, label, permission, layer,
template, default_template, bases, for_,
fields, content_factory, arguments,
- keyword_arguments, set_before_add, set_after_add,
- menu=u''):
+ keyword_arguments, set_before_add, set_after_add):
class_ = SimpleViewClass(
template, used_for=schema, bases=bases, name=name)
Modified: Zope3/trunk/src/zope/app/form/browser/addwizard.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/addwizard.py 2005-07-29 21:06:40 UTC (rev 37568)
+++ Zope3/trunk/src/zope/app/form/browser/addwizard.py 2005-07-29 21:10:06 UTC (rev 37569)
@@ -126,7 +126,7 @@
self.__dict__['_factory_or_id'] = value
-# XXX: Needs unittest
+# TODO: Needs unittest
def AddWizardViewFactory(
name, schema, permission, layer, panes, fields,
template, default_template, bases, for_, content_factory, arguments,
Modified: Zope3/trunk/src/zope/app/form/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/configure.zcml 2005-07-29 21:06:40 UTC (rev 37568)
+++ Zope3/trunk/src/zope/app/form/browser/configure.zcml 2005-07-29 21:10:06 UTC (rev 37569)
@@ -451,7 +451,7 @@
permission="zope.Public"
/>
- <!-- Register the form documentation with the apidoc tool -->
+ <!-- Register the form documentation with the apidoc tool -->
<configure
xmlns:apidoc="http://namespaces.zope.org/apidoc"
xmlns:zcml="http://namespaces.zope.org/zcml"
Modified: Zope3/trunk/src/zope/app/form/browser/editview.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/editview.py 2005-07-29 21:06:40 UTC (rev 37568)
+++ Zope3/trunk/src/zope/app/form/browser/editview.py 2005-07-29 21:10:06 UTC (rev 37569)
@@ -123,7 +123,7 @@
def EditViewFactory(name, schema, label, permission, layer,
template, default_template, bases, for_, fields,
- fulledit_path=None, fulledit_label=None, menu=u''):
+ fulledit_path=None, fulledit_label=None):
class_ = SimpleViewClass(template, used_for=schema, bases=bases, name=name)
class_.schema = schema
Modified: Zope3/trunk/src/zope/app/form/browser/editwizard.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/editwizard.py 2005-07-29 21:06:40 UTC (rev 37568)
+++ Zope3/trunk/src/zope/app/form/browser/editwizard.py 2005-07-29 21:10:06 UTC (rev 37569)
@@ -209,8 +209,7 @@
def EditWizardViewFactory(name, schema, permission, layer,
panes, fields, template, default_template, bases, for_,
- menu=u'', use_session=False):
- # XXX What about the __implements__ of the bases?
+ use_session=False):
class_ = SimpleViewClass(template, used_for=schema, bases=bases, name=name)
class_.schema = schema
class_.panes = panes
@@ -227,7 +226,7 @@
if layer is None:
layer = IDefaultBrowserLayer
- # XXX: untested
+ # TODO: untested
sm = zapi.getGlobalSiteManager()
sm.provideAdapter((for_, layer), Interface, name, class_)
Modified: Zope3/trunk/src/zope/app/form/browser/ftests/support.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/ftests/support.py 2005-07-29 21:06:40 UTC (rev 37568)
+++ Zope3/trunk/src/zope/app/form/browser/ftests/support.py 2005-07-29 21:10:06 UTC (rev 37569)
@@ -83,8 +83,10 @@
def validationErrorExists(field, error_msg, source):
- return patternExists(
- '%s.*name="field.%s"' % (error_msg, field), source, re.DOTALL)
+ regex = re.compile(r'%s.*?name="field.(\w+)(?:\.[\w\.]+)?"' % (error_msg,),
+ re.DOTALL)
+ # compile it first because Python 2.3 doesn't allow flags in findall
+ return field in regex.findall(source)
def missingInputErrorExists(field, source):
Modified: Zope3/trunk/src/zope/app/form/browser/ftests/test_filewidget.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/ftests/test_filewidget.py 2005-07-29 21:06:40 UTC (rev 37568)
+++ Zope3/trunk/src/zope/app/form/browser/ftests/test_filewidget.py 2005-07-29 21:10:06 UTC (rev 37569)
@@ -107,7 +107,9 @@
response = self.publish('/test/edit.html', form={
'UPDATE_SUBMIT' : '',
'field.f1' : self.sampleTextFile,
- 'field.f2' : self.sampleTextFile })
+ 'field.f2' : self.sampleTextFile,
+ 'field.f1.used' : '',
+ 'field.f2.used' : '' })
self.assertEqual(response.getStatus(), 200)
self.assert_(updatedMsgExists(response.getBody()))
@@ -124,26 +126,25 @@
# submit an invalid file value
response = self.publish('/test/edit.html', form={
'UPDATE_SUBMIT' : '',
- 'field.f1' : 'not a file - same as missing input' })
+ 'field.f1' : 'not a file - same as missing input',
+ 'field.f1.used' : '',
+ 'field.f2.used' : '' })
self.assertEqual(response.getStatus(), 200)
self.assert_(validationErrorExists('f1',
'Form input is not a file object', response.getBody()))
- # For some reason this test does not work, which means that the missing
- # input recognition of file widgets does not work correctly. I just lost
- # my patience looking at it.
- def XXX_test_required_validation(self):
+ def test_required_validation(self):
self.getRootFolder()['test'] = FileTest()
transaction.commit()
# submit missing value for required field f1
response = self.publish('/test/edit.html', form={
- 'UPDATE_SUBMIT' : ''})
+ 'UPDATE_SUBMIT' : '',
+ 'field.f1.used' : '',
+ 'field.f2.used' : ''})
self.assertEqual(response.getStatus(), 200)
- print response.getBody()
-
# confirm error msgs
self.assert_(missingInputErrorExists('f1', response.getBody()))
self.assert_(not missingInputErrorExists('f2', response.getBody()))
@@ -156,7 +157,11 @@
# submit an empty text file
response = self.publish('/test/edit.html', form={
'UPDATE_SUBMIT' : '',
- 'field.f2' : self.emptyFile })
+ 'field.f2' : self.emptyFile,
+ # 'field.f1.used' : '', # we don't let f1 know that it was rendered
+ # or else it will complain (see test_required_validation) and the
+ # change will not succeed.
+ 'field.f2.used' : ''})
self.assertEqual(response.getStatus(), 200)
self.assert_(updatedMsgExists(response.getBody()))
Modified: Zope3/trunk/src/zope/app/form/browser/metaconfigure.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/metaconfigure.py 2005-07-29 21:06:40 UTC (rev 37568)
+++ Zope3/trunk/src/zope/app/form/browser/metaconfigure.py 2005-07-29 21:10:06 UTC (rev 37569)
@@ -270,7 +270,6 @@
args=self._args()+(self.content_factory, self.arguments,
self.keyword_arguments,
self.set_before_add, self.set_after_add),
- kw={'menu': self.menu},
)
class EditFormDirectiveBase(BaseFormDirective):
@@ -305,7 +304,6 @@
discriminator=self._discriminator(),
callable=EditViewFactory,
args=self._args(),
- kw={'menu': self.menu},
)
class FormDirective(EditFormDirective):
Modified: Zope3/trunk/src/zope/app/form/browser/schemadisplay.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/schemadisplay.py 2005-07-29 21:06:40 UTC (rev 37568)
+++ Zope3/trunk/src/zope/app/form/browser/schemadisplay.py 2005-07-29 21:10:06 UTC (rev 37569)
@@ -63,9 +63,7 @@
def DisplayViewFactory(name, schema, label, permission, layer,
template, default_template, bases, for_, fields,
- fulledit_path=None, fulledit_label=None, menu=u'',
- usage=u''):
- # XXX What about the __implements__ of the bases?
+ fulledit_path=None, fulledit_label=None):
class_ = SimpleViewClass(template, used_for=schema, bases=bases,
name=name)
class_.schema = schema
@@ -76,10 +74,6 @@
fulledit_label = "Full display"
class_.fulledit_label = fulledit_label
class_.generated_form = ViewPageTemplateFile(default_template)
- # XXX: Cannot work!
- class_.usage = usage or (
- menu and globalBrowserMenuService.getMenuUsage(menu)
- )
defineChecker(class_,
NamesChecker(("__call__", "__getitem__", "browserDefault"),
permission))
Modified: Zope3/trunk/src/zope/app/form/browser/source.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/source.py 2005-07-29 21:06:40 UTC (rev 37568)
+++ Zope3/trunk/src/zope/app/form/browser/source.py 2005-07-29 21:10:06 UTC (rev 37569)
@@ -179,7 +179,7 @@
def error(self):
if self._error:
- # XXX This code path is untested.
+ # TODO This code path is untested.
return zapi.getMultiAdapter((self._error, self.request),
IWidgetInputErrorView).snippet()
return ""
@@ -291,7 +291,7 @@
if token is None:
if field.required:
- # XXX This code path is untested.
+ # TODO This code path is untested.
raise zope.app.form.interfaces.MissingInputError(
field.__name__, self.label,
)
@@ -300,7 +300,7 @@
try:
value = self.terms.getValue(str(token))
except LookupError:
- # XXX This code path is untested.
+ # TODO This code path is untested.
err = zope.schema.interfaces.ValidationError(
"Invalid value id", token)
raise WidgetInputError(field.__name__, self.label, err)
@@ -311,7 +311,7 @@
try:
field.validate(value)
except ValidationError, err:
- # XXX This code path is untested.
+ # TODO This code path is untested.
self._error = WidgetInputError(field.__name__, self.label, err)
raise self._error
@@ -487,7 +487,7 @@
try:
field.validate(value)
except ValidationError, err:
- # XXX This code path is untested.
+ # TODO This code path is untested.
self._error = WidgetInputError(field.__name__, self.label, err)
raise self._error
Modified: Zope3/trunk/src/zope/app/form/browser/source.txt
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/source.txt 2005-07-29 21:06:40 UTC (rev 37568)
+++ Zope3/trunk/src/zope/app/form/browser/source.txt 2005-07-29 21:10:06 UTC (rev 37569)
@@ -480,7 +480,7 @@
Here the output looks very similar to the simple choice case. We get
a search input for each source. In this case, we don't show any
-inputs (XXX we probably should make it clearer that there are no
+inputs (TODO we probably should make it clearer that there are no
selected values.)
As before, we can search one of the sources:
Modified: Zope3/trunk/src/zope/app/form/browser/tests/test_filewidget.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/tests/test_filewidget.py 2005-07-29 21:06:40 UTC (rev 37568)
+++ Zope3/trunk/src/zope/app/form/browser/tests/test_filewidget.py 2005-07-29 21:10:06 UTC (rev 37569)
@@ -49,6 +49,13 @@
self.assertEqual(self._widget.displayWidth, 20)
self.assertEqual(self._widget.displayMaxWidth, '')
+ def test_hasInput(self): # override the usual one
+ del self._widget.request.form['field.foo']
+ self._widget.request.form['field.foo.used'] = ''
+ self.failUnless(self._widget.hasInput())
+ del self._widget.request.form['field.foo.used']
+ self.failIf(self._widget.hasInput())
+
def testRender(self):
value = 'Foo Value'
self._widget.setRenderedValue(value)
Modified: Zope3/trunk/src/zope/app/form/browser/textwidgets.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/textwidgets.py 2005-07-29 21:06:40 UTC (rev 37568)
+++ Zope3/trunk/src/zope/app/form/browser/textwidgets.py 2005-07-29 21:10:06 UTC (rev 37569)
@@ -136,7 +136,7 @@
'size': self.displayWidth,
'extra': self.extra}
if self.displayMaxWidth:
- kwargs['maxlength'] = self.displayMaxWidth # XXX This is untested.
+ kwargs['maxlength'] = self.displayMaxWidth # TODO This is untested.
return renderElement(self.tag, **kwargs)
@@ -402,8 +402,13 @@
def __call__(self):
displayMaxWidth = self.displayMaxWidth or 0
+ hidden = renderElement(self.tag,
+ type='hidden',
+ name=self.name+".used",
+ id=self.name+".used",
+ value="")
if displayMaxWidth > 0:
- return renderElement(self.tag,
+ elem = renderElement(self.tag,
type=self.type,
name=self.name,
id=self.name,
@@ -412,16 +417,17 @@
maxlength=displayMaxWidth,
extra=self.extra)
else:
- return renderElement(self.tag,
+ elem = renderElement(self.tag,
type=self.type,
name=self.name,
id=self.name,
cssClass=self.cssClass,
size=self.displayWidth,
extra=self.extra)
+ return "%s %s" % (hidden, elem)
def _toFieldValue(self, input):
- if input == '':
+ if input is None or input == '':
return self.context.missing_value
try:
seek = input.seek
@@ -436,6 +442,9 @@
else:
return self.context.missing_value
+ def hasInput(self):
+ return self.name+".used" in self.request.form
+
class IntWidget(TextWidget):
"""Integer number widget.
Modified: Zope3/trunk/src/zope/app/form/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/form/interfaces.py 2005-07-29 21:06:40 UTC (rev 37568)
+++ Zope3/trunk/src/zope/app/form/interfaces.py 2005-07-29 21:10:06 UTC (rev 37569)
@@ -45,7 +45,7 @@
self.errors = errors
def doc(self):
- # XXX this duck typing is to get the code working. See
+ # TODO this duck typing is to get the code working. See
# collector issue 372
if isinstance(self.errors, basestring):
return self.errors
More information about the Zope3-Checkins
mailing list