source: main/waeup.sirp/branches/ulif-fasttables/src/waeup/sirp/widgets/objectwidget.py @ 5305

Last change on this file since 5305 was 5302, checked in by uli, 14 years ago

Move widgets from jambtables to widgets module.

File size: 2.6 KB
Line 
1##
2## resultswidget.py
3## Login : <uli@pu.smp.net>
4## Started on  Tue Jul 20 02:04:30 2010 Uli Fouquet
5## $Id$
6##
7## Copyright (C) 2010 Uli Fouquet
8## This program is free software; you can redistribute it and/or modify
9## it under the terms of the GNU General Public License as published by
10## the Free Software Foundation; either version 2 of the License, or
11## (at your option) any later version.
12##
13## This program is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16## GNU General Public License for more details.
17##
18## You should have received a copy of the GNU General Public License
19## along with this program; if not, write to the Free Software
20## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21##
22"""A widget to display IObject instances in forms.
23"""
24from zope.browserpage import ViewPageTemplateFile
25from zope.formlib.interfaces import IDisplayWidget
26from zope.formlib.objectwidget import ObjectWidget, ObjectWidgetView
27from zope.formlib.utility import setUpWidgets
28from zope.schema import getFieldNamesInOrder
29
30class WAeUPObjectWidgetView(ObjectWidgetView):
31    template = ViewPageTemplateFile('objectwidget.pt')
32
33class WAeUPObjectWidget(ObjectWidget):
34
35    def __init__(self, context, request, factory, **kw):
36        #super(ResultsEntryWidget, self).__init__(context, request)
37        super(ObjectWidget, self).__init__(context, request)
38
39        # define view that renders the widget
40        self.view = self._getView(request)
41
42        # factory used to create content that this widget (field)
43        # represents
44        self.factory = factory
45
46        # handle foo_widget specs being passed in
47        self.names = getFieldNamesInOrder(self.context.schema)
48        for k, v in kw.items():
49            if k.endswith('_widget'):
50                setattr(self, k, v)
51
52        # set up my subwidgets
53        self._setUpWidgets()
54
55    def subwidgets(self):
56        result = [self.getSubWidget(name) for name in self.names]
57        return result
58
59    def _setUpWidgets(self):
60        return self._setUpEditWidgets()
61
62    def _getView(self, request):
63        return ResultsEntryWidgetView(self, request)
64
65class WAeUPObjectDisplayWidget(WAeUPObjectWidget):
66
67    def _setUpDisplayWidgets(self):
68        # subwidgets need a new name
69        setUpWidgets(self, self.context.schema, IDisplayWidget,
70                         prefix=self.name, names=self.names,
71                         context=self.context)
72
73    def _setUpWidgets(self):
74        return self._setUpDisplayWidgets()
Note: See TracBrowser for help on using the repository browser.