[Zope3-checkins] CVS: Zope3/src/zope/app/browser/component - interfacewidget.py:1.20
Steve Alexander
steve@cat-box.net
Fri, 17 Jan 2003 11:32:04 -0500
Update of /cvs-repository/Zope3/src/zope/app/browser/component
In directory cvs.zope.org:/tmp/cvs-serv15686/src/zope/app/browser/component
Modified Files:
interfacewidget.py
Log Message:
Fixed bugs todo with empty form fields. Added new test case.
=== Zope3/src/zope/app/browser/component/interfacewidget.py 1.19 => 1.20 ===
--- Zope3/src/zope/app/browser/component/interfacewidget.py:1.19 Thu Jan 16 14:50:25 2003
+++ Zope3/src/zope/app/browser/component/interfacewidget.py Fri Jan 17 11:31:32 2003
@@ -35,7 +35,7 @@
v = self.request.form[self.name]
return v and (v == 'None' or nameToInterface(self.context, v))
return False
-
+
def getData(self, optional=0):
field = self.context
value = self.request.form.get(self.name, self) # self used as marker
@@ -63,14 +63,14 @@
self.title, str(v))
return value
-
+
def __call__(self):
name = self.name
search_name = name + ".search"
search_string = self.request.form.get(search_name, '')
value = self.request.form.get(self.name, self) # self used as marker
-
+
field = self.context
service = getService(field.context, "Interfaces")
base = field.basetype
@@ -138,7 +138,7 @@
#
# name.i0, name.i1, ... the value of the interfaces
# name.search.i0, ... the search box for that interface
- #
+ #
def haveData(self):
name_i = self.name+'.i'
field = self.context
@@ -156,14 +156,14 @@
# values will be sorted in key order
values = [v
for k,v in items_sorted
- if k.startswith(name_i)]
+ if k.startswith(name_i)
+ if v]
if not values:
# No user input
if field.required and not optional:
raise MissingInputError(field.__name__, field.title,
'the field is required')
return field.default
-
try:
values = tuple([nameToInterface(field, value) for value in values])
except ComponentLookupError:
@@ -186,7 +186,7 @@
name = self.name
name_i = name+'.i'
name_search_i = name+'.search.i'
-
+
service = getService(field.context, "Interfaces")
base = field.basetype
include_none = base is None
@@ -195,7 +195,7 @@
if self._data is None: # no data has been set with Widget.setData(),
# so use the data in the form
-
+
# If a search term is entered, that interface selection remains.
# If an interface is selected, that interface selection remains.
# Remove all others.
@@ -229,7 +229,7 @@
# the order as the user might expect.
if selections[0][0] != 0:
first_is_blank = True
-
+
# get just [search, value], and discard the keys
selections = [v for k,v in selections]
# XXX is validation here really needed?
@@ -243,7 +243,7 @@
# data has been set with Widget.setData()
selections = [('', interfaceToName(interface))
for interface in self._data]
-
+
# If there are no empty values, add one extra empty selection
if not [1 for s,v in selections if v == '']:
# if first_is_blank, put the empty selection at the start
@@ -313,7 +313,7 @@
'See IBrowserWidget'
raise NotImplementedError
-
+
class InterfaceDisplayWidget(InterfaceWidget):
def __call__(self):
if self._data is None:
@@ -354,7 +354,7 @@
return HTML
def nameToInterface(context, name):
- if name is 'None':
+ if name == 'None':
return None
service = getService(context, "Interfaces")
return service.getInterface(name)