source: main/waeup.sirp/branches/ulif-fasttables/src/waeup/sirp/jambtables/resultsentrywidget.py @ 5276

Last change on this file since 5276 was 5275, checked in by uli, 14 years ago

Add widget for resultentries. This could be used/named in a much wider field.

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