[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form - widget.py:1.29.4.4
Fred L. Drake, Jr.
fred@zope.com
Mon, 5 May 2003 15:11:05 -0400
Update of /cvs-repository/Zope3/src/zope/app/browser/form
In directory cvs.zope.org:/tmp/cvs-serv12634
Modified Files:
Tag: schema-vocabulary-branch
widget.py
Log Message:
better separate "get the value" from "render the value"
=== Zope3/src/zope/app/browser/form/widget.py 1.29.4.3 => 1.29.4.4 ===
--- Zope3/src/zope/app/browser/form/widget.py:1.29.4.3 Mon May 5 13:56:08 2003
+++ Zope3/src/zope/app/browser/form/widget.py Mon May 5 15:11:04 2003
@@ -743,19 +743,20 @@
assert field.context is not None
self.field = field
self.name = self._prefix + field.__name__
- if not self.haveData():
- # not provided by form, so pull data from the content object
- self.setData(self.field.get(field.context))
def __call__(self):
- return self.render()
+ if self.haveData():
+ value = self._showData()
+ else:
+ value = self.field.get(self.field.context)
+ return self.render(value)
def textForValue(self, term):
# Extract the value from the term. This can be overridden to
# support more complex term objects.
return term.value
- def render(self):
+ def render(self, value):
raise NotImplementedError(
"render() must be implemented by a subclass")
@@ -763,8 +764,7 @@
class VocabularyDisplayWidget(VocabularyWidgetBase):
"""Simple single-selection display that can be used in many cases."""
- def render(self):
- value = self.field.get(self.field.context)
+ def render(self, value):
term = self.field.vocabulary.getTerm(value)
return self.textForValue(term)
@@ -784,8 +784,8 @@
size = 5
tag = 'select'
- def render(self):
- rendered_items = self.renderItems(self._showData())
+ def render(self, value):
+ rendered_items = self.renderItems(value)
return renderElement(self.getValue('tag'),
type = self.getValue('type'),
name = self.name,