source: main/waeup.sirp/trunk/src/waeup/sirp/widgets/objectwidget.py @ 6465

Last change on this file since 6465 was 5328, checked in by uli, 14 years ago

Merge changes from ulif-fasttables back into trunk.

File size: 2.7 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.interface import implements, implementsOnly
29from zope.schema import getFieldNamesInOrder
30
31class WAeUPObjectWidgetView(ObjectWidgetView):
32    template = ViewPageTemplateFile('objectwidget.pt')
33
34class WAeUPObjectWidget(ObjectWidget):
35
36    def __init__(self, context, request, factory, **kw):
37        #super(ResultsEntryWidget, self).__init__(context, request)
38        super(ObjectWidget, self).__init__(context, request)
39
40        # define view that renders the widget
41        self.view = self._getView(request)
42
43        # factory used to create content that this widget (field)
44        # represents
45        self.factory = factory
46
47        # handle foo_widget specs being passed in
48        self.names = getFieldNamesInOrder(self.context.schema)
49        for k, v in kw.items():
50            if k.endswith('_widget'):
51                setattr(self, k, v)
52
53        # set up my subwidgets
54        self._setUpWidgets()
55
56    def subwidgets(self):
57        result = [self.getSubWidget(name) for name in self.names]
58        return result
59
60    def _setUpWidgets(self):
61        return self._setUpEditWidgets()
62
63    def _getView(self, request):
64        return WAeUPObjectWidgetView(self, request)
65
66class WAeUPObjectDisplayWidget(WAeUPObjectWidget):
67
68    implementsOnly(IDisplayWidget)
69
70    def _setUpDisplayWidgets(self):
71        # subwidgets need a new name
72        setUpWidgets(self, self.context.schema, IDisplayWidget,
73                         prefix=self.name, names=self.names,
74                         context=self.context)
75
76    def _setUpWidgets(self):
77        return self._setUpDisplayWidgets()
Note: See TracBrowser for help on using the repository browser.