source: main/waeup.sirp/branches/ulif-images/src/waeup/sirp/widgets/multilistwidget.py @ 9819

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

Merge changes from ulif-fasttables back into trunk.

File size: 2.8 KB
Line 
1##
2## multilistwidget.py
3## Login : <uli@pu.smp.net>
4## Started on  Tue Jul 20 02:53:10 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 that renders multiple contained items horizontally.
23"""
24from zope.browserpage import ViewPageTemplateFile
25from zope.formlib.sequencewidget import (
26    ListSequenceWidget, SequenceDisplayWidget)
27from zope.formlib.widget import renderElement
28from zope.i18n import translate
29
30
31class MultiListWidget(ListSequenceWidget):
32    template = ViewPageTemplateFile('multilistwidget.pt')
33
34class MultiListDisplayWidget(SequenceDisplayWidget):
35    cssClass = "multiSequenceWidget"
36
37    def __call__(self):
38        # get the data to display:
39        if self._renderedValueSet():
40            data = self._data
41        else:
42            data = self.context.get(self.context.context)
43
44        # deal with special cases:
45        if data == self.context.missing_value:
46            return translate(self._missingValueMessage, self.request)
47        data = list(data)
48        if not data:
49            return translate(self._emptySequenceMessage, self.request)
50
51        parts = ['<table>']
52        for i, item in enumerate(data):
53            widget = self._getWidget(i)
54            if i == 0:
55                parts.append('<thead><tr>')
56                for x in widget.subwidgets():
57                    parts.append('<th>%s</th>' % x.label)
58                parts.append('</tr></thead><tbody>')
59            widget.setRenderedValue(item)
60            s = widget()
61            #print s
62            if self.itemTag:
63                #s = "<%s>%s</%s>" % (self.itemTag, s, self.itemTag)
64                evenodd = i%2 and 'odd' or 'even'
65                s = '<tr class="%s">%s</tr>' % (evenodd, s)
66            parts.append(s)
67        parts.append('</tbody></table>')
68        contents = "\n".join(parts)
69        if self.tag:
70            contents = "\n%s\n" % contents
71            contents = renderElement(self.tag,
72                                     cssClass=self.cssClass,
73                                     extra=self.extra,
74                                     contents=contents)
75        return contents
Note: See TracBrowser for help on using the repository browser.