|
1 # |
|
2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net> |
|
3 # All Rights Reserved. |
|
4 # |
|
5 # This software is subject to the provisions of the Zope Public License, |
|
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
|
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|
10 # FOR A PARTICULAR PURPOSE. |
|
11 # |
|
12 |
|
13 __docformat__ = 'restructuredtext' |
|
14 |
|
15 |
|
16 # import standard library |
|
17 |
|
18 # import interfaces |
|
19 from z3c.form.interfaces import IFieldWidget |
|
20 from ztfy.myams.interfaces.widget import ISelect2Widget |
|
21 from zope.schema.interfaces import IChoice |
|
22 |
|
23 # import packages |
|
24 from z3c.form.browser.select import SelectWidget |
|
25 from z3c.form.widget import FieldWidget |
|
26 from zope.component import adapter |
|
27 from zope.i18n import translate |
|
28 from zope.interface import implementer, implementer_only |
|
29 from ztfy.myams.layer import MyAMSLayer |
|
30 |
|
31 from ztfy.myams import _ |
|
32 |
|
33 |
|
34 @implementer_only(ISelect2Widget) |
|
35 class Select2Widget(SelectWidget): |
|
36 """Select2 widget""" |
|
37 |
|
38 noValueMessage = _("(no selected value)") |
|
39 |
|
40 def get_content(self, entry): |
|
41 return translate(entry['content'], context=self.request) |
|
42 |
|
43 |
|
44 @adapter(IChoice, MyAMSLayer) |
|
45 @implementer(IFieldWidget) |
|
46 def ChoiceFieldWidget(field, request): |
|
47 return FieldWidget(field, Select2Widget(request)) |