author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 19 Oct 2009 18:15:45 +0200 | |
changeset 3735 | 80fb4083c29b |
parent 3720 | 5376aaadd16b |
child 3890 | d7a270f50f54 |
permissions | -rw-r--r-- |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
1 |
"""field classes for form construction |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
2 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
3 |
:organization: Logilab |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1858
diff
changeset
|
4 |
:copyright: 2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1858
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
7 |
""" |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
8 |
__docformat__ = "restructuredtext en" |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
9 |
|
2244
52e2431e7cce
missing import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2196
diff
changeset
|
10 |
from warnings import warn |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
11 |
from datetime import datetime |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
12 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2244
diff
changeset
|
13 |
from logilab.mtconverter import xml_escape |
2459
d088d0ff48a1
move RichString and co to yams, keeping only a small monkeypatch for cw-page-template here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2362
diff
changeset
|
14 |
from yams.constraints import (SizeConstraint, StaticVocabularyConstraint, |
d088d0ff48a1
move RichString and co to yams, keeping only a small monkeypatch for cw-page-template here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2362
diff
changeset
|
15 |
FormatConstraint) |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
16 |
|
2678
0308dc159b96
use yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2568
diff
changeset
|
17 |
from cubicweb.utils import ustrftime |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
18 |
from cubicweb.common import tags, uilib |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
19 |
from cubicweb.web import INTERNAL_FIELD_VALUE |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
20 |
from cubicweb.web.formwidgets import ( |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
21 |
HiddenInput, TextInput, FileInput, PasswordInput, TextArea, FCKEditor, |
1437 | 22 |
Radio, Select, DateTimePicker) |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
23 |
|
1986
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
24 |
|
3334
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
25 |
def vocab_sort(vocab): |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
26 |
"""sort vocabulary, considering option groups""" |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
27 |
result = [] |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
28 |
partresult = [] |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
29 |
for label, value in vocab: |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
30 |
if value is None: # opt group start |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
31 |
if partresult: |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
32 |
result += sorted(partresult) |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
33 |
partresult = [] |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
34 |
result.append( (label, value) ) |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
35 |
else: |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
36 |
partresult.append( (label, value) ) |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
37 |
result += sorted(partresult) |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
38 |
return result |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
39 |
|
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
40 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
41 |
class Field(object): |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
42 |
"""field class is introduced to control what's displayed in forms. It makes |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
43 |
the link between something to edit and its display in the form. Actual |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
44 |
display is handled by a widget associated to the field. |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
45 |
|
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
46 |
Attributes |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
47 |
---------- |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
48 |
all the attributes described below have sensible default value which may be |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
49 |
overriden by value given to field's constructor. |
1437 | 50 |
|
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
51 |
:name: |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
52 |
name of the field (basestring), should be unique in a form. |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
53 |
:id: |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
54 |
dom identifier (default to the same value as `name`), should be unique in |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
55 |
a form. |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
56 |
:label: |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
57 |
label of the field (default to the same value as `name`). |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
58 |
:help: |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
59 |
help message about this field. |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
60 |
:widget: |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
61 |
widget associated to the field. Each field class has a default widget |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
62 |
class which may be overriden per instance. |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
63 |
:required: |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
64 |
bool flag telling if the field is required or not. |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
65 |
:initial: |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
66 |
initial value, used when no value specified by other means. |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
67 |
:choices: |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
68 |
static vocabulary for this field. May be a list of values or a list of |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
69 |
(label, value) tuples if specified. |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
70 |
:sort: |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
71 |
bool flag telling if the vocabulary (either static vocabulary specified |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
72 |
in `choices` or dynamic vocabulary fetched from the form) should be |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
73 |
sorted on label. |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
74 |
:internationalizable: |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
75 |
bool flag telling if the vocabulary labels should be translated using the |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
76 |
current request language. |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
77 |
:eidparam: |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
78 |
bool flag telling if this field is linked to a specific entity |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
79 |
:role: |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
80 |
when the field is linked to an entity attribute or relation, tells the |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
81 |
role of the entity in the relation (eg 'subject' or 'object') |
2520
8c5cf48ae9ea
new fieldset attribute on field, use to group fields by the default form renderer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2459
diff
changeset
|
82 |
:fieldset: |
8c5cf48ae9ea
new fieldset attribute on field, use to group fields by the default form renderer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2459
diff
changeset
|
83 |
optional fieldset to which this field belongs to |
1437 | 84 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
85 |
""" |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
86 |
# default widget associated to this class of fields. May be overriden per |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
87 |
# instance |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
88 |
widget = TextInput |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
89 |
# does this field requires a multipart form |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
90 |
needs_multipart = False |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
91 |
# class attribute used for ordering of fields in a form |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
92 |
__creation_rank = 0 |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
93 |
|
1437 | 94 |
def __init__(self, name=None, id=None, label=None, help=None, |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
95 |
widget=None, required=False, initial=None, |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
96 |
choices=None, sort=True, internationalizable=False, |
2520
8c5cf48ae9ea
new fieldset attribute on field, use to group fields by the default form renderer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2459
diff
changeset
|
97 |
eidparam=False, role='subject', fieldset=None): |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
98 |
self.name = name |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
99 |
self.id = id or name |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
100 |
self.label = label or name |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
101 |
self.help = help |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
102 |
self.required = required |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
103 |
self.initial = initial |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
104 |
self.choices = choices |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
105 |
self.sort = sort |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
106 |
self.internationalizable = internationalizable |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
107 |
self.eidparam = eidparam |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
108 |
self.role = role |
2520
8c5cf48ae9ea
new fieldset attribute on field, use to group fields by the default form renderer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2459
diff
changeset
|
109 |
self.fieldset = fieldset |
1986
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
110 |
self.init_widget(widget) |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
111 |
# ordering number for this field instance |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
112 |
self.creation_rank = Field.__creation_rank |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
113 |
Field.__creation_rank += 1 |
1437 | 114 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
115 |
def __unicode__(self): |
1562
e6d2c07c0c58
[forms/widgets] fix relation field not sorting its vocabulary, revert hack on Select widget
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1505
diff
changeset
|
116 |
return u'<%s name=%r label=%r id=%r initial=%r visible=%r @%x>' % ( |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
117 |
self.__class__.__name__, self.name, self.label, |
1562
e6d2c07c0c58
[forms/widgets] fix relation field not sorting its vocabulary, revert hack on Select widget
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1505
diff
changeset
|
118 |
self.id, self.initial, self.is_visible(), id(self)) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
119 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
120 |
def __repr__(self): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
121 |
return self.__unicode__().encode('utf-8') |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
122 |
|
1986
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
123 |
def init_widget(self, widget): |
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
124 |
if widget is not None: |
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
125 |
self.widget = widget |
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2086
diff
changeset
|
126 |
elif self.choices and not self.widget.vocabulary_widget: |
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2086
diff
changeset
|
127 |
self.widget = Select() |
1986
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
128 |
if isinstance(self.widget, type): |
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
129 |
self.widget = self.widget() |
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
130 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
131 |
def set_name(self, name): |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
132 |
"""automatically set .id and .label when name is set""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
133 |
assert name |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
134 |
self.name = name |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
135 |
if not self.id: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
136 |
self.id = name |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
137 |
if not self.label: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
138 |
self.label = name |
1437 | 139 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
140 |
def is_visible(self): |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
141 |
"""return true if the field is not an hidden field""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
142 |
return not isinstance(self.widget, HiddenInput) |
1437 | 143 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
144 |
def actual_fields(self, form): |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
145 |
"""return actual fields composing this field in case of a compound |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
146 |
field, usually simply return self |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
147 |
""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
148 |
yield self |
1437 | 149 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
150 |
def format_value(self, req, value): |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
151 |
"""return value suitable for display where value may be a list or tuple |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
152 |
of values |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
153 |
""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
154 |
if isinstance(value, (list, tuple)): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
155 |
return [self.format_single_value(req, val) for val in value] |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
156 |
return self.format_single_value(req, value) |
1437 | 157 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
158 |
def format_single_value(self, req, value): |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
159 |
"""return value suitable for display""" |
1306 | 160 |
if value is None or value is False: |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
161 |
return u'' |
1306 | 162 |
if value is True: |
163 |
return u'1' |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
164 |
return unicode(value) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
165 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
166 |
def get_widget(self, form): |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
167 |
"""return the widget instance associated to this field""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
168 |
return self.widget |
1437 | 169 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
170 |
def example_format(self, req): |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
171 |
"""return a sample string describing what can be given as input for this |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
172 |
field |
1437 | 173 |
""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
174 |
return u'' |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
175 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
176 |
def render(self, form, renderer): |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
177 |
"""render this field, which is part of form, using the given form |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
178 |
renderer |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
179 |
""" |
2522
562f5dcf2345
widget.render now takes the renderer as third argument (keeping minimal bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2520
diff
changeset
|
180 |
widget = self.get_widget(form) |
562f5dcf2345
widget.render now takes the renderer as third argument (keeping minimal bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2520
diff
changeset
|
181 |
try: |
562f5dcf2345
widget.render now takes the renderer as third argument (keeping minimal bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2520
diff
changeset
|
182 |
return widget.render(form, self, renderer) |
562f5dcf2345
widget.render now takes the renderer as third argument (keeping minimal bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2520
diff
changeset
|
183 |
except TypeError: |
3533
88ceed15a3d3
nicer deprecation messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3510
diff
changeset
|
184 |
warn('[3.3] %s: widget.render now take the renderer as third argument, ' |
88ceed15a3d3
nicer deprecation messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3510
diff
changeset
|
185 |
'please update implementation' % widget, DeprecationWarning) |
2522
562f5dcf2345
widget.render now takes the renderer as third argument (keeping minimal bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2520
diff
changeset
|
186 |
return widget.render(form, self) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
187 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
188 |
def vocabulary(self, form): |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
189 |
"""return vocabulary for this field. This method will be called by |
1437 | 190 |
widgets which desire it.""" |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
191 |
if self.choices is not None: |
1181
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
1147
diff
changeset
|
192 |
if callable(self.choices): |
2196
b08521e4eaab
vocabulary method (eg field.choices) should now take the form instance as argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2146
diff
changeset
|
193 |
try: |
b08521e4eaab
vocabulary method (eg field.choices) should now take the form instance as argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2146
diff
changeset
|
194 |
vocab = self.choices(form=form) |
b08521e4eaab
vocabulary method (eg field.choices) should now take the form instance as argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2146
diff
changeset
|
195 |
except TypeError: |
3533
88ceed15a3d3
nicer deprecation messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3510
diff
changeset
|
196 |
warn('[3.3] vocabulary method (eg field.choices) should now take ' |
2196
b08521e4eaab
vocabulary method (eg field.choices) should now take the form instance as argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2146
diff
changeset
|
197 |
'the form instance as argument', DeprecationWarning) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3388
diff
changeset
|
198 |
vocab = self.choices(req=form._cw) |
1181
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
1147
diff
changeset
|
199 |
else: |
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
1147
diff
changeset
|
200 |
vocab = self.choices |
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
1147
diff
changeset
|
201 |
if vocab and not isinstance(vocab[0], (list, tuple)): |
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
1147
diff
changeset
|
202 |
vocab = [(x, x) for x in vocab] |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
203 |
else: |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
204 |
vocab = form.form_field_vocabulary(self) |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
205 |
if self.internationalizable: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3388
diff
changeset
|
206 |
vocab = [(form._cw._(label), value) for label, value in vocab] |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
207 |
if self.sort: |
3334
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
208 |
vocab = vocab_sort(vocab) |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
209 |
return vocab |
1437 | 210 |
|
1307 | 211 |
def form_init(self, form): |
3510
bf746bf4a394
rename form_build_context to build_context, and call it from form, not renderer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3496
diff
changeset
|
212 |
"""method called before by build_context to trigger potential field |
1307 | 213 |
initialization requiring the form instance |
214 |
""" |
|
215 |
pass |
|
1437 | 216 |
|
3387
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
217 |
def process_form_value(self, form): |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
218 |
"""process posted form and return correctly typed value""" |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
219 |
widget = self.get_widget(form) |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
220 |
return widget.process_field_data(form, self) |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
221 |
|
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
222 |
def process_posted(self, form): |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
223 |
for field in self.actual_fields(form): |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
224 |
if field is self: |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
225 |
yield field.name, field.process_form_value(form) |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
226 |
else: |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
227 |
# recursive function: we might have compound fields |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
228 |
# of compound fields (of compound fields of ...) |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
229 |
for fieldname, value in field.process_posted(form): |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
230 |
yield fieldname, value |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
231 |
|
1986
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
232 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
233 |
class StringField(Field): |
1986
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
234 |
widget = TextArea |
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
235 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
236 |
def __init__(self, max_length=None, **kwargs): |
1986
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
237 |
self.max_length = max_length # must be set before super call |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
238 |
super(StringField, self).__init__(**kwargs) |
1986
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
239 |
|
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
240 |
def init_widget(self, widget): |
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
241 |
if widget is None: |
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
242 |
if self.choices: |
1988
b5c5c088bb03
if choices is set and widget not explicitly specified, use Select in base field
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1986
diff
changeset
|
243 |
widget = Select() |
1986
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
244 |
elif self.max_length and self.max_length < 257: |
1988
b5c5c088bb03
if choices is set and widget not explicitly specified, use Select in base field
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1986
diff
changeset
|
245 |
widget = TextInput() |
2344
22b5ea0679ed
[formfields] set a reasonable minimal minimum length to input/text, also set the max length if applicable (closes #344538)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2332
diff
changeset
|
246 |
|
1986
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
247 |
super(StringField, self).init_widget(widget) |
1573
d34589d35daa
drop TextField, this is simply a StringField with a text area widget
sylvain.thenault@logilab.fr
parents:
1564
diff
changeset
|
248 |
if isinstance(self.widget, TextArea): |
d34589d35daa
drop TextField, this is simply a StringField with a text area widget
sylvain.thenault@logilab.fr
parents:
1564
diff
changeset
|
249 |
self.init_text_area(self.widget) |
2362 | 250 |
elif isinstance(self.widget, TextInput): |
2360
1d43aa551ba9
[formwidgets,formfields] hum, this way
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2356
diff
changeset
|
251 |
self.init_text_input(self.widget) |
1d43aa551ba9
[formwidgets,formfields] hum, this way
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2356
diff
changeset
|
252 |
|
1d43aa551ba9
[formwidgets,formfields] hum, this way
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2356
diff
changeset
|
253 |
def init_text_input(self, widget): |
1d43aa551ba9
[formwidgets,formfields] hum, this way
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2356
diff
changeset
|
254 |
if self.max_length: |
1d43aa551ba9
[formwidgets,formfields] hum, this way
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2356
diff
changeset
|
255 |
widget.attrs.setdefault('size', min(45, self.max_length)) |
1d43aa551ba9
[formwidgets,formfields] hum, this way
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2356
diff
changeset
|
256 |
widget.attrs.setdefault('maxlength', self.max_length) |
1573
d34589d35daa
drop TextField, this is simply a StringField with a text area widget
sylvain.thenault@logilab.fr
parents:
1564
diff
changeset
|
257 |
|
d34589d35daa
drop TextField, this is simply a StringField with a text area widget
sylvain.thenault@logilab.fr
parents:
1564
diff
changeset
|
258 |
def init_text_area(self, widget): |
d34589d35daa
drop TextField, this is simply a StringField with a text area widget
sylvain.thenault@logilab.fr
parents:
1564
diff
changeset
|
259 |
if self.max_length < 513: |
d34589d35daa
drop TextField, this is simply a StringField with a text area widget
sylvain.thenault@logilab.fr
parents:
1564
diff
changeset
|
260 |
widget.attrs.setdefault('cols', 60) |
d34589d35daa
drop TextField, this is simply a StringField with a text area widget
sylvain.thenault@logilab.fr
parents:
1564
diff
changeset
|
261 |
widget.attrs.setdefault('rows', 5) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
262 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
263 |
|
1573
d34589d35daa
drop TextField, this is simply a StringField with a text area widget
sylvain.thenault@logilab.fr
parents:
1564
diff
changeset
|
264 |
class RichTextField(StringField): |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
265 |
widget = None |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
266 |
def __init__(self, format_field=None, **kwargs): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
267 |
super(RichTextField, self).__init__(**kwargs) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
268 |
self.format_field = format_field |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
269 |
|
2348
acf4b6a59558
[formwidgets] ensure textarea for richstring has not ridicuously small size (close #344547)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2347
diff
changeset
|
270 |
def init_text_area(self, widget): |
acf4b6a59558
[formwidgets] ensure textarea for richstring has not ridicuously small size (close #344547)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2347
diff
changeset
|
271 |
pass |
acf4b6a59558
[formwidgets] ensure textarea for richstring has not ridicuously small size (close #344547)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2347
diff
changeset
|
272 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
273 |
def get_widget(self, form): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
274 |
if self.widget is None: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
275 |
if self.use_fckeditor(form): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
276 |
return FCKEditor() |
1573
d34589d35daa
drop TextField, this is simply a StringField with a text area widget
sylvain.thenault@logilab.fr
parents:
1564
diff
changeset
|
277 |
widget = TextArea() |
d34589d35daa
drop TextField, this is simply a StringField with a text area widget
sylvain.thenault@logilab.fr
parents:
1564
diff
changeset
|
278 |
self.init_text_area(widget) |
d34589d35daa
drop TextField, this is simply a StringField with a text area widget
sylvain.thenault@logilab.fr
parents:
1564
diff
changeset
|
279 |
return widget |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
280 |
return self.widget |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
281 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
282 |
def get_format_field(self, form): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
283 |
if self.format_field: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
284 |
return self.format_field |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
285 |
# we have to cache generated field since it's use as key in the |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
286 |
# context dictionnary |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3388
diff
changeset
|
287 |
req = form._cw |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
288 |
try: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
289 |
return req.data[self] |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
290 |
except KeyError: |
2724
7966d87202d7
format field should inherit from parent field's eidparam
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2723
diff
changeset
|
291 |
fkwargs = {'eidparam': self.eidparam} |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
292 |
if self.use_fckeditor(form): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
293 |
# if fckeditor is used and format field isn't explicitly |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
294 |
# deactivated, we want an hidden field for the format |
1858
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
295 |
fkwargs['widget'] = HiddenInput() |
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
296 |
fkwargs['initial'] = 'text/html' |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
297 |
else: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
298 |
# else we want a format selector |
1858
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
299 |
fkwargs['widget'] = Select() |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
300 |
fcstr = FormatConstraint() |
3347
428f95118556
fix vocab param to avoid deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3337
diff
changeset
|
301 |
fkwargs['choices'] = fcstr.vocabulary(form=form) |
1858
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
302 |
fkwargs['internationalizable'] = True |
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
303 |
fkwargs['initial'] = lambda f: f.form_field_format(self) |
3385
68953ecddd2b
[forms] work-in-progress: let guess_field and RichTextField.get_format_field handle eidparam of meta fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3384
diff
changeset
|
304 |
fkwargs['eidparam'] = self.eidparam |
1858
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
305 |
field = StringField(name=self.name + '_format', **fkwargs) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
306 |
req.data[self] = field |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
307 |
return field |
1437 | 308 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
309 |
def actual_fields(self, form): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
310 |
yield self |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
311 |
format_field = self.get_format_field(form) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
312 |
if format_field: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
313 |
yield format_field |
1437 | 314 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
315 |
def use_fckeditor(self, form): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
316 |
"""return True if fckeditor should be used to edit entity's attribute named |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
317 |
`attr`, according to user preferences |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
318 |
""" |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3388
diff
changeset
|
319 |
if form._cw.use_fckeditor(): |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
320 |
return form.form_field_format(self) == 'text/html' |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
321 |
return False |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
322 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
323 |
def render(self, form, renderer): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
324 |
format_field = self.get_format_field(form) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
325 |
if format_field: |
1793
fdac26e003e7
fix vertical alignment pb. with descr. format list and textarea inputs
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1758
diff
changeset
|
326 |
# XXX we want both fields to remain vertically aligned |
2723
d38c2b01d766
don't set display: block on hidden input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2362
diff
changeset
|
327 |
if format_field.is_visible(): |
d38c2b01d766
don't set display: block on hidden input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2362
diff
changeset
|
328 |
format_field.widget.attrs['style'] = 'display: block' |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
329 |
result = format_field.render(form, renderer) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
330 |
else: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
331 |
result = u'' |
2522
562f5dcf2345
widget.render now takes the renderer as third argument (keeping minimal bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2520
diff
changeset
|
332 |
return result + self.get_widget(form).render(form, self, renderer) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
333 |
|
1417 | 334 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
335 |
class FileField(StringField): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
336 |
widget = FileInput |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
337 |
needs_multipart = True |
1437 | 338 |
|
3496
35a67ac6efe8
support name metadata on guess_field; add name_field to FileField
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3347
diff
changeset
|
339 |
def __init__(self, format_field=None, encoding_field=None, name_field=None, |
35a67ac6efe8
support name metadata on guess_field; add name_field to FileField
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3347
diff
changeset
|
340 |
**kwargs): |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
341 |
super(FileField, self).__init__(**kwargs) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
342 |
self.format_field = format_field |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
343 |
self.encoding_field = encoding_field |
3496
35a67ac6efe8
support name metadata on guess_field; add name_field to FileField
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3347
diff
changeset
|
344 |
self.name_field = name_field |
1437 | 345 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
346 |
def actual_fields(self, form): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
347 |
yield self |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
348 |
if self.format_field: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
349 |
yield self.format_field |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
350 |
if self.encoding_field: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
351 |
yield self.encoding_field |
3496
35a67ac6efe8
support name metadata on guess_field; add name_field to FileField
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3347
diff
changeset
|
352 |
if self.name_field: |
35a67ac6efe8
support name metadata on guess_field; add name_field to FileField
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3347
diff
changeset
|
353 |
yield self.name_field |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
354 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
355 |
def render(self, form, renderer): |
2522
562f5dcf2345
widget.render now takes the renderer as third argument (keeping minimal bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2520
diff
changeset
|
356 |
wdgs = [self.get_widget(form).render(form, self, renderer)] |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
357 |
if self.format_field or self.encoding_field: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
358 |
divid = '%s-advanced' % form.context[self]['name'] |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
359 |
wdgs.append(u'<a href="%s" title="%s"><img src="%s" alt="%s"/></a>' % |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2244
diff
changeset
|
360 |
(xml_escape(uilib.toggle_action(divid)), |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3388
diff
changeset
|
361 |
form._cw._('show advanced fields'), |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3388
diff
changeset
|
362 |
xml_escape(form._cw.build_url('data/puce_down.png')), |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3388
diff
changeset
|
363 |
form._cw._('show advanced fields'))) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
364 |
wdgs.append(u'<div id="%s" class="hidden">' % divid) |
3496
35a67ac6efe8
support name metadata on guess_field; add name_field to FileField
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3347
diff
changeset
|
365 |
if self.name_field: |
35a67ac6efe8
support name metadata on guess_field; add name_field to FileField
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3347
diff
changeset
|
366 |
wdgs.append(self.render_subfield(form, self.name_field, renderer)) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
367 |
if self.format_field: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
368 |
wdgs.append(self.render_subfield(form, self.format_field, renderer)) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
369 |
if self.encoding_field: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
370 |
wdgs.append(self.render_subfield(form, self.encoding_field, renderer)) |
1437 | 371 |
wdgs.append(u'</div>') |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
372 |
if not self.required and form.context[self]['value']: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
373 |
# trick to be able to delete an uploaded file |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
374 |
wdgs.append(u'<br/>') |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
375 |
wdgs.append(tags.input(name=u'%s__detach' % form.context[self]['name'], |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
376 |
type=u'checkbox')) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3388
diff
changeset
|
377 |
wdgs.append(form._cw._('detach attached file')) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
378 |
return u'\n'.join(wdgs) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
379 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
380 |
def render_subfield(self, form, field, renderer): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
381 |
return (renderer.render_label(form, field) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
382 |
+ field.render(form, renderer) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
383 |
+ renderer.render_help(form, field) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
384 |
+ u'<br/>') |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
385 |
|
3387
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
386 |
def process_form_value(self, form): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3388
diff
changeset
|
387 |
posted = form._cw.form |
3387
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
388 |
value = posted.get(form.form_field_name(self)) |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
389 |
formkey = form.form_field_name(self) |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
390 |
if ('%s__detach' % form.context[self]['name']) in posted: |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
391 |
# drop current file value |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
392 |
value = None |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
393 |
# no need to check value when nor explicit detach nor new file |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
394 |
# submitted, since it will think the attribute is not modified |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
395 |
elif value: |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
396 |
filename, _, stream = value |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
397 |
# value is a 3-uple (filename, mimetype, stream) |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
398 |
value = Binary(stream.read()) |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
399 |
if not val.getvalue(): # usually an unexistant file |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
400 |
value = None |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
401 |
else: |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
402 |
value.filename = filename |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
403 |
return value |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
404 |
|
1437 | 405 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
406 |
class EditableFileField(FileField): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
407 |
editable_formats = ('text/plain', 'text/html', 'text/rest') |
1437 | 408 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
409 |
def render(self, form, renderer): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
410 |
wdgs = [super(EditableFileField, self).render(form, renderer)] |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
411 |
if form.form_field_format(self) in self.editable_formats: |
1392
d6279efff7b3
refactor the way field value/display value are handled to avoid getting a 'display' value when expected a 'typed' value
sylvain.thenault@logilab.fr
parents:
1307
diff
changeset
|
412 |
data = form.form_field_value(self, load_bytes=True) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
413 |
if data: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
414 |
encoding = form.form_field_encoding(self) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
415 |
try: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
416 |
form.context[self]['value'] = unicode(data.getvalue(), encoding) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
417 |
except UnicodeError: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
418 |
pass |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
419 |
else: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
420 |
if not self.required: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3388
diff
changeset
|
421 |
msg = form._cw._( |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
422 |
'You can either submit a new file using the browse button above' |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
423 |
', or choose to remove already uploaded file by checking the ' |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
424 |
'"detach attached file" check-box, or edit file content online ' |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
425 |
'with the widget below.') |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
426 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3388
diff
changeset
|
427 |
msg = form._cw._( |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
428 |
'You can either submit a new file using the browse button above' |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
429 |
', or edit file content online with the widget below.') |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
430 |
wdgs.append(u'<p><b>%s</b></p>' % msg) |
2522
562f5dcf2345
widget.render now takes the renderer as third argument (keeping minimal bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2520
diff
changeset
|
431 |
wdgs.append(TextArea(setdomid=False).render(form, self, renderer)) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
432 |
# XXX restore form context? |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
433 |
return '\n'.join(wdgs) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
434 |
|
3387
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
435 |
def process_form_value(self, form): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3388
diff
changeset
|
436 |
value = form._cw.form.get(form.form_field_name(self)) |
3387
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
437 |
if isinstance(value, unicode): |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
438 |
# file modified using a text widget |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
439 |
encoding = form.form_field_encoding(self) |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
440 |
return Binary(value.encode(encoding)) |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
441 |
return super(EditableFileField, self).process_form_value(form) |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
442 |
|
1437 | 443 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
444 |
class IntField(Field): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
445 |
def __init__(self, min=None, max=None, **kwargs): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
446 |
super(IntField, self).__init__(**kwargs) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
447 |
self.min = min |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
448 |
self.max = max |
1758 | 449 |
if isinstance(self.widget, TextInput): |
450 |
self.widget.attrs.setdefault('size', 5) |
|
451 |
self.widget.attrs.setdefault('maxlength', 15) |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
452 |
|
3387
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
453 |
def process_form_value(self, form): |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
454 |
return int(Field.process_form_value(self, form)) |
1986
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
455 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
456 |
class BooleanField(Field): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
457 |
widget = Radio |
1437 | 458 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
459 |
def vocabulary(self, form): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
460 |
if self.choices: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
461 |
return self.choices |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3388
diff
changeset
|
462 |
return [(form._cw._('yes'), '1'), (form._cw._('no'), '')] |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
463 |
|
3387
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
464 |
def process_form_value(self, form): |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
465 |
return bool(Field.process_form_value(self, form)) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
466 |
|
1437 | 467 |
class FloatField(IntField): |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
468 |
def format_single_value(self, req, value): |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
469 |
formatstr = req.property_value('ui.float-format') |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
470 |
if value is None: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
471 |
return u'' |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
472 |
return formatstr % float(value) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
473 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
474 |
def render_example(self, req): |
2086
be76ce00a05e
fix TimeField format_prop, use format_single_value directly in render_example
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1989
diff
changeset
|
475 |
return self.format_single_value(req, 1.234) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
476 |
|
3387
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
477 |
def process_form_value(self, form): |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
478 |
return float(Field.process_form_value(self, form)) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
479 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
480 |
class DateField(StringField): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
481 |
format_prop = 'ui.date-format' |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
482 |
widget = DateTimePicker |
1437 | 483 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
484 |
def format_single_value(self, req, value): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
485 |
return value and ustrftime(value, req.property_value(self.format_prop)) or u'' |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
486 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
487 |
def render_example(self, req): |
2086
be76ce00a05e
fix TimeField format_prop, use format_single_value directly in render_example
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1989
diff
changeset
|
488 |
return self.format_single_value(req, datetime.now()) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
489 |
|
3387
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
490 |
def process_form_value(self, form): |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
491 |
# widget is supposed to return a date as a correctly formatted string |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
492 |
date = Field.process_form_value(self, form) |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
493 |
# but for some widgets, it might be simpler to return date objects |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
494 |
# directly, so handle that case : |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
495 |
if isinstance(date, basestring): |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
496 |
date = form.parse_date(wdgdate, 'Date') |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
497 |
return date |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
498 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
499 |
class DateTimeField(DateField): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
500 |
format_prop = 'ui.datetime-format' |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
501 |
|
3387
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
502 |
def process_form_value(self, form): |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
503 |
# widget is supposed to return a date as a correctly formatted string |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
504 |
date = Field.process_form_value(self, form) |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
505 |
# but for some widgets, it might be simpler to return date objects |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
506 |
# directly, so handle that case : |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
507 |
if isinstance(date, basestring): |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
508 |
date = form.parse_datetime(wdgdate, 'Datetime') |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
509 |
return date |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
510 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
511 |
class TimeField(DateField): |
2086
be76ce00a05e
fix TimeField format_prop, use format_single_value directly in render_example
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1989
diff
changeset
|
512 |
format_prop = 'ui.time-format' |
1758 | 513 |
widget = TextInput |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
514 |
|
3387
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
515 |
def process_form_value(self, form): |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
516 |
# widget is supposed to return a date as a correctly formatted string |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
517 |
time = Field.process_form_value(self, form) |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
518 |
# but for some widgets, it might be simpler to return time objects |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
519 |
# directly, so handle that case : |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
520 |
if isinstance(time, basestring): |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
521 |
time = form.parse_time(wdgdate, 'Time') |
a357d4147eee
[forms] work-in-progress, big editcontroller refactoring: let fields/widgets process posted data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3385
diff
changeset
|
522 |
return time |
1437 | 523 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
524 |
class RelationField(Field): |
3246
9e4adca73a95
stop setting sort to false by default on relation field and explain why
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2726
diff
changeset
|
525 |
# XXX (syt): iirc, we originaly don't sort relation vocabulary since we want |
9e4adca73a95
stop setting sort to false by default on relation field and explain why
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2726
diff
changeset
|
526 |
# to let entity.unrelated_rql control this, usually to get most recently |
9e4adca73a95
stop setting sort to false by default on relation field and explain why
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2726
diff
changeset
|
527 |
# modified entities in the select box instead of by alphabetical order. Now, |
9e4adca73a95
stop setting sort to false by default on relation field and explain why
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2726
diff
changeset
|
528 |
# we first use unrelated_rql to get the vocabulary, which may be limited |
9e4adca73a95
stop setting sort to false by default on relation field and explain why
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2726
diff
changeset
|
529 |
# (hence we get the latest modified entities) and we can sort here for |
9e4adca73a95
stop setting sort to false by default on relation field and explain why
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2726
diff
changeset
|
530 |
# better readability |
9e4adca73a95
stop setting sort to false by default on relation field and explain why
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2726
diff
changeset
|
531 |
# |
9e4adca73a95
stop setting sort to false by default on relation field and explain why
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2726
diff
changeset
|
532 |
# def __init__(self, **kwargs): |
9e4adca73a95
stop setting sort to false by default on relation field and explain why
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2726
diff
changeset
|
533 |
# kwargs.setdefault('sort', False) |
9e4adca73a95
stop setting sort to false by default on relation field and explain why
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2726
diff
changeset
|
534 |
# super(RelationField, self).__init__(**kwargs) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
535 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
536 |
@staticmethod |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
537 |
def fromcardinality(card, **kwargs): |
1738
2cfd50c8a415
should not override potential explicit widget
sylvain.thenault@logilab.fr
parents:
1709
diff
changeset
|
538 |
kwargs.setdefault('widget', Select(multiple=card in '*+')) |
2cfd50c8a415
should not override potential explicit widget
sylvain.thenault@logilab.fr
parents:
1709
diff
changeset
|
539 |
return RelationField(**kwargs) |
1437 | 540 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
541 |
def vocabulary(self, form): |
1147 | 542 |
entity = form.edited_entity |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3388
diff
changeset
|
543 |
req = entity._cw |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
544 |
# first see if its specified by __linkto form parameters |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
545 |
linkedto = entity.linked_to(self.name, self.role) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
546 |
if linkedto: |
2680
66472d85d548
[R] use req.entity_from_eid
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2678
diff
changeset
|
547 |
entities = (req.entity_from_eid(eid) for eid in linkedto) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
548 |
return [(entity.view('combobox'), entity.eid) for entity in entities] |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
549 |
# it isn't, check if the entity provides a method to get correct values |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
550 |
res = [] |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
551 |
if not self.required: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
552 |
res.append(('', INTERNAL_FIELD_VALUE)) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
553 |
# vocabulary doesn't include current values, add them |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
554 |
if entity.has_eid(): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
555 |
rset = entity.related(self.name, self.role) |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
556 |
relatedvocab = [(e.view('combobox'), e.eid) for e in rset.entities()] |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
557 |
else: |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
558 |
relatedvocab = [] |
1562
e6d2c07c0c58
[forms/widgets] fix relation field not sorting its vocabulary, revert hack on Select widget
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1505
diff
changeset
|
559 |
vocab = res + form.form_field_vocabulary(self) + relatedvocab |
e6d2c07c0c58
[forms/widgets] fix relation field not sorting its vocabulary, revert hack on Select widget
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1505
diff
changeset
|
560 |
if self.sort: |
3334
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3308
diff
changeset
|
561 |
vocab = vocab_sort(vocab) |
1562
e6d2c07c0c58
[forms/widgets] fix relation field not sorting its vocabulary, revert hack on Select widget
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1505
diff
changeset
|
562 |
return vocab |
1437 | 563 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
564 |
def format_single_value(self, req, value): |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
565 |
return value |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
566 |
|
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
567 |
|
2523
1d245fbbeb90
some new field/widgets classes: CompoundField, IntervalWidget, HorizontalLayoutWidget
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2522
diff
changeset
|
568 |
class CompoundField(Field): |
1d245fbbeb90
some new field/widgets classes: CompoundField, IntervalWidget, HorizontalLayoutWidget
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2522
diff
changeset
|
569 |
def __init__(self, fields, *args, **kwargs): |
1d245fbbeb90
some new field/widgets classes: CompoundField, IntervalWidget, HorizontalLayoutWidget
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2522
diff
changeset
|
570 |
super(CompoundField, self).__init__(*args, **kwargs) |
1d245fbbeb90
some new field/widgets classes: CompoundField, IntervalWidget, HorizontalLayoutWidget
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2522
diff
changeset
|
571 |
self.fields = fields |
1d245fbbeb90
some new field/widgets classes: CompoundField, IntervalWidget, HorizontalLayoutWidget
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2522
diff
changeset
|
572 |
|
2549
3d8c62e5e2d4
[R forms] use a subfields(form) method to get a chance to adapt to context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2523
diff
changeset
|
573 |
def subfields(self, form): |
3d8c62e5e2d4
[R forms] use a subfields(form) method to get a chance to adapt to context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2523
diff
changeset
|
574 |
return self.fields |
2568 | 575 |
|
2523
1d245fbbeb90
some new field/widgets classes: CompoundField, IntervalWidget, HorizontalLayoutWidget
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2522
diff
changeset
|
576 |
def actual_fields(self, form): |
1d245fbbeb90
some new field/widgets classes: CompoundField, IntervalWidget, HorizontalLayoutWidget
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2522
diff
changeset
|
577 |
return [self] + list(self.fields) |
1d245fbbeb90
some new field/widgets classes: CompoundField, IntervalWidget, HorizontalLayoutWidget
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2522
diff
changeset
|
578 |
|
1d245fbbeb90
some new field/widgets classes: CompoundField, IntervalWidget, HorizontalLayoutWidget
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2522
diff
changeset
|
579 |
|
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1437
diff
changeset
|
580 |
def guess_field(eschema, rschema, role='subject', skip_meta_attr=True, **kwargs): |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
581 |
"""return the most adapated widget to edit the relation |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
582 |
'subjschema rschema objschema' according to information found in the schema |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
583 |
""" |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
584 |
fieldclass = None |
2678
0308dc159b96
use yams api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2568
diff
changeset
|
585 |
card = eschema.cardinality(rschema, role) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
586 |
if role == 'subject': |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
587 |
targetschema = rschema.objects(eschema)[0] |
1268
5db94912650b
get field's help in guess_field
sylvain.thenault@logilab.fr
parents:
1265
diff
changeset
|
588 |
help = rschema.rproperty(eschema, targetschema, 'description') |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3575
diff
changeset
|
589 |
if rschema.final: |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
590 |
if rschema.rproperty(eschema, targetschema, 'internationalizable'): |
2095
897732d3ee5a
avoid overriding specified values when guessing field
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
591 |
kwargs.setdefault('internationalizable', True) |
1709
f7110f533d14
use yams.schema method for initial value
sylvain.thenault@logilab.fr
parents:
1706
diff
changeset
|
592 |
def get_default(form, es=eschema, rs=rschema): |
f7110f533d14
use yams.schema method for initial value
sylvain.thenault@logilab.fr
parents:
1706
diff
changeset
|
593 |
return es.default(rs) |
2095
897732d3ee5a
avoid overriding specified values when guessing field
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
594 |
kwargs.setdefault('initial', get_default) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
595 |
else: |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
596 |
targetschema = rschema.subjects(eschema)[0] |
1268
5db94912650b
get field's help in guess_field
sylvain.thenault@logilab.fr
parents:
1265
diff
changeset
|
597 |
help = rschema.rproperty(targetschema, eschema, 'description') |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
598 |
kwargs['required'] = card in '1+' |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
599 |
kwargs['name'] = rschema.type |
3308
88f5f89d8d1b
fix generated label for object relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3299
diff
changeset
|
600 |
if role == 'object': |
3574
f179ccbd13e6
[forms] fix generated label for fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3563
diff
changeset
|
601 |
kwargs.setdefault('label', (eschema.type, rschema.type + '_object')) |
3308
88f5f89d8d1b
fix generated label for object relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3299
diff
changeset
|
602 |
else: |
3574
f179ccbd13e6
[forms] fix generated label for fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3563
diff
changeset
|
603 |
kwargs.setdefault('label', (eschema.type, rschema.type)) |
3385
68953ecddd2b
[forms] work-in-progress: let guess_field and RichTextField.get_format_field handle eidparam of meta fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3384
diff
changeset
|
604 |
kwargs['eidparam'] = True |
2095
897732d3ee5a
avoid overriding specified values when guessing field
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
605 |
kwargs.setdefault('help', help) |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3575
diff
changeset
|
606 |
if rschema.final: |
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1101
diff
changeset
|
607 |
if skip_meta_attr and rschema in eschema.meta_attributes(): |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
608 |
return None |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
609 |
fieldclass = FIELDS[targetschema] |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
610 |
if fieldclass is StringField: |
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1101
diff
changeset
|
611 |
if targetschema == 'Password': |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1101
diff
changeset
|
612 |
# special case for Password field: specific PasswordInput widget |
1147 | 613 |
kwargs.setdefault('widget', PasswordInput()) |
614 |
return StringField(**kwargs) |
|
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1101
diff
changeset
|
615 |
if eschema.has_metadata(rschema, 'format'): |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1101
diff
changeset
|
616 |
# use RichTextField instead of StringField if the attribute has |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1101
diff
changeset
|
617 |
# a "format" metadata. But getting information from constraints |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1101
diff
changeset
|
618 |
# may be useful anyway... |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1101
diff
changeset
|
619 |
constraints = rschema.rproperty(eschema, targetschema, 'constraints') |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1101
diff
changeset
|
620 |
for cstr in constraints: |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1101
diff
changeset
|
621 |
if isinstance(cstr, StaticVocabularyConstraint): |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1101
diff
changeset
|
622 |
raise Exception('rich text field with static vocabulary') |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1101
diff
changeset
|
623 |
return RichTextField(**kwargs) |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
624 |
constraints = rschema.rproperty(eschema, targetschema, 'constraints') |
1574 | 625 |
# init StringField parameters according to constraints |
626 |
for cstr in constraints: |
|
627 |
if isinstance(cstr, StaticVocabularyConstraint): |
|
1577 | 628 |
kwargs.setdefault('choices', cstr.vocabulary) |
1986
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
629 |
break |
1836
d3f0c6e868ef
fix StringField widget selection with SizeConstraint and StaticVocabularyConstraint constraints
Florent <florent@secondweb.fr>
parents:
1803
diff
changeset
|
630 |
for cstr in constraints: |
1574 | 631 |
if isinstance(cstr, SizeConstraint) and cstr.max is not None: |
632 |
kwargs['max_length'] = cstr.max |
|
633 |
return StringField(**kwargs) |
|
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1101
diff
changeset
|
634 |
if fieldclass is FileField: |
3496
35a67ac6efe8
support name metadata on guess_field; add name_field to FileField
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3347
diff
changeset
|
635 |
for metadata in ('format', 'encoding', 'name'): |
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1101
diff
changeset
|
636 |
metaschema = eschema.has_metadata(rschema, metadata) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1101
diff
changeset
|
637 |
if metaschema is not None: |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1437
diff
changeset
|
638 |
kwargs['%s_field' % metadata] = guess_field(eschema, metaschema, |
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1101
diff
changeset
|
639 |
skip_meta_attr=False) |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
640 |
return fieldclass(**kwargs) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
641 |
kwargs['role'] = role |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
1081
diff
changeset
|
642 |
return RelationField.fromcardinality(card, **kwargs) |
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
643 |
|
1986
96c0e56cb0cf
move widget selection's logic on fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
644 |
|
1081
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
645 |
FIELDS = { |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
646 |
'Boolean': BooleanField, |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
647 |
'Bytes': FileField, |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
648 |
'Date': DateField, |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
649 |
'Datetime': DateTimeField, |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
650 |
'Int': IntField, |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
651 |
'Float': FloatField, |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
652 |
'Decimal': StringField, |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
653 |
'Password': StringField, |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
654 |
'String' : StringField, |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
655 |
'Time': TimeField, |
f2a85f52b9e5
move fields and widgets to their own module
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
656 |
} |