10 |
10 |
11 from logilab.common.decorators import iclassmethod |
11 from logilab.common.decorators import iclassmethod |
12 |
12 |
13 from cubicweb import typed_eid |
13 from cubicweb import typed_eid |
14 from cubicweb.web import stdmsgs, uicfg |
14 from cubicweb.web import stdmsgs, uicfg |
15 from cubicweb.web.form import FieldNotFound |
15 from cubicweb.web import form, formwidgets as fwdgs |
16 from cubicweb.web.formfields import guess_field |
16 from cubicweb.web.formfields import guess_field |
17 from cubicweb.web import formwidgets |
|
18 from cubicweb.web.views import forms, editforms |
17 from cubicweb.web.views import forms, editforms |
19 |
18 |
20 |
19 |
21 class AutomaticEntityForm(forms.EntityFieldsForm): |
20 class AutomaticEntityForm(forms.EntityFieldsForm): |
22 """base automatic form to edit any entity. |
21 """base automatic form to edit any entity. |
33 id = 'edition' |
32 id = 'edition' |
34 |
33 |
35 cwtarget = 'eformframe' |
34 cwtarget = 'eformframe' |
36 cssclass = 'entityForm' |
35 cssclass = 'entityForm' |
37 copy_nav_params = True |
36 copy_nav_params = True |
38 form_buttons = [formwidgets.SubmitButton(), |
37 form_buttons = [fwdgs.SubmitButton(), |
39 formwidgets.Button(stdmsgs.BUTTON_APPLY, cwaction='apply'), |
38 fwdgs.Button(stdmsgs.BUTTON_APPLY, cwaction='apply'), |
40 formwidgets.Button(stdmsgs.BUTTON_CANCEL, cwaction='cancel')] |
39 fwdgs.Button(stdmsgs.BUTTON_CANCEL, cwaction='cancel')] |
41 attrcategories = ('primary', 'secondary') |
40 attrcategories = ('primary', 'secondary') |
42 # class attributes below are actually stored in the uicfg module since we |
41 # class attributes below are actually stored in the uicfg module since we |
43 # don't want them to be reloaded |
42 # don't want them to be reloaded |
44 rcategories = uicfg.autoform_section |
43 rcategories = uicfg.autoform_section |
45 rfields = uicfg.autoform_field |
44 rfields = uicfg.autoform_field |
131 defined for the form but `eclass` is specified, guess_field will be |
130 defined for the form but `eclass` is specified, guess_field will be |
132 called. |
131 called. |
133 """ |
132 """ |
134 try: |
133 try: |
135 return super(AutomaticEntityForm, cls_or_self).field_by_name(name, role) |
134 return super(AutomaticEntityForm, cls_or_self).field_by_name(name, role) |
136 except FieldNotFound: # XXX should raise more explicit exception |
135 except form.FieldNotFound: |
137 if eschema is None or not name in cls_or_self.schema: |
136 if eschema is None or not name in cls_or_self.schema: |
138 raise |
137 raise |
139 rschema = cls_or_self.schema.rschema(name) |
138 rschema = cls_or_self.schema.rschema(name) |
140 # XXX use a sample target type. Document this. |
139 # XXX use a sample target type. Document this. |
141 tschemas = rschema.targets(eschema, role) |
140 tschemas = rschema.targets(eschema, role) |
161 entity.complete() |
160 entity.complete() |
162 for rschema, role in self.editable_attributes(): |
161 for rschema, role in self.editable_attributes(): |
163 try: |
162 try: |
164 self.field_by_name(rschema.type, role) |
163 self.field_by_name(rschema.type, role) |
165 continue # explicitly specified |
164 continue # explicitly specified |
166 except FieldNotFound: |
165 except form.FieldNotFound: |
167 # has to be guessed |
166 # has to be guessed |
168 try: |
167 try: |
169 field = self.field_by_name(rschema.type, role, |
168 field = self.field_by_name(rschema.type, role, |
170 eschema=entity.e_schema) |
169 eschema=entity.e_schema) |
171 self.fields.append(field) |
170 self.fields.append(field) |
172 except FieldNotFound: |
171 except form.FieldNotFound: |
173 # meta attribute such as <attr>_format |
172 # meta attribute such as <attr>_format |
174 continue |
173 continue |
175 self.maxrelitems = self.req.property_value('navigation.related-limit') |
174 self.maxrelitems = self.req.property_value('navigation.related-limit') |
176 self.force_display = bool(self.req.form.get('__force_display')) |
175 self.force_display = bool(self.req.form.get('__force_display')) |
177 |
176 |
328 uicfg.autoform_section.tag_subject_of(('*', 'is_instance_of', '*'), 'generated') |
327 uicfg.autoform_section.tag_subject_of(('*', 'is_instance_of', '*'), 'generated') |
329 uicfg.autoform_section.tag_object_of(('*', 'is_instance_of', '*'), 'generated') |
328 uicfg.autoform_section.tag_object_of(('*', 'is_instance_of', '*'), 'generated') |
330 uicfg.autoform_section.tag_subject_of(('*', 'identity', '*'), 'generated') |
329 uicfg.autoform_section.tag_subject_of(('*', 'identity', '*'), 'generated') |
331 uicfg.autoform_section.tag_object_of(('*', 'identity', '*'), 'generated') |
330 uicfg.autoform_section.tag_object_of(('*', 'identity', '*'), 'generated') |
332 uicfg.autoform_section.tag_subject_of(('*', 'require_permission', '*'), 'generated') |
331 uicfg.autoform_section.tag_subject_of(('*', 'require_permission', '*'), 'generated') |
333 uicfg.autoform_section.tag_subject_of(('*', 'wf_info_for', '*'), 'generated') |
332 uicfg.autoform_section.tag_subject_of(('*', 'by_transition', '*'), 'primary') |
|
333 uicfg.autoform_section.tag_object_of(('*', 'by_transition', '*'), 'generated') |
|
334 uicfg.autoform_section.tag_object_of(('*', 'from_state', '*'), 'generated') |
|
335 uicfg.autoform_section.tag_object_of(('*', 'to_state', '*'), 'generated') |
|
336 uicfg.autoform_section.tag_subject_of(('*', 'wf_info_for', '*'), 'primary') |
334 uicfg.autoform_section.tag_object_of(('*', 'wf_info_for', '*'), 'generated') |
337 uicfg.autoform_section.tag_object_of(('*', 'wf_info_for', '*'), 'generated') |
335 uicfg.autoform_section.tag_subject_of(('*', 'for_user', '*'), 'generated') |
338 uicfg.autoform_section.tag_subject_of(('*', 'for_user', '*'), 'generated') |
336 uicfg.autoform_section.tag_object_of(('*', 'for_user', '*'), 'generated') |
339 uicfg.autoform_section.tag_object_of(('*', 'for_user', '*'), 'generated') |
337 uicfg.autoform_section.tag_subject_of(('CWPermission', 'require_group', '*'), 'primary') |
340 uicfg.autoform_section.tag_subject_of(('CWPermission', 'require_group', '*'), 'primary') |
338 uicfg.autoform_section.tag_attribute(('CWEType', 'final'), 'generated') |
341 uicfg.autoform_section.tag_attribute(('CWEType', 'final'), 'generated') |
347 uicfg.autoform_section.tag_attribute(('Bookmark', 'path'), 'primary') |
350 uicfg.autoform_section.tag_attribute(('Bookmark', 'path'), 'primary') |
348 uicfg.autoform_section.tag_subject_of(('*', 'use_email', '*'), 'generated') # inlined actually |
351 uicfg.autoform_section.tag_subject_of(('*', 'use_email', '*'), 'generated') # inlined actually |
349 uicfg.autoform_section.tag_subject_of(('*', 'primary_email', '*'), 'generic') |
352 uicfg.autoform_section.tag_subject_of(('*', 'primary_email', '*'), 'generic') |
350 |
353 |
351 uicfg.autoform_field_kwargs.tag_attribute(('RQLExpression', 'expression'), |
354 uicfg.autoform_field_kwargs.tag_attribute(('RQLExpression', 'expression'), |
352 {'widget': formwidgets.TextInput}) |
355 {'widget': fwdgs.TextInput}) |
353 uicfg.autoform_field_kwargs.tag_attribute(('Bookmark', 'path'), |
356 uicfg.autoform_field_kwargs.tag_attribute(('Bookmark', 'path'), |
354 {'widget': formwidgets.TextInput}) |
357 {'widget': fwdgs.TextInput}) |
|
358 uicfg.autoform_field_kwargs.tag_subject_of(('TrInfo', 'wf_info_for', '*'), |
|
359 {'widget': fwdgs.HiddenInput}) |
355 |
360 |
356 uicfg.autoform_is_inlined.tag_subject_of(('*', 'use_email', '*'), True) |
361 uicfg.autoform_is_inlined.tag_subject_of(('*', 'use_email', '*'), True) |
357 uicfg.autoform_is_inlined.tag_subject_of(('CWRelation', 'relation_type', '*'), True) |
362 uicfg.autoform_is_inlined.tag_subject_of(('CWRelation', 'relation_type', '*'), True) |
358 uicfg.autoform_is_inlined.tag_subject_of(('CWRelation', 'from_entity', '*'), True) |
363 uicfg.autoform_is_inlined.tag_subject_of(('CWRelation', 'from_entity', '*'), True) |
359 uicfg.autoform_is_inlined.tag_subject_of(('CWRelation', 'to_entity', '*'), True) |
364 uicfg.autoform_is_inlined.tag_subject_of(('CWRelation', 'to_entity', '*'), True) |