1 | ## $Id$ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2012 Uli Fouquet & Henrik Bettermann |
---|
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. |
---|
8 | ## |
---|
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. |
---|
13 | ## |
---|
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 | ## |
---|
18 | """An improved sequence widget. |
---|
19 | |
---|
20 | We provide a sequence widget that better suits our needs layout-wise |
---|
21 | than the default implementation from zope.formlib. |
---|
22 | """ |
---|
23 | import grok |
---|
24 | from zope.browserpage import ViewPageTemplateFile |
---|
25 | from zope.formlib.interfaces import IInputWidget, IDisplayWidget |
---|
26 | from zope.formlib.widgets import ( |
---|
27 | ListSequenceWidget, SequenceDisplayWidget) |
---|
28 | from zope.publisher.interfaces.browser import IBrowserRequest |
---|
29 | from zope.schema.interfaces import IField, IList |
---|
30 | |
---|
31 | class SIRPSequenceWidget(ListSequenceWidget): |
---|
32 | """A sequence widget for lists. |
---|
33 | |
---|
34 | This is basically a plain copy from zope.formlib. We have, |
---|
35 | however, the possibility to tweak the attached template. |
---|
36 | """ |
---|
37 | template = ViewPageTemplateFile('sequencewidget.pt') |
---|
38 | |
---|
39 | class KofaSequenceDisplayWidget(SequenceDisplayWidget): |
---|
40 | """A sequence widget for lists. |
---|
41 | |
---|
42 | This is basically a plain copy from zope.formlib. We have, |
---|
43 | however, the possibility to tweak html tags. |
---|
44 | """ |
---|
45 | |
---|
46 | tag = None |
---|
47 | itemTag = 'div' |
---|
48 | |
---|
49 | # Register our sequence widgets as default for lists. |
---|
50 | @grok.adapter(IList, IField, IBrowserRequest) |
---|
51 | @grok.implementer(IInputWidget) |
---|
52 | def seq_input_widget(obj, field, req, *args, **kw): |
---|
53 | return SIRPSequenceWidget(obj, field, req, *args, **kw) |
---|
54 | |
---|
55 | @grok.adapter(IList, IField, IBrowserRequest) |
---|
56 | @grok.implementer(IDisplayWidget) |
---|
57 | def seq_display_widget(obj, field, req, *args, **kw): |
---|
58 | return KofaSequenceDisplayWidget(obj, field, req, *args, **kw) |
---|