author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Fri, 20 Feb 2009 16:01:33 +0100 | |
branch | tls-sprint |
changeset 901 | 0dcf01eb97a0 |
parent 900 | 8f95ebbe2fd8 |
child 902 | e4de959c76af |
permissions | -rw-r--r-- |
0 | 1 |
"""abstract form classes for CubicWeb web client |
2 |
||
3 |
:organization: Logilab |
|
751 | 4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 |
""" |
|
7 |
__docformat__ = "restructuredtext en" |
|
8 |
||
848
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
9 |
from warnings import warn |
0 | 10 |
from simplejson import dumps |
867
14a79faa3a56
fix implementation errors import DateTimePicker
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
865
diff
changeset
|
11 |
from mx.DateTime import today |
0 | 12 |
|
844 | 13 |
from logilab.common.compat import any |
0 | 14 |
from logilab.mtconverter import html_escape |
15 |
||
897
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
16 |
from yams.constraints import SizeConstraint, StaticVocabularyConstraint |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
17 |
|
0 | 18 |
from cubicweb import typed_eid |
867
14a79faa3a56
fix implementation errors import DateTimePicker
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
865
diff
changeset
|
19 |
from cubicweb.utils import ustrftime |
692
800592b8d39b
replace deprecated cubicweb.common.selectors by its new module path (cubicweb.selectors)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
431
diff
changeset
|
20 |
from cubicweb.selectors import match_form_params |
751 | 21 |
from cubicweb.view import NOINDEX, NOFOLLOW, View, EntityView, AnyRsetView |
0 | 22 |
from cubicweb.common.registerers import accepts_registerer |
23 |
from cubicweb.web import stdmsgs |
|
24 |
from cubicweb.web.httpcache import NoHTTPCacheManager |
|
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
25 |
from cubicweb.web.controller import NAV_FORM_PARAMETERS, redirect_params |
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
26 |
from cubicweb.web import INTERNAL_FIELD_VALUE, eid_param |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
27 |
|
0 | 28 |
|
29 |
def relation_id(eid, rtype, target, reid): |
|
30 |
if target == 'subject': |
|
31 |
return u'%s:%s:%s' % (eid, rtype, reid) |
|
32 |
return u'%s:%s:%s' % (reid, rtype, eid) |
|
844 | 33 |
|
34 |
def toggable_relation_link(eid, nodeid, label='x'): |
|
35 |
js = u"javascript: togglePendingDelete('%s', %s);" % (nodeid, html_escape(dumps(eid))) |
|
36 |
return u'[<a class="handle" href="%s" id="handle%s">%s</a>]' % (js, nodeid, label) |
|
0 | 37 |
|
38 |
||
39 |
class FormMixIn(object): |
|
40 |
"""abstract form mix-in""" |
|
41 |
category = 'form' |
|
42 |
controller = 'edit' |
|
43 |
domid = 'entityForm' |
|
44 |
||
45 |
http_cache_manager = NoHTTPCacheManager |
|
46 |
add_to_breadcrumbs = False |
|
47 |
skip_relations = set() |
|
48 |
||
49 |
def __init__(self, req, rset): |
|
50 |
super(FormMixIn, self).__init__(req, rset) |
|
51 |
self.maxrelitems = self.req.property_value('navigation.related-limit') |
|
52 |
self.maxcomboitems = self.req.property_value('navigation.combobox-limit') |
|
53 |
self.force_display = not not req.form.get('__force_display') |
|
54 |
# get validation session data which may have been previously set. |
|
55 |
# deleting validation errors here breaks form reloading (errors are |
|
56 |
# no more available), they have to be deleted by application's publish |
|
57 |
# method on successful commit |
|
58 |
formurl = req.url() |
|
59 |
forminfo = req.get_session_data(formurl) |
|
60 |
if forminfo: |
|
61 |
req.data['formvalues'] = forminfo['values'] |
|
62 |
req.data['formerrors'] = errex = forminfo['errors'] |
|
63 |
req.data['displayederrors'] = set() |
|
64 |
# if some validation error occured on entity creation, we have to |
|
65 |
# get the original variable name from its attributed eid |
|
66 |
foreid = errex.entity |
|
67 |
for var, eid in forminfo['eidmap'].items(): |
|
68 |
if foreid == eid: |
|
69 |
errex.eid = var |
|
70 |
break |
|
71 |
else: |
|
72 |
errex.eid = foreid |
|
73 |
||
74 |
def html_headers(self): |
|
75 |
"""return a list of html headers (eg something to be inserted between |
|
76 |
<head> and </head> of the returned page |
|
77 |
||
78 |
by default forms are neither indexed nor followed |
|
79 |
""" |
|
80 |
return [NOINDEX, NOFOLLOW] |
|
81 |
||
82 |
def linkable(self): |
|
83 |
"""override since forms are usually linked by an action, |
|
84 |
so we don't want them to be listed by appli.possible_views |
|
85 |
""" |
|
86 |
return False |
|
87 |
||
88 |
@property |
|
89 |
def limit(self): |
|
90 |
if self.force_display: |
|
91 |
return None |
|
92 |
return self.maxrelitems + 1 |
|
93 |
||
94 |
def need_multipart(self, entity, categories=('primary', 'secondary')): |
|
95 |
"""return a boolean indicating if form's enctype should be multipart |
|
96 |
""" |
|
97 |
for rschema, _, x in entity.relations_by_category(categories): |
|
98 |
if entity.get_widget(rschema, x).need_multipart: |
|
99 |
return True |
|
100 |
# let's find if any of our inlined entities needs multipart |
|
101 |
for rschema, targettypes, x in entity.relations_by_category('inlineview'): |
|
102 |
assert len(targettypes) == 1, \ |
|
103 |
"I'm not able to deal with several targets and inlineview" |
|
104 |
ttype = targettypes[0] |
|
105 |
inlined_entity = self.vreg.etype_class(ttype)(self.req, None, None) |
|
106 |
for irschema, _, x in inlined_entity.relations_by_category(categories): |
|
107 |
if inlined_entity.get_widget(irschema, x).need_multipart: |
|
108 |
return True |
|
109 |
return False |
|
110 |
||
111 |
def error_message(self): |
|
112 |
"""return formatted error message |
|
113 |
||
114 |
This method should be called once inlined field errors has been consumed |
|
115 |
""" |
|
116 |
errex = self.req.data.get('formerrors') |
|
117 |
# get extra errors |
|
118 |
if errex is not None: |
|
119 |
errormsg = self.req._('please correct the following errors:') |
|
120 |
displayed = self.req.data['displayederrors'] |
|
121 |
errors = sorted((field, err) for field, err in errex.errors.items() |
|
122 |
if not field in displayed) |
|
123 |
if errors: |
|
124 |
if len(errors) > 1: |
|
125 |
templstr = '<li>%s</li>\n' |
|
126 |
else: |
|
127 |
templstr = ' %s\n' |
|
128 |
for field, err in errors: |
|
129 |
if field is None: |
|
130 |
errormsg += templstr % err |
|
131 |
else: |
|
132 |
errormsg += templstr % '%s: %s' % (self.req._(field), err) |
|
133 |
if len(errors) > 1: |
|
134 |
errormsg = '<ul>%s</ul>' % errormsg |
|
135 |
return u'<div class="errorMessage">%s</div>' % errormsg |
|
136 |
return u'' |
|
137 |
||
138 |
def restore_pending_inserts(self, entity, cell=False): |
|
139 |
"""used to restore edition page as it was before clicking on |
|
140 |
'search for <some entity type>' |
|
141 |
|
|
142 |
""" |
|
143 |
eid = entity.eid |
|
144 |
cell = cell and "div_insert_" or "tr" |
|
145 |
pending_inserts = set(self.req.get_pending_inserts(eid)) |
|
146 |
for pendingid in pending_inserts: |
|
147 |
eidfrom, rtype, eidto = pendingid.split(':') |
|
148 |
if typed_eid(eidfrom) == entity.eid: # subject |
|
149 |
label = display_name(self.req, rtype, 'subject') |
|
150 |
reid = eidto |
|
151 |
else: |
|
152 |
label = display_name(self.req, rtype, 'object') |
|
153 |
reid = eidfrom |
|
154 |
jscall = "javascript: cancelPendingInsert('%s', '%s', null, %s);" \ |
|
155 |
% (pendingid, cell, eid) |
|
156 |
rset = self.req.eid_rset(reid) |
|
157 |
eview = self.view('text', rset, row=0) |
|
158 |
# XXX find a clean way to handle baskets |
|
159 |
if rset.description[0][0] == 'Basket': |
|
160 |
eview = '%s (%s)' % (eview, display_name(self.req, 'Basket')) |
|
161 |
yield rtype, pendingid, jscall, label, reid, eview |
|
162 |
||
163 |
||
164 |
def force_display_link(self): |
|
165 |
return (u'<span class="invisible">' |
|
166 |
u'[<a href="javascript: window.location.href+=\'&__force_display=1\'">%s</a>]' |
|
167 |
u'</span>' % self.req._('view all')) |
|
168 |
||
169 |
def relations_table(self, entity): |
|
170 |
"""yiels 3-tuples (rtype, target, related_list) |
|
171 |
where <related_list> itself a list of : |
|
172 |
- node_id (will be the entity element's DOM id) |
|
173 |
- appropriate javascript's togglePendingDelete() function call |
|
174 |
- status 'pendingdelete' or '' |
|
175 |
- oneline view of related entity |
|
176 |
""" |
|
177 |
eid = entity.eid |
|
178 |
pending_deletes = self.req.get_pending_deletes(eid) |
|
179 |
# XXX (adim) : quick fix to get Folder relations |
|
180 |
for label, rschema, target in entity.srelations_by_category(('generic', 'metadata'), 'add'): |
|
181 |
if rschema in self.skip_relations: |
|
182 |
continue |
|
183 |
relatedrset = entity.related(rschema, target, limit=self.limit) |
|
184 |
toggable_rel_link = self.toggable_relation_link_func(rschema) |
|
185 |
related = [] |
|
186 |
for row in xrange(relatedrset.rowcount): |
|
187 |
nodeid = relation_id(eid, rschema, target, relatedrset[row][0]) |
|
188 |
if nodeid in pending_deletes: |
|
189 |
status = u'pendingDelete' |
|
190 |
label = '+' |
|
191 |
else: |
|
192 |
status = u'' |
|
193 |
label = 'x' |
|
194 |
dellink = toggable_rel_link(eid, nodeid, label) |
|
195 |
eview = self.view('oneline', relatedrset, row=row) |
|
196 |
related.append((nodeid, dellink, status, eview)) |
|
197 |
yield (rschema, target, related) |
|
198 |
||
199 |
def toggable_relation_link_func(self, rschema): |
|
200 |
if not rschema.has_perm(self.req, 'delete'): |
|
201 |
return lambda x, y, z: u'' |
|
202 |
return toggable_relation_link |
|
203 |
||
204 |
||
205 |
def redirect_url(self, entity=None): |
|
206 |
"""return a url to use as next direction if there are some information |
|
207 |
specified in current form params, else return the result the reset_url |
|
208 |
method which should be defined in concrete classes |
|
209 |
""" |
|
210 |
rparams = redirect_params(self.req.form) |
|
211 |
if rparams: |
|
212 |
return self.build_url('view', **rparams) |
|
213 |
return self.reset_url(entity) |
|
214 |
||
215 |
def reset_url(self, entity): |
|
216 |
raise NotImplementedError('implement me in concrete classes') |
|
217 |
||
218 |
BUTTON_STR = u'<input class="validateButton" type="submit" name="%s" value="%s" tabindex="%s"/>' |
|
219 |
ACTION_SUBMIT_STR = u'<input class="validateButton" type="button" onclick="postForm(\'%s\', \'%s\', \'%s\')" value="%s" tabindex="%s"/>' |
|
220 |
||
221 |
def button_ok(self, label=None, tabindex=None): |
|
222 |
label = self.req._(label or stdmsgs.BUTTON_OK).capitalize() |
|
223 |
return self.BUTTON_STR % ('defaultsubmit', label, tabindex or 2) |
|
224 |
||
225 |
def button_apply(self, label=None, tabindex=None): |
|
226 |
label = self.req._(label or stdmsgs.BUTTON_APPLY).capitalize() |
|
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
227 |
return self.ACTION_SUBMIT_STR % ('__action_apply', label, self.domid, |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
228 |
label, tabindex or 3) |
0 | 229 |
|
230 |
def button_delete(self, label=None, tabindex=None): |
|
231 |
label = self.req._(label or stdmsgs.BUTTON_DELETE).capitalize() |
|
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
232 |
return self.ACTION_SUBMIT_STR % ('__action_delete', label, self.domid, |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
233 |
label, tabindex or 3) |
0 | 234 |
|
235 |
def button_cancel(self, label=None, tabindex=None): |
|
236 |
label = self.req._(label or stdmsgs.BUTTON_CANCEL).capitalize() |
|
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
237 |
return self.ACTION_SUBMIT_STR % ('__action_cancel', label, self.domid, |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
238 |
label, tabindex or 4) |
0 | 239 |
|
240 |
def button_reset(self, label=None, tabindex=None): |
|
241 |
label = self.req._(label or stdmsgs.BUTTON_CANCEL).capitalize() |
|
242 |
return u'<input class="validateButton" type="reset" value="%s" tabindex="%s"/>' % ( |
|
243 |
label, tabindex or 4) |
|
844 | 244 |
|
245 |
||
246 |
############################################################################### |
|
247 |
||
248 |
from cubicweb.common import tags |
|
249 |
||
250 |
# widgets ############ |
|
251 |
||
252 |
class FieldWidget(object): |
|
253 |
def __init__(self, attrs=None): |
|
254 |
self.attrs = attrs or {} |
|
897
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
255 |
|
844 | 256 |
def render(self, form, field): |
257 |
raise NotImplementedError |
|
258 |
||
259 |
class Input(FieldWidget): |
|
260 |
type = None |
|
261 |
||
262 |
def render(self, form, field): |
|
263 |
name, value, attrs = self._render_attrs(form, field) |
|
264 |
if attrs is None: |
|
265 |
return tags.input(name=name, value=value) |
|
266 |
return tags.input(name=name, value=value, type=self.type, **attrs) |
|
267 |
||
268 |
def _render_attrs(self, form, field): |
|
269 |
name = form.context[field]['name'] # qualified name |
|
270 |
value = form.context[field]['value'] |
|
271 |
#fattrs = field.widget_attributes(self) |
|
272 |
attrs = self.attrs.copy() |
|
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
273 |
attrs['id'] = form.context[field]['id'] |
844 | 274 |
#attrs.update(fattrs) |
275 |
# XXX id |
|
276 |
return name, value, attrs |
|
277 |
||
278 |
class TextInput(Input): |
|
279 |
type = 'text' |
|
280 |
||
281 |
class PasswordInput(Input): |
|
282 |
type = 'password' |
|
283 |
||
284 |
class FileInput(Input): |
|
285 |
type = 'file' |
|
864
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
286 |
|
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
287 |
def _render_attrs(self, form, field): |
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
288 |
name = form.context[field]['name'] # qualified name |
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
289 |
return name, None, {} |
844 | 290 |
|
291 |
class HiddenInput(Input): |
|
292 |
type = 'hidden' |
|
897
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
293 |
|
844 | 294 |
class Button(Input): |
295 |
type = 'button' |
|
296 |
||
297 |
class TextArea(FieldWidget): |
|
298 |
def render(self, form, field): |
|
299 |
name, value, attrs = self._render_attrs(form, field) |
|
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
300 |
attrs.setdefault('onkeypress', 'autogrow(this)') |
844 | 301 |
return tags.textarea(value, name=name, **attrs) |
302 |
||
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
303 |
class FCKEditor(TextArea): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
304 |
def __init__(self, attrs): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
305 |
super(FCKEditor, self).__init__(attrs) |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
306 |
self.attrs['cubicweb:type'] = 'wysiwyg' |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
307 |
|
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
308 |
def render(self, form, field): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
309 |
form.req.fckeditor_config() |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
310 |
return super(self, FCKEditor, self).render(form, field) |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
311 |
|
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
312 |
|
894 | 313 |
#class EditableFile(Widget): |
314 |
# # XXX |
|
315 |
# pass |
|
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
316 |
|
864
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
317 |
class Select(FieldWidget): |
894 | 318 |
def __init__(self, attrs=None, vocabulary=()): |
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
319 |
super(Select, self).__init__(attrs) |
901
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
320 |
self.multiple = multiple |
864
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
321 |
|
844 | 322 |
def render(self, form, field): |
323 |
name, value, attrs = self._render_attrs(form, field) |
|
324 |
if self.vocabulary: |
|
325 |
# static vocabulary defined in form definition |
|
326 |
vocab = self.vocabulary |
|
327 |
else: |
|
328 |
vocab = form.get_vocabulary(field) |
|
329 |
options = [] |
|
330 |
for label, value in vocab: |
|
331 |
options.append(tags.option(label, value=value)) |
|
332 |
if attrs is None: |
|
333 |
return tags.select(name=name, options=options) |
|
901
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
334 |
return tags.select(name=name, multiple=self.multiple, |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
335 |
options=options, **attrs) |
844 | 336 |
|
337 |
||
864
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
338 |
class CheckBox(FieldWidget): |
844 | 339 |
|
865
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
340 |
def _render_attrs(self, form, field): |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
341 |
name, value, attrs = super(CheckBox, self)._render_attrs(form, field) |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
342 |
if value: |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
343 |
attrs['checked'] = u'checked' |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
344 |
return name, None, attrs |
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
345 |
|
865
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
346 |
|
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
347 |
class Radio(FieldWidget): |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
348 |
pass |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
349 |
|
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
350 |
|
865
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
351 |
class DateTimePicker(TextInput): |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
352 |
monthnames = ("january", "february", "march", "april", |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
353 |
"may", "june", "july", "august", |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
354 |
"september", "october", "november", "december") |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
355 |
|
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
356 |
daynames = ("monday", "tuesday", "wednesday", "thursday", |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
357 |
"friday", "saturday", "sunday") |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
358 |
|
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
359 |
@classmethod |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
360 |
def add_localized_infos(cls, req): |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
361 |
"""inserts JS variables defining localized months and days""" |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
362 |
# import here to avoid dependancy from cubicweb-common to simplejson |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
363 |
_ = req._ |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
364 |
monthnames = [_(mname) for mname in cls.monthnames] |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
365 |
daynames = [_(dname) for dname in cls.daynames] |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
366 |
req.html_headers.define_var('MONTHNAMES', monthnames) |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
367 |
req.html_headers.define_var('DAYNAMES', daynames) |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
368 |
|
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
369 |
def render(self, form, field): |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
370 |
txtwidget = super(DateTimePicker, self).render(form, field) |
867
14a79faa3a56
fix implementation errors import DateTimePicker
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
865
diff
changeset
|
371 |
cal_button = self._render_calendar_popup(form, field) |
865
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
372 |
return txtwidget + cal_button |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
373 |
|
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
374 |
def _render_calendar_popup(self, form, field): |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
375 |
req = form.req |
867
14a79faa3a56
fix implementation errors import DateTimePicker
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
865
diff
changeset
|
376 |
value = form.context[field]['rawvalue'] |
14a79faa3a56
fix implementation errors import DateTimePicker
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
865
diff
changeset
|
377 |
inputid = form.context[field]['id'] |
14a79faa3a56
fix implementation errors import DateTimePicker
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
865
diff
changeset
|
378 |
helperid = '%shelper' % inputid |
865
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
379 |
if not value: |
867
14a79faa3a56
fix implementation errors import DateTimePicker
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
865
diff
changeset
|
380 |
value = today() |
865
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
381 |
year, month = value.year, value.month |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
382 |
onclick = "toggleCalendar('%s', '%s', %s, %s);" % ( |
867
14a79faa3a56
fix implementation errors import DateTimePicker
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
865
diff
changeset
|
383 |
helperid, inputid, year, month) |
865
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
384 |
return (u"""<a onclick="toggleCalendar('%s', '%s', %s, %s);" class="calhelper"> |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
385 |
<img src="%s" title="%s" alt="" /></a><div class="calpopup hidden" id="%s"></div>""" |
90a1aea85637
DatePicker widget
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
864
diff
changeset
|
386 |
% (helperid, inputid, year, month, |
867
14a79faa3a56
fix implementation errors import DateTimePicker
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
865
diff
changeset
|
387 |
req.external_resource('CALENDAR_ICON'), |
14a79faa3a56
fix implementation errors import DateTimePicker
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
865
diff
changeset
|
388 |
req._('calendar'), helperid) ) |
844 | 389 |
|
390 |
||
391 |
# fields ############ |
|
392 |
||
393 |
class Field(object): |
|
394 |
"""field class is introduced to control what's displayed in edition form |
|
395 |
""" |
|
396 |
widget = TextInput |
|
397 |
needs_multipart = False |
|
398 |
creation_rank = 0 |
|
399 |
||
400 |
def __init__(self, name=None, id=None, label=None, |
|
901
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
401 |
widget=None, required=False, initial=None, |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
402 |
choices=None, help=None, eidparam=False): |
844 | 403 |
self.required = required |
404 |
if widget is not None: |
|
405 |
self.widget = widget |
|
406 |
if isinstance(self.widget, type): |
|
407 |
self.widget = self.widget() |
|
408 |
self.name = name |
|
409 |
self.label = label or name |
|
410 |
self.id = id or name |
|
411 |
self.initial = initial |
|
901
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
412 |
self.choices = choices or () |
844 | 413 |
self.help = help |
414 |
self.eidparam = eidparam |
|
901
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
415 |
self.role = 'subject' |
844 | 416 |
# global fields ordering in forms |
417 |
Field.creation_rank += 1 |
|
418 |
||
419 |
def set_name(self, name): |
|
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
420 |
assert name |
844 | 421 |
self.name = name |
422 |
if not self.id: |
|
423 |
self.id = name |
|
424 |
if not self.label: |
|
425 |
self.label = name |
|
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
426 |
|
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
427 |
def is_visible(self): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
428 |
return isinstance(self.widget, HiddenInput) |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
429 |
|
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
430 |
def actual_fields(self, form): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
431 |
yield self |
844 | 432 |
|
900
8f95ebbe2fd8
field debug helper
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
899
diff
changeset
|
433 |
def __unicode__(self): |
8f95ebbe2fd8
field debug helper
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
899
diff
changeset
|
434 |
return u'<%s name=%r label=%r id=%r initial=%r>' % ( |
8f95ebbe2fd8
field debug helper
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
899
diff
changeset
|
435 |
self.__class__.__name__, self.name, self.label, |
8f95ebbe2fd8
field debug helper
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
899
diff
changeset
|
436 |
self.id, self.initial) |
8f95ebbe2fd8
field debug helper
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
899
diff
changeset
|
437 |
|
8f95ebbe2fd8
field debug helper
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
899
diff
changeset
|
438 |
def __repr__(self): |
8f95ebbe2fd8
field debug helper
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
899
diff
changeset
|
439 |
return self.__unicode__().encode('utf-8') |
8f95ebbe2fd8
field debug helper
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
899
diff
changeset
|
440 |
|
844 | 441 |
def format_value(self, req, value): |
442 |
return unicode(value) |
|
443 |
||
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
444 |
def get_widget(self, req): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
445 |
return self.widget |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
446 |
|
844 | 447 |
def render(self, form): |
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
448 |
return self.get_widget(form.req).render(form, self) |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
449 |
|
844 | 450 |
|
901
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
451 |
def vocabulary(self, form): |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
452 |
return self.choices |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
453 |
|
844 | 454 |
class StringField(Field): |
455 |
def __init__(self, max_length=None, **kwargs): |
|
456 |
super(StringField, self).__init__(**kwargs) |
|
457 |
self.max_length = max_length |
|
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
458 |
|
844 | 459 |
class TextField(Field): |
460 |
widget = TextArea |
|
461 |
def __init__(self, row=None, col=None, **kwargs): |
|
462 |
super(TextField, self).__init__(**kwargs) |
|
463 |
self.row = row |
|
464 |
self.col = col |
|
465 |
||
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
466 |
|
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
467 |
class RichTextField(TextField): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
468 |
widget = None |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
469 |
def __init__(self, format_field=None, **kwargs): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
470 |
super(RichTextField, self).__init__(**kwargs) |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
471 |
self.format_field = format_field |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
472 |
|
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
473 |
def get_widget(self, req): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
474 |
if self.widget is None: |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
475 |
if self.use_fckeditor(req): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
476 |
return FCKEditor() |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
477 |
return TextArea() |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
478 |
return self.widget |
844 | 479 |
|
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
480 |
def get_format_field(self, form): |
894 | 481 |
if not self.format_field: |
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
482 |
# if fckeditor is used and format field isn't explicitly |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
483 |
# deactivated, we want an hidden field for the format |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
484 |
if self.use_fckeditor(form): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
485 |
widget = HiddenInput |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
486 |
# else we want a format selector |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
487 |
else: |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
488 |
widget = Select |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
489 |
return StringField(name=self.name + '_format', widget=widget) |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
490 |
else: |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
491 |
return self.format_field |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
492 |
|
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
493 |
def actual_fields(self, form): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
494 |
yield self |
894 | 495 |
format_field = self.get_format_field(form) |
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
496 |
if format_field: |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
497 |
yield format_field |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
498 |
|
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
499 |
def use_fckeditor(self, form): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
500 |
"""return True if fckeditor should be used to edit entity's attribute named |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
501 |
`attr`, according to user preferences |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
502 |
""" |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
503 |
if form.config.fckeditor_installed() and form.req.property_value('ui.fckeditor'): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
504 |
return form.form_format_field_value(self) == 'text/html' |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
505 |
return False |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
506 |
|
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
507 |
def render(self, form): |
894 | 508 |
format_field = self.get_format_field(form) |
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
509 |
if format_field: |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
510 |
result = format_field.render(form) |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
511 |
else: |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
512 |
result = u'' |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
513 |
return result + self.get_widget(form.req).render(form, self) |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
514 |
|
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
515 |
|
844 | 516 |
class IntField(Field): |
517 |
def __init__(self, min=None, max=None, **kwargs): |
|
518 |
super(IntField, self).__init__(**kwargs) |
|
519 |
self.min = min |
|
520 |
self.max = max |
|
521 |
||
864
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
522 |
class FloatField(IntField): |
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
523 |
def format_value(self, req, value): |
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
524 |
formatstr = entity.req.property_value('ui.float-format') |
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
525 |
if value is None: |
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
526 |
return u'' |
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
527 |
return formatstr % float(value) |
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
528 |
|
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
529 |
class DateField(StringField): |
899
48d465b5171a
rename propname into format_prop
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
898
diff
changeset
|
530 |
format_prop = 'ui.date-format' |
844 | 531 |
|
899
48d465b5171a
rename propname into format_prop
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
898
diff
changeset
|
532 |
def format_single_value(self, req, value): |
48d465b5171a
rename propname into format_prop
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
898
diff
changeset
|
533 |
return value and ustrftime(value, req.property_value(self.format_prop)) or u'' |
844 | 534 |
|
864
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
535 |
class DateTimeField(DateField): |
899
48d465b5171a
rename propname into format_prop
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
898
diff
changeset
|
536 |
format_prop = 'ui.datetime-format' |
864
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
537 |
|
899
48d465b5171a
rename propname into format_prop
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
898
diff
changeset
|
538 |
class TimeField(DateField): |
48d465b5171a
rename propname into format_prop
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
898
diff
changeset
|
539 |
format_prop = 'ui.datetime-format' |
844 | 540 |
|
864
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
541 |
class FileField(StringField): |
e0947007542a
basic implementation of Date / Float fields
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
863
diff
changeset
|
542 |
needs_multipart = True |
844 | 543 |
|
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
544 |
class HiddenInitialValueField(Field): |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
545 |
def __init__(self, visible_field, name): |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
546 |
super(HiddenInitialValueField, self).__init__(name=name, |
898
583f64567256
fix HiddenRelationField bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
897
diff
changeset
|
547 |
widget=HiddenInput, |
583f64567256
fix HiddenRelationField bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
897
diff
changeset
|
548 |
eidparam=True) |
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
549 |
self.visible_field = visible_field |
897
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
550 |
|
844 | 551 |
|
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
552 |
class RelationField(Field): |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
553 |
def __init__(self, role='subject', **kwargs): |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
554 |
super(RelationField, self).__init__(**kwargs) |
897
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
555 |
|
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
556 |
@staticmethod |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
557 |
def fromcardinality(card, role, **kwargs): |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
558 |
return RelationField(widget=Select(multiple=card in '*+'), |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
559 |
**kwargs) |
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
560 |
|
901
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
561 |
def vocabulary(self, form): |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
562 |
entity = form.entity |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
563 |
req = entity.req |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
564 |
# first see if its specified by __linkto form parameters |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
565 |
linkedto = entity.linked_to(self.name, self.role) |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
566 |
if linkedto: |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
567 |
entities = (req.eid_rset(eid).get_entity(0, 0) for eid in linkedto) |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
568 |
return [(entity.view('combobox'), entity.eid) for entity in entities] |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
569 |
# it isn't, check if the entity provides a method to get correct values |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
570 |
res = [] |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
571 |
if not self.required: |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
572 |
res.append(('', INTERNAL_FIELD_VALUE)) |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
573 |
# vocabulary doesn't include current values, add them |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
574 |
if entity.has_eid(): |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
575 |
rset = entity.related(self.name, self.role) |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
576 |
relatedvocab = [(e.view('combobox'), e.eid) for e in rset.entities()] |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
577 |
else: |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
578 |
relatedvocab = [] |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
579 |
return res + form.form_field_vocabulary(self) + relatedvocab |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
580 |
|
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
581 |
def format_single_value(self, req, value): |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
582 |
return value |
0dcf01eb97a0
implement default vocabulary method on Field, provide a specific one on RelationField
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
900
diff
changeset
|
583 |
|
844 | 584 |
# forms ############ |
585 |
class metafieldsform(type): |
|
586 |
def __new__(mcs, name, bases, classdict): |
|
587 |
allfields = [] |
|
588 |
for base in bases: |
|
589 |
if hasattr(base, '_fields_'): |
|
590 |
allfields += base._fields_ |
|
591 |
clsfields = (item for item in classdict.items() |
|
592 |
if isinstance(item[1], Field)) |
|
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
593 |
for fieldname, field in sorted(clsfields, key=lambda x: x[1].creation_rank): |
844 | 594 |
if not field.name: |
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
595 |
field.set_name(fieldname) |
844 | 596 |
allfields.append(field) |
597 |
classdict['_fields_'] = allfields |
|
598 |
return super(metafieldsform, mcs).__new__(mcs, name, bases, classdict) |
|
599 |
||
600 |
||
887
51e371245bc5
various fixes to have change state and deletion forms working
sylvain.thenault@logilab.fr
parents:
874
diff
changeset
|
601 |
class FieldsForm(FormMixIn): |
844 | 602 |
__metaclass__ = metafieldsform |
603 |
||
887
51e371245bc5
various fixes to have change state and deletion forms working
sylvain.thenault@logilab.fr
parents:
874
diff
changeset
|
604 |
def __init__(self, req, domid=None, title=None, action='edit', |
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
605 |
onsubmit="return freezeFormButtons('%s');", |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
606 |
cssclass=None, cssstyle=None, cwtarget=None, buttons=None, |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
607 |
redirect_path=None, set_error_url=True, copy_nav_params=False): |
844 | 608 |
self.req = req |
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
609 |
self.config = req.vreg.config |
887
51e371245bc5
various fixes to have change state and deletion forms working
sylvain.thenault@logilab.fr
parents:
874
diff
changeset
|
610 |
self.domid = domid or 'form' |
844 | 611 |
self.title = title |
612 |
self.action = action |
|
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
613 |
self.onsubmit = onsubmit |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
614 |
self.cssclass = cssclass |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
615 |
self.cssstyle = cssstyle |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
616 |
self.cwtarget = cwtarget |
887
51e371245bc5
various fixes to have change state and deletion forms working
sylvain.thenault@logilab.fr
parents:
874
diff
changeset
|
617 |
self.redirect_path = redirect_path |
844 | 618 |
self.fields = list(self.__class__._fields_) |
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
619 |
if set_error_url: |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
620 |
self.form_add_hidden('__errorurl', req.url()) |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
621 |
if copy_nav_params: |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
622 |
for param in NAV_FORM_PARAMETERS: |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
623 |
value = req.form.get(param) |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
624 |
if value: |
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
625 |
self.form_add_hidden(param, initial=value) |
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
626 |
self.buttons = buttons or [] |
844 | 627 |
self.context = {} |
628 |
||
629 |
@property |
|
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
630 |
def form_needs_multipart(self): |
844 | 631 |
return any(field.needs_multipart for field in self.fields) |
0 | 632 |
|
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
633 |
def form_add_hidden(self, name, value=None, **kwargs): |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
634 |
self.fields.append(TextField(name=name, widget=HiddenInput, |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
635 |
initial=value, **kwargs)) |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
636 |
|
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
637 |
def form_render(self, **values): |
844 | 638 |
renderer = values.pop('renderer', FormRenderer()) |
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
639 |
return renderer.render(self, values) |
844 | 640 |
|
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
641 |
def form_build_context(self, values): |
844 | 642 |
self.context = context = {} |
849
8591d896db7e
update some prototype, ChangeStateForm
sylvain.thenault@logilab.fr
parents:
848
diff
changeset
|
643 |
# on validation error, we get a dictionnary of previously submitted values |
8591d896db7e
update some prototype, ChangeStateForm
sylvain.thenault@logilab.fr
parents:
848
diff
changeset
|
644 |
previous_values = self.req.data.get('formvalues') |
8591d896db7e
update some prototype, ChangeStateForm
sylvain.thenault@logilab.fr
parents:
848
diff
changeset
|
645 |
if previous_values: |
8591d896db7e
update some prototype, ChangeStateForm
sylvain.thenault@logilab.fr
parents:
848
diff
changeset
|
646 |
values.update(previous_values) |
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
647 |
for field in self.fields: |
894 | 648 |
for field in field.actual_fields(self): |
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
649 |
value = self.form_field_value(field, values) |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
650 |
context[field] = {'value': field.format_value(self.req, value), |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
651 |
'rawvalue': value, |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
652 |
'name': self.form_field_name(field), |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
653 |
'id': self.form_field_id(field), |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
654 |
} |
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
655 |
|
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
656 |
def form_field_value(self, field, values): |
848
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
657 |
"""looks for field's value in |
849
8591d896db7e
update some prototype, ChangeStateForm
sylvain.thenault@logilab.fr
parents:
848
diff
changeset
|
658 |
1. kw args given to render_form (including previously submitted form |
8591d896db7e
update some prototype, ChangeStateForm
sylvain.thenault@logilab.fr
parents:
848
diff
changeset
|
659 |
values if any) |
848
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
660 |
2. req.form |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
661 |
3. field's initial value |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
662 |
""" |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
663 |
if field.name in values: |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
664 |
value = values[field.name] |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
665 |
elif field.name in self.req.form: |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
666 |
value = self.req.form[field.name] |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
667 |
else: |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
668 |
value = field.initial |
897
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
669 |
return value |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
670 |
|
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
671 |
def form_format_field_value(self, field, values): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
672 |
return self.req.property_value('ui.default-text-format') |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
673 |
|
849
8591d896db7e
update some prototype, ChangeStateForm
sylvain.thenault@logilab.fr
parents:
848
diff
changeset
|
674 |
def form_field_name(self, field): |
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
675 |
return field.name |
844 | 676 |
|
849
8591d896db7e
update some prototype, ChangeStateForm
sylvain.thenault@logilab.fr
parents:
848
diff
changeset
|
677 |
def form_field_id(self, field): |
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
678 |
return field.id |
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
679 |
|
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
680 |
def form_field_vocabulary(self, field): |
844 | 681 |
raise NotImplementedError |
682 |
||
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
683 |
def form_buttons(self): |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
684 |
return self.buttons |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
685 |
|
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
686 |
|
844 | 687 |
class EntityFieldsForm(FieldsForm): |
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
688 |
|
844 | 689 |
def __init__(self, *args, **kwargs): |
887
51e371245bc5
various fixes to have change state and deletion forms working
sylvain.thenault@logilab.fr
parents:
874
diff
changeset
|
690 |
kwargs.setdefault('domid', 'entityForm') |
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
691 |
self.entity = kwargs.pop('entity', None) |
844 | 692 |
super(EntityFieldsForm, self).__init__(*args, **kwargs) |
887
51e371245bc5
various fixes to have change state and deletion forms working
sylvain.thenault@logilab.fr
parents:
874
diff
changeset
|
693 |
self.form_add_hidden('__type', eidparam=True) |
51e371245bc5
various fixes to have change state and deletion forms working
sylvain.thenault@logilab.fr
parents:
874
diff
changeset
|
694 |
self.form_add_hidden('eid') |
844 | 695 |
|
874
90d98d80af82
EntityFieldsForm.form_render() doesn't need entity anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
869
diff
changeset
|
696 |
def form_render(self, **values): |
90d98d80af82
EntityFieldsForm.form_render() doesn't need entity anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
869
diff
changeset
|
697 |
self.form_add_entity_hiddens(self.entity.e_schema) |
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
698 |
return super(EntityFieldsForm, self).form_render(**values) |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
699 |
|
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
700 |
def form_add_entity_hiddens(self, eschema): |
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
701 |
for field in self.fields[:]: |
894 | 702 |
for field in field.actual_fields(self): |
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
703 |
fieldname = field.name |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
704 |
if fieldname != 'eid' and ( |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
705 |
(eschema.has_subject_relation(fieldname) or |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
706 |
eschema.has_object_relation(fieldname))): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
707 |
field.eidparam = True |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
708 |
self.fields.append(self.form_entity_hidden_field(field)) |
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
709 |
|
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
710 |
def form_entity_hidden_field(self, field): |
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
711 |
"""returns the hidden field which will indicate the value |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
712 |
before the modification |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
713 |
""" |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
714 |
# Only RelationField has a `role` attribute, others are used |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
715 |
# to describe attribute fields => role is 'subject' |
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
716 |
if getattr(field, 'role', 'subject') == 'subject': |
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
717 |
name = 'edits-%s' % field.name |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
718 |
else: |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
719 |
name = 'edito-%s' % field.name |
898
583f64567256
fix HiddenRelationField bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
897
diff
changeset
|
720 |
return HiddenInitialValueField(field, name=name) |
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
721 |
|
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
722 |
def form_field_value(self, field, values): |
848
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
723 |
"""look for field's value with the following rules: |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
724 |
1. handle special __type and eid fields |
849
8591d896db7e
update some prototype, ChangeStateForm
sylvain.thenault@logilab.fr
parents:
848
diff
changeset
|
725 |
2. looks in kw args given to render_form (including previously submitted |
8591d896db7e
update some prototype, ChangeStateForm
sylvain.thenault@logilab.fr
parents:
848
diff
changeset
|
726 |
form values if any) |
848
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
727 |
3. looks in req.form |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
728 |
4. if entity has an eid: |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
729 |
1. looks for an associated attribute / method |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
730 |
2. use field's initial value |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
731 |
else: |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
732 |
1. looks for a default_<fieldname> attribute / method on the form |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
733 |
2. use field's initial value |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
734 |
|
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
735 |
values found in step 4 may be a callable which'll then be called. |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
736 |
""" |
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
737 |
fieldname = field.name |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
738 |
if fieldname.startswith('edits-') or fieldname.startswith('edito-'): |
888
603327e9aef4
fix field value for hidden edit[s|Ã ] fields
sylvain.thenault@logilab.fr
parents:
887
diff
changeset
|
739 |
# edit[s|o]- fieds must have the actual value stored on the entity |
603327e9aef4
fix field value for hidden edit[s|Ã ] fields
sylvain.thenault@logilab.fr
parents:
887
diff
changeset
|
740 |
if self.entity.has_eid(): |
603327e9aef4
fix field value for hidden edit[s|Ã ] fields
sylvain.thenault@logilab.fr
parents:
887
diff
changeset
|
741 |
value = self.form_field_entity_value(field, default_initial=False) |
603327e9aef4
fix field value for hidden edit[s|Ã ] fields
sylvain.thenault@logilab.fr
parents:
887
diff
changeset
|
742 |
else: |
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
743 |
value = INTERNAL_FIELD_VALUE |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
744 |
elif fieldname == '__type': |
848
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
745 |
value = self.entity.id |
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
746 |
elif fieldname == 'eid': |
848
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
747 |
value = self.entity.eid |
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
748 |
elif fieldname in values: |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
749 |
value = values[fieldname] |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
750 |
elif fieldname in self.req.form: |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
751 |
value = self.req.form[fieldname] |
848
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
752 |
else: |
888
603327e9aef4
fix field value for hidden edit[s|Ã ] fields
sylvain.thenault@logilab.fr
parents:
887
diff
changeset
|
753 |
if self.entity.has_eid() and field.eidparam: |
848
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
754 |
# use value found on the entity or field's initial value if it's |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
755 |
# not an attribute of the entity (XXX may conflicts and get |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
756 |
# undesired value) |
888
603327e9aef4
fix field value for hidden edit[s|Ã ] fields
sylvain.thenault@logilab.fr
parents:
887
diff
changeset
|
757 |
value = self.form_field_entity_value(field, default_initial=True) |
848
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
758 |
else: |
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
759 |
defaultattr = 'default_%s' % fieldname |
848
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
760 |
if hasattr(self.entity, defaultattr): |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
761 |
# XXX bw compat, default_<field name> on the entity |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
762 |
warn('found %s on %s, should be set on a specific form' |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
763 |
% (defaultattr, self.entity.id), DeprecationWarning) |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
764 |
value = getattr(self.entity, defaultattr) |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
765 |
elif hasattr(self, defaultattr): |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
766 |
# search for default_<field name> on the form instance |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
767 |
value = getattr(self, defaultattr) |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
768 |
else: |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
769 |
# use field's initial value |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
770 |
value = field.initial |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
771 |
if callable(value): |
f5aca5c5f6ca
set __errorurl, fix retreiving of field's value
sylvain.thenault@logilab.fr
parents:
847
diff
changeset
|
772 |
values = value() |
897
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
773 |
return value |
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
774 |
|
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
775 |
def form_format_field_value(self, field, values): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
776 |
entity = self.entity |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
777 |
if field.eidparam and entity.has_format(field.name) and ( |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
778 |
entity.has_eid() or '%s_format' % field.name in entity): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
779 |
return self.entity.format(field.name) == 'text/html' |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
780 |
return self.req.property_value('ui.default-text-format') |
844 | 781 |
|
888
603327e9aef4
fix field value for hidden edit[s|Ã ] fields
sylvain.thenault@logilab.fr
parents:
887
diff
changeset
|
782 |
def form_field_entity_value(self, field, default_initial=True): |
603327e9aef4
fix field value for hidden edit[s|Ã ] fields
sylvain.thenault@logilab.fr
parents:
887
diff
changeset
|
783 |
attr = field.name |
603327e9aef4
fix field value for hidden edit[s|Ã ] fields
sylvain.thenault@logilab.fr
parents:
887
diff
changeset
|
784 |
if field.role == 'object': |
603327e9aef4
fix field value for hidden edit[s|Ã ] fields
sylvain.thenault@logilab.fr
parents:
887
diff
changeset
|
785 |
attr += '_object' |
603327e9aef4
fix field value for hidden edit[s|Ã ] fields
sylvain.thenault@logilab.fr
parents:
887
diff
changeset
|
786 |
if default_initial: |
603327e9aef4
fix field value for hidden edit[s|Ã ] fields
sylvain.thenault@logilab.fr
parents:
887
diff
changeset
|
787 |
return getattr(self.entity, attr, field.initial) |
603327e9aef4
fix field value for hidden edit[s|Ã ] fields
sylvain.thenault@logilab.fr
parents:
887
diff
changeset
|
788 |
else: |
603327e9aef4
fix field value for hidden edit[s|Ã ] fields
sylvain.thenault@logilab.fr
parents:
887
diff
changeset
|
789 |
return getattr(self.entity, attr) |
603327e9aef4
fix field value for hidden edit[s|Ã ] fields
sylvain.thenault@logilab.fr
parents:
887
diff
changeset
|
790 |
|
849
8591d896db7e
update some prototype, ChangeStateForm
sylvain.thenault@logilab.fr
parents:
848
diff
changeset
|
791 |
def form_field_name(self, field): |
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
792 |
if field.eidparam: |
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
793 |
return eid_param(field.name, self.entity.eid) |
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
794 |
return field.name |
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
795 |
|
849
8591d896db7e
update some prototype, ChangeStateForm
sylvain.thenault@logilab.fr
parents:
848
diff
changeset
|
796 |
def form_field_id(self, field): |
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
797 |
if field.eidparam: |
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
798 |
return eid_param(field.id, self.entity.eid) |
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
799 |
return field.id |
844 | 800 |
|
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
801 |
def form_field_vocabulary(self, field): |
844 | 802 |
choices = self.vocabfunc(entity) |
803 |
if self.sort: |
|
804 |
choices = sorted(choices) |
|
805 |
if self.rschema.rproperty(self.subjtype, self.objtype, 'internationalizable'): |
|
806 |
return zip((entity.req._(v) for v in choices), choices) |
|
807 |
return zip(choices, choices) |
|
808 |
||
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
809 |
|
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
810 |
class MultipleFieldsForm(FieldsForm): |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
811 |
def __init__(self, *args, **kwargs): |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
812 |
super(MultipleFieldsForm, self).__init__(*args, **kwargs) |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
813 |
self.forms = [] |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
814 |
|
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
815 |
def form_add_subform(self, subform): |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
816 |
self.forms.append(subform) |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
817 |
|
844 | 818 |
# form renderers ############ |
819 |
||
820 |
class FormRenderer(object): |
|
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
821 |
|
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
822 |
def render(self, form, values): |
844 | 823 |
data = [] |
824 |
w = data.append |
|
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
825 |
# XXX form_needs_multipart |
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
826 |
w(self.open_form(form)) |
896
6e0379fc1988
put form buttons in a separate table
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
894
diff
changeset
|
827 |
w(u'<div id="progress">%s</div>' % form.req._('validating...')) |
844 | 828 |
w(u'<fieldset>') |
887
51e371245bc5
various fixes to have change state and deletion forms working
sylvain.thenault@logilab.fr
parents:
874
diff
changeset
|
829 |
w(tags.input(type='hidden', name='__form_id', value=form.domid)) |
844 | 830 |
if form.redirect_path: |
887
51e371245bc5
various fixes to have change state and deletion forms working
sylvain.thenault@logilab.fr
parents:
874
diff
changeset
|
831 |
w(tags.input(type='hidden', name='__redirectpath', value=form.redirect_path)) |
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
832 |
self.render_fields(w, form, values) |
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
833 |
self.render_buttons(w, form) |
844 | 834 |
w(u'</fieldset>') |
835 |
w(u'</form>') |
|
836 |
return '\n'.join(data) |
|
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
837 |
|
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
838 |
def open_form(self, form): |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
839 |
if form.form_needs_multipart: |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
840 |
enctype = 'multipart/form-data' |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
841 |
else: |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
842 |
enctype = 'application/x-www-form-urlencoded' |
887
51e371245bc5
various fixes to have change state and deletion forms working
sylvain.thenault@logilab.fr
parents:
874
diff
changeset
|
843 |
tag = ('<form action="%s" methody="post" id="%s" enctype="%s"' % ( |
51e371245bc5
various fixes to have change state and deletion forms working
sylvain.thenault@logilab.fr
parents:
874
diff
changeset
|
844 |
html_escape(form.action or '#'), form.domid, enctype)) |
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
845 |
if form.onsubmit: |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
846 |
tag += ' onsubmit="%s"' % html_escape(form.onsubmit) |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
847 |
if form.cssstyle: |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
848 |
tag += ' style="%s"' % html_escape(form.cssstyle) |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
849 |
if form.cssclass: |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
850 |
tag += ' class="%s"' % html_escape(form.cssclass) |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
851 |
if form.cwtarget: |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
852 |
tag += ' cubicweb:target="%s"' % html_escape(form.cwtarget) |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
853 |
return tag + '>' |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
854 |
|
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
855 |
def render_fields(self, w, form, values): |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
856 |
form.form_build_context(values) |
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
857 |
fields = form.fields[:] |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
858 |
for field in form.fields: |
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
859 |
if not field.is_visible(): |
863
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
860 |
w(field.render(form)) |
4fde01fc39ca
restore previous hidden input behaviour (edits- / edito- fields)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
849
diff
changeset
|
861 |
fields.remove(field) |
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
862 |
if fields: |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
863 |
w(u'<table>') |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
864 |
for field in fields: |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
865 |
w(u'<tr>') |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
866 |
w('<th>%s</th>' % self.render_label(form, field)) |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
867 |
w(u'<td style="width:100%;">') |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
868 |
w(field.render(form)) |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
869 |
w(u'</td></tr>') |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
870 |
w(u'</table>') |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
871 |
for childform in getattr(form, 'forms', []): |
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
872 |
self.render_fields(w, childform, values) |
892
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
873 |
|
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
874 |
#def render_field(self, w, form, field): |
1558772340a7
rich field / fckeditor handling
sylvain.thenault@logilab.fr
parents:
888
diff
changeset
|
875 |
|
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
876 |
def render_buttons(self, w, form): |
896
6e0379fc1988
put form buttons in a separate table
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
894
diff
changeset
|
877 |
w(u'<table class="formButtonBar">\n<tr>\n') |
869
168ad6d424d1
form to edit multiple entities, use it in DeleteConfForm
sylvain.thenault@logilab.fr
parents:
867
diff
changeset
|
878 |
for button in form.form_buttons(): |
896
6e0379fc1988
put form buttons in a separate table
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
894
diff
changeset
|
879 |
w(u'<td>%s</td>\n' % button) |
6e0379fc1988
put form buttons in a separate table
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
894
diff
changeset
|
880 |
w(u'</tr></table>') |
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
881 |
|
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
882 |
def render_label(self, form, field): |
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
883 |
label = form.req._(field.label) |
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
884 |
attrs = {'for': form.context[field]['id']} |
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
885 |
if field.required: |
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
886 |
attrs['class'] = 'required' |
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
887 |
return tags.label(label, **attrs) |
897
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
888 |
|
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
889 |
|
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
890 |
def stringfield_from_constraints(constraints, **kwargs): |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
891 |
field = None |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
892 |
for cstr in constraints: |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
893 |
if isinstance(cstr, StaticVocabularyConstraint): |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
894 |
return StringField(widget=Select(vocabulary=cstr.vocabulary), |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
895 |
**kwargs) |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
896 |
if isinstance(cstr, SizeConstraint) and cstr.max is not None: |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
897 |
if cstr.max > 257: |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
898 |
field = textfield_from_constraint(cstr, **kwargs) |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
899 |
else: |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
900 |
field = StringField(max_length=cstr.max, **kwargs) |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
901 |
return field or TextField(**kwargs) |
847
27c4ebe90d03
prefixed form methods to avoid potential conflicts with field names, button related method, a bit more serious renderer
sylvain.thenault@logilab.fr
parents:
844
diff
changeset
|
902 |
|
897
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
903 |
|
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
904 |
def textfield_from_constraint(constraint, **kwargs): |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
905 |
if 256 < constraint.max < 513: |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
906 |
rows, cols = 5, 60 |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
907 |
else: |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
908 |
rows, cols = 10, 80 |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
909 |
return TextField(rows, cols, **kwargs) |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
910 |
|
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
911 |
|
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
912 |
def find_field(eclass, subjschema, rschema, role='subject'): |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
913 |
"""return the most adapated widget to edit the relation |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
914 |
'subjschema rschema objschema' according to information found in the schema |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
915 |
""" |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
916 |
fieldclass = None |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
917 |
if role == 'subject': |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
918 |
objschema = rschema.objects(subjschema)[0] |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
919 |
cardidx = 0 |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
920 |
else: |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
921 |
objschema = rschema.subjects(subjschema)[0] |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
922 |
cardidx = 1 |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
923 |
card = rschema.rproperty(subjschema, objschema, 'cardinality')[cardidx] |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
924 |
required = card in '1+' |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
925 |
if rschema in eclass.widgets: |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
926 |
fieldclass = eclass.widgets[rschema] |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
927 |
if isinstance(fieldclass, basestring): |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
928 |
return StringField(name=rschema.type) |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
929 |
elif not rschema.is_final(): |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
930 |
return RelationField.fromcardinality(card, role,name=rschema.type, |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
931 |
required=required) |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
932 |
else: |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
933 |
fieldclass = FIELDS[objschema] |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
934 |
if fieldclass is StringField: |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
935 |
constraints = rschema.rproperty(subjschema, objschema, 'constraints') |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
936 |
return stringfield_from_constraints(constraints, name=rschema.type, |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
937 |
required=required) |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
938 |
return fieldclass(name=rschema.type, required=required) |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
939 |
|
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
940 |
FIELDS = { |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
941 |
'Boolean': BooleanField, |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
942 |
'Bytes': FileField, |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
943 |
'Date': DateField, |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
944 |
'Datetime': DateTimeField, |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
945 |
'Int': IntField, |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
946 |
'Float': FloatField, |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
947 |
'Decimal': StringField, |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
948 |
'Password': StringField, |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
949 |
'String' : StringField, |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
950 |
'Time': TimeField, |
f5b91f11d8b6
provide basic methods to build fields from schema constraints / cardinality
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
896
diff
changeset
|
951 |
} |