[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Forms/Views/Browser - IBrowserWidget.py:1.3 Widget.py:1.10
Jim Fulton
jim@zope.com
Mon, 28 Oct 2002 18:53:02 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Forms/Views/Browser
In directory cvs.zope.org:/tmp/cvs-serv12652/lib/python/Zope/App/Forms/Views/Browser
Modified Files:
IBrowserWidget.py Widget.py
Log Message:
Merged the form (Zope.App.Forms) changes from the
Zope3-Banagalore-TTW-Branch branch.
See IWidget and IBrwoserWidget for important changes to those
interfaces.
See Utility.py for a number of functions for managing schema-driven
forms. These will ultimately replace FormViews, which will, I hope,
soon be deprecated.
=== Zope3/lib/python/Zope/App/Forms/Views/Browser/IBrowserWidget.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/App/Forms/Views/Browser/IBrowserWidget.py:1.2 Tue Jul 16 10:03:02 2002
+++ Zope3/lib/python/Zope/App/Forms/Views/Browser/IBrowserWidget.py Mon Oct 28 18:52:31 2002
@@ -25,11 +25,36 @@
default value and so on.
"""
+ def setPrefix(self, prefix):
+ """Set the form-variable name prefix used for the widget
+
+ The widget will define it's own form variable names by
+ concatinating the profix and the field name using a dot. For
+ example, with a prefix of "page" and a field name of "title",
+ a form name of "page.title" will be used. A widget may use
+ multiple form fields. If so, it should add distinguishing
+ suffixes to the prefix and field name.
+ """
+
+ def __call__():
+ """Render the widget
+ """
+
+ def hidden():
+ """Render the widget as a hidden field
+ """
+
+
+ # XXX The following methods are being supported for backward compatability
+ # They are depricated and will be refactored away eventually.
def render(value):
- """Renders this widget as HTML using property values in field."""
+ """Renders this widget as HTML using property values in field.
+ The value if given will be used as the default value for the widget.
+ """
- def render_hidden(field, key, value):
- """Renders this widget as a hidden field."""
+ def renderHidden(value):
+ """Renders this widget as a hidden field.
+ """
=== Zope3/lib/python/Zope/App/Forms/Views/Browser/Widget.py 1.9 => 1.10 ===
--- Zope3/lib/python/Zope/App/Forms/Views/Browser/Widget.py:1.9 Sat Sep 7 12:18:48 2002
+++ Zope3/lib/python/Zope/App/Forms/Views/Browser/Widget.py Mon Oct 28 18:52:31 2002
@@ -33,39 +33,59 @@
__implements__ = IBrowserWidget
converter = Converter.NullConverter()
- propertyNames = Widget.propertyNames + \
- ['tag', 'type', 'cssClass', 'hidden', 'extra']
+ propertyNames = (Widget.propertyNames +
+ ['tag', 'type', 'cssClass', 'extra'])
tag = 'input'
type = 'text'
cssClass = ''
- hidden = 0
extra = ''
+ _data = ''
+ _prefix = 'field.'
-
+ def setPrefix(self, prefix):
+ if not prefix.endswith("."):
+ prefix += '.'
+ self._prefix = prefix
+
def _getRawData(self):
- return self.request.form["field_" + self.getName()]
+ return self.request.form[self._prefix + self.context.__name__]
def _convert(self, value):
return self.converter.convert(value)
- def render(self, value):
+ def setData(self, value):
+ self._data = value
+
+ def __call__(self):
'See Zope.App.Forms.Views.Browser.IBrowserWidget.IBrowserWidget'
return renderElement(self.getValue('tag'),
type = self.getValue('type'),
- name = self.getName(),
- value = value,
+ name = self._prefix + self.context.__name__,
+ value = self._data,
cssClass = self.getValue('cssClass'),
extra = self.getValue('extra'))
- def renderHidden(self, value):
+ def hidden(self):
'See Zope.App.Forms.Views.Browser.IBrowserWidget.IBrowserWidget'
return renderElement(self.getValue('tag'),
type = 'hidden',
- name = self.getName(),
- value = value,
+ name = self._prefix + self.context.__name__,
+ value = self._data,
cssClass = self.getValue('cssClass'),
extra = self.getValue('extra'))
+
+
+
+ def render(self, value):
+ 'See Zope.App.Forms.Views.Browser.IBrowserWidget.IBrowserWidget'
+ self.setData(value)
+ return self()
+
+ def renderHidden(self, value):
+ 'See Zope.App.Forms.Views.Browser.IBrowserWidget.IBrowserWidget'
+ self.setData(value)
+ return self.hidden()
class CheckBoxWidget(BrowserWidget):
@@ -77,19 +97,19 @@
default = 0
extra = ''
- def render(self, value):
+ def __call__(self):
'See Zope.App.Forms.Views.Browser.IBrowserWidget.IBrowserWidget'
- if value:
+ if self._data:
return renderElement(self.getValue('tag'),
type = self.getValue('type'),
- name = self.context.getName(),
+ name = self._prefix + self.context.__name__,
checked = None,
cssClass = self.getValue('cssClass'),
extra = self.getValue('extra'))
else:
return renderElement(self.getValue('tag'),
type = self.getValue('type'),
- name = self.context.getName(),
+ name = self._prefix + self.context.__name__,
cssClass = self.getValue('cssClass'),
size = self.getValue('displayWidth'),
extra = self.getValue('extra'))
@@ -104,14 +124,14 @@
displayMaxWidth = ""
extra = ''
- def render(self, value):
+ def __call__(self):
'See Zope.App.Forms.Views.Browser.IBrowserWidget.IBrowserWidget'
displayMaxWidth = self.getValue('displayMaxWidth') or 0
if displayMaxWidth > 0:
return renderElement(self.getValue('tag'),
type = self.getValue('type'),
- name = self.context.getName(),
- value = value,
+ name = self._prefix + self.context.__name__,
+ value = self._data,
cssClass = self.getValue('cssClass'),
size = self.getValue('displayWidth'),
maxlength = displayMaxWidth,
@@ -119,8 +139,8 @@
else:
return renderElement(self.getValue('tag'),
type = self.getValue('type'),
- name = self.context.getName(),
- value = value,
+ name = self._prefix + self.context.__name__,
+ value = self._data,
cssClass = self.getValue('cssClass'),
size = self.getValue('displayWidth'),
extra = self.getValue('extra'))
@@ -153,15 +173,15 @@
height = 15
extra=""
- def render(self, value):
+ def __call__(self):
'See Zope.App.Forms.Views.Browser.IBrowserWidget.IBrowserWidget'
return renderElement("textarea",
- name=self.context.getName(),
- cssClass=self.getValue('cssClass'),
- cols=self.getValue('width'),
- rows=self.getValue('height'),
- contents=value,
- extra=self.getValue('extra'))
+ name = self._prefix + self.context.__name__,
+ cssClass = self.getValue('cssClass'),
+ cols = self.getValue('width'),
+ rows = self.getValue('height'),
+ contents = self._data,
+ extra = self.getValue('extra'))
class PasswordWidget(TextWidget):
@@ -174,13 +194,13 @@
converter = Converter.FileToStrConverter()
type = 'file'
- def render(self, value):
+ def __call__(self):
'See Zope.App.Forms.Views.Browser.IBrowserWidget.IBrowserWidget'
displayMaxWidth = self.getValue('displayMaxWidth') or 0
if displayMaxWidth > 0:
return renderElement(self.getValue('tag'),
type = self.getValue('type'),
- name = self.context.getName(),
+ name = self._prefix + self.context.__name__,
cssClass = self.getValue('cssClass'),
size = self.getValue('displayWidth'),
maxlength = displayMaxWidth,
@@ -188,7 +208,7 @@
else:
return renderElement(self.getValue('tag'),
type = self.getValue('type'),
- name = self.context.getName(),
+ name = self._prefix + self.context.__name__,
cssClass = self.getValue('cssClass'),
size = self.getValue('displayWidth'),
extra = self.getValue('extra'))
@@ -206,7 +226,7 @@
firstItem = 0
def renderItems(self, value):
- name = self.context.getName()
+ name = self._prefix + self.context.__name__
# get items
items = self.context.items
if callable(items):
@@ -253,15 +273,15 @@
['firstItem', 'items', 'size', 'extra']
size = 5
- def render(self, value):
+ def __call__(self):
'See Zope.App.Forms.Views.Browser.IBrowserWidget.IBrowserWidget'
- renderedItems = self.renderItems(value)
+ renderedItems = self.renderItems(self._data)
return renderElement('select',
- name=self.context.getName(),
- cssClass=self.getValue('cssClass'),
- size=self.getValue('size'),
- contents="\n".join(renderedItems),
- extra=self.getValue('extra'))
+ name = self._prefix + self.context.__name__,
+ cssClass = self.getValue('cssClass'),
+ size = self.getValue('size'),
+ contents = "\n".join(renderedItems),
+ extra = self.getValue('extra'))
def renderItem(self, text, value, name, cssClass):
return renderElement('option', contents=text, value=value,
@@ -278,9 +298,9 @@
['firstItem', 'items', 'orientation']
orientation = "vertical"
- def render(self, value):
+ def __call__(self):
'See Zope.App.Forms.Views.Browser.IBrowserWidget.IBrowserWidget'
- rendered_items = self.renderItems(value)
+ rendered_items = self.renderItems(self._data)
orientation = self.getValue('orientation')
if orientation == 'horizontal':
return " ".join(rendered_items)
@@ -289,18 +309,18 @@
def renderItem(self, text, value, name, cssClass):
return renderElement('input',
- type="radio",
- cssClass=cssClass,
- name=name,
- value=value) + text
+ type = "radio",
+ cssClass = cssClass,
+ name = name,
+ value = value) + text
def renderSelectedItem(self, text, value, name, cssClass):
return renderElement('input',
type="radio",
cssClass=cssClass,
- name=name,
- value=value,
- checked=None) + text
+ name = name,
+ value = value,
+ checked = None) + text
class MultiItemsWidget(ItemsWidget):
@@ -315,7 +335,7 @@
if not isinstance(value, ListTypes):
value = [value]
- name = self.context.getName()
+ name = self._prefix + self.context.__name__
items = self.context.items
if callable(items):
items = items()
@@ -350,16 +370,16 @@
['items', 'size', 'extra']
size = 5
- def render(self, value):
+ def __call__(self):
'See Zope.App.Forms.Views.Browser.IBrowserWidget.IBrowserWidget'
- rendered_items = self.renderItems(value)
+ rendered_items = self.renderItems(self._data)
return renderElement('select',
- name=self.context.getName(),
- multiple=None,
- cssClass=self.getValue('cssClass'),
- size=self.getValue('size'),
- contents="\n".join(rendered_items),
- extra=self.getValue('extra'))
+ name = self._prefix + self.context.__name__,
+ multiple = None,
+ cssClass = self.getValue('cssClass'),
+ size = self.getValue('size'),
+ contents = "\n".join(rendered_items),
+ extra = self.getValue('extra'))
def renderItem(self, text, value, name, cssClass):
return renderElement('option', contents=text, value=value)
@@ -375,9 +395,9 @@
['items', 'orientation']
orientation = "vertical"
- def render(self, value):
+ def __call__(self):
'See Zope.App.Forms.Views.Browser.IBrowserWidget.IBrowserWidget'
- rendered_items = self.renderItems(value)
+ rendered_items = self.renderItems(self._data)
orientation = self.getValue('orientation')
if orientation == 'horizontal':
return " ".join(rendered_items)
@@ -386,18 +406,18 @@
def renderItem(self, text, value, name, cssClass):
return renderElement('input',
- type="checkbox",
- cssClass=cssClass,
- name=name,
- value=value) + text
+ type = "checkbox",
+ cssClass = cssClass,
+ name = name,
+ value = value) + text
def renderSelectedItem(self, text, value, name, cssClass):
return renderElement('input',
- type="checkbox",
- cssClass=cssClass,
- name=name,
- value=value,
- checked=None) + text
+ type = "checkbox",
+ cssClass = cssClass,
+ name = name,
+ value = value,
+ checked = None) + text
# XXX Note, some HTML quoting is needed in renderTag and renderElement.
@@ -405,9 +425,6 @@
def renderTag(tag, **kw):
"""Render the tag. Well, not all of it, as we may want to / it."""
attr_list = []
-
- if kw.has_key('name'):
- kw['name'] = 'field_' + kw['name']
# special case handling for cssClass
if 'cssClass' in kw: