source: main/waeup.kofa/trunk/src/waeup/kofa/widgets/objectwidget.py @ 17463

Last change on this file since 17463 was 14013, checked in by Henrik Bettermann, 8 years ago

Break line in object display widgets.

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