[Zope3-checkins] CVS: Zope3/src/zope/app/form/browser -
objectwidget.pt:1.1 objectwidget.py:1.2
Garrett Smith
garrett at mojave-corp.com
Fri May 7 15:42:03 EDT 2004
Update of /cvs-repository/Zope3/src/zope/app/form/browser
In directory cvs.zope.org:/tmp/cvs-serv31620/src/zope/app/form/browser
Modified Files:
objectwidget.py
Added Files:
objectwidget.pt
Log Message:
Created a page template to render the object widget since widget row
method is no longer available for use.
=== Added File Zope3/src/zope/app/form/browser/objectwidget.pt ===
<fieldset>
<legend tal:content="context/legendTitle">The Legend</legend>
<tal:block repeat="widget context/subwidgets">
<metal:block use-macro="context/@@form_macros/widget_row" />
</tal:block>
</fieldset>
=== Zope3/src/zope/app/form/browser/objectwidget.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/form/browser/objectwidget.py:1.1 Wed Mar 17 12:35:02 2004
+++ Zope3/src/zope/app/form/browser/objectwidget.py Fri May 7 15:41:32 2004
@@ -21,7 +21,21 @@
from zope.app.form.interfaces import IInputWidget
from zope.app.form.browser.widget import BrowserWidget
from zope.app.form.utility import setUpEditWidgets, applyWidgetsChanges
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+
+class ObjectWidgetView:
+
+ template = ViewPageTemplateFile('objectwidget.pt')
+
+ def __init__(self, context, request):
+ self.context = context
+ self.request = request
+
+ def __call__(self):
+ return self.template()
+
+
class ObjectWidget(BrowserWidget):
"""A widget over an Interface that contains Fields.
@@ -38,6 +52,9 @@
def __init__(self, context, request, factory, **kw):
super(ObjectWidget, self).__init__(context, request)
+
+ # define view that renders the widget
+ self.view = ObjectWidgetView(self, request)
# factory used to create content that this widget (field)
# represents
@@ -63,33 +80,23 @@
context=self.context)
def __call__(self):
- """Render the widget
- """
- render = []
-
- # XXX see if there's some widget layout already
-
- # generate each widget from fields in the schema
- field = self.context
- title = field.title or field.__name__
- render.append('<fieldset><legend>%s</legend>'%title)
- for name, widget in self.getSubWidgets():
- render.append(widget.row())
- render.append('</fieldset>')
-
- return '\n'.join(render)
-
- def getSubWidgets(self):
- l = []
- for name in self.names:
- l.append((name, getattr(self, '%s_widget'%name)))
- return l
+ return self.view()
+
+ def legendTitle(self):
+ return self.context.title or self.context.__name__
+
+ def getSubWidget(self, name):
+ return getattr(self, '%s_widget' % name)
+
+ def subwidgets(self):
+ return [self.getSubWidget(name) for name in self.names]
def hidden(self):
- ''' Render the list as hidden fields '''
- for name, widget in self.getSubWidgets():
- s += widget.hidden()
- return s
+ """Render the list as hidden fields."""
+ result = []
+ for name in self.names:
+ result.append(getSubwidget(name).hidden())
+ return "".join(result)
def getInputValue(self):
"""Return converted and validated widget data.
@@ -101,8 +108,8 @@
does this).
"""
content = self.factory()
- for name, widget in self.getSubWidgets():
- setattr(content, name, widget.getInputValue())
+ for name in self.names:
+ setattr(content, name, self.getSubWidget(name).getInputValue())
return content
def applyChanges(self, content):
@@ -130,8 +137,8 @@
Return True if there is data and False otherwise.
"""
- for name, widget in self.getSubWidgets():
- if widget.hasInput():
+ for name in self.names:
+ if self.getSubWidget(name).hasInput():
return True
return False
@@ -143,7 +150,7 @@
"""
# re-call setupwidgets with the content
self._setUpEditWidgets()
- for name, widget in self.getSubWidgets():
- widget.setRenderedValue(getattr(value, name, None))
+ for name in self.names:
+ self.getSubWidget(name).setRenderedValue(getattr(value, name, None))
More information about the Zope3-Checkins
mailing list