[7766] | 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 |
---|
[7797] | 25 | from zope.formlib.interfaces import IInputWidget, IDisplayWidget |
---|
| 26 | from zope.formlib.widgets import ( |
---|
| 27 | ListSequenceWidget, SequenceDisplayWidget) |
---|
[7766] | 28 | from zope.publisher.interfaces.browser import IBrowserRequest |
---|
| 29 | from zope.schema.interfaces import IField, IList |
---|
| 30 | |
---|
[7819] | 31 | class KofaSequenceWidget(ListSequenceWidget): |
---|
[7766] | 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 | |
---|
[7797] | 39 | class KofaSequenceDisplayWidget(SequenceDisplayWidget): |
---|
| 40 | """A sequence widget for lists. |
---|
[7766] | 41 | |
---|
[7797] | 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 |
---|
[7802] | 47 | itemTag = 'div' |
---|
[7797] | 48 | |
---|
| 49 | # Register our sequence widgets as default for lists. |
---|
[7766] | 50 | @grok.adapter(IList, IField, IBrowserRequest) |
---|
| 51 | @grok.implementer(IInputWidget) |
---|
| 52 | def seq_input_widget(obj, field, req, *args, **kw): |
---|
[7819] | 53 | return KofaSequenceWidget(obj, field, req, *args, **kw) |
---|
[7797] | 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) |
---|