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

Last change on this file since 10009 was 5310, checked in by uli, 14 years ago

Make sure that the ObjectDisplayWidget? only offers IDisplayWidget
capabilities and not also IInputWidget.

File size: 2.7 KB
RevLine 
[5275]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##
[5299]22"""A widget to display IObject instances in forms.
[5275]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
[5310]28from zope.interface import implements, implementsOnly
[5275]29from zope.schema import getFieldNamesInOrder
30
[5299]31class WAeUPObjectWidgetView(ObjectWidgetView):
32    template = ViewPageTemplateFile('objectwidget.pt')
[5275]33
[5299]34class WAeUPObjectWidget(ObjectWidget):
[5275]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):
[5306]64        return WAeUPObjectWidgetView(self, request)
[5275]65
[5300]66class WAeUPObjectDisplayWidget(WAeUPObjectWidget):
[5275]67
[5310]68    implementsOnly(IDisplayWidget)
69
[5275]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.