81 init_primaryview_section, |
82 init_primaryview_section, |
82 frozenset(('attributes', 'relations', |
83 frozenset(('attributes', 'relations', |
83 'sideboxes', 'hidden'))) |
84 'sideboxes', 'hidden'))) |
84 |
85 |
85 |
86 |
86 class DisplayCtrlRelationTags(RelationTagsDict): |
87 class DisplayCtrlRelationTags(NoTargetRelationTagsDict): |
87 def __init__(self, *args, **kwargs): |
88 def __init__(self, *args, **kwargs): |
88 super(DisplayCtrlRelationTags, self).__init__(*args, **kwargs) |
89 super(DisplayCtrlRelationTags, self).__init__(*args, **kwargs) |
89 self.counter = 0 |
90 self.counter = 0 |
90 |
|
91 def tag_subject_of(self, key, tag): |
|
92 subj, rtype, obj = key |
|
93 if obj != '*': |
|
94 self.warning('using explict target type in display_ctrl.tag_subject_of() ' |
|
95 'has no effect, use (%s, %s, "*") instead of (%s, %s, %s)', |
|
96 subj, rtype, subj, rtype, obj) |
|
97 super(DisplayCtrlRelationTags, self).tag_subject_of((subj, rtype, '*'), tag) |
|
98 |
|
99 def tag_object_of(self, key, tag): |
|
100 subj, rtype, obj = key |
|
101 if subj != '*': |
|
102 self.warning('using explict subject type in display_ctrl.tag_object_of() ' |
|
103 'has no effect, use ("*", %s, %s) instead of (%s, %s, %s)', |
|
104 rtype, obj, subj, rtype, obj) |
|
105 super(DisplayCtrlRelationTags, self).tag_object_of(('*', rtype, obj), tag) |
|
106 |
91 |
107 def init_primaryview_display_ctrl(rtag, sschema, rschema, oschema, role): |
92 def init_primaryview_display_ctrl(rtag, sschema, rschema, oschema, role): |
108 if role == 'subject': |
93 if role == 'subject': |
109 oschema = '*' |
94 oschema = '*' |
110 else: |
95 else: |
376 |
361 |
377 # relations'field class |
362 # relations'field class |
378 autoform_field = RelationTags('autoform_field') |
363 autoform_field = RelationTags('autoform_field') |
379 |
364 |
380 # relations'field explicit kwargs (given to field's __init__) |
365 # relations'field explicit kwargs (given to field's __init__) |
381 autoform_field_kwargs = RelationTagsDict() |
366 autoform_field_kwargs = RelationTagsDict('autoform_field_kwargs') |
382 |
367 |
383 |
368 |
384 # set of tags of the form <action>_on_new on relations. <action> is a |
369 # set of tags of the form <action>_on_new on relations. <action> is a |
385 # schema action (add/update/delete/read), and when such a tag is found |
370 # schema action (add/update/delete/read), and when such a tag is found |
386 # permissions checking is by-passed and supposed to be ok |
371 # permissions checking is by-passed and supposed to be ok |
387 autoform_permissions_overrides = RelationTagsSet('autoform_permissions_overrides') |
372 autoform_permissions_overrides = RelationTagsSet('autoform_permissions_overrides') |
388 |
373 |
389 class _ReleditTags(RelationTagsDict): |
374 class ReleditTags(NoTargetRelationTagsDict): |
390 _keys = frozenset('reload default_value noedit'.split()) |
375 """ |
391 |
376 default_value: alternative default value |
392 def tag_subject_of(self, key, *args, **kwargs): |
377 The default value is what is shown when there is no value. |
393 subj, rtype, obj = key |
378 reload: boolean, eid (to reload to) or function taking subject and returning bool/eid |
394 if obj != '*': |
379 This is useful when editing a relation (or attribute) that impacts the url |
395 self.warning('using explict target type in display_ctrl.tag_subject_of() ' |
380 or another parts of the current displayed page. Defaults to False. |
396 'has no effect, use (%s, %s, "*") instead of (%s, %s, %s)', |
381 rvid: alternative view id (as str) for relation or composite edition |
397 subj, rtype, subj, rtype, obj) |
382 Default is 'incontext' or 'csv' depending on the cardinality. They can also be |
398 super(_ReleditTags, self).tag_subject_of(key, *args, **kwargs) |
383 statically changed by subclassing ClickAndEditFormView and redefining _one_rvid |
399 |
384 (resp. _many_rvid). |
400 def tag_object_of(self, key, *args, **kwargs): |
385 edit_target: 'rtype' (to edit the relation) or 'related' (to edit the related entity) |
401 subj, rtype, obj = key |
386 This controls whether to edit the relation or the target entity of the relation. |
402 if subj != '*': |
387 Currently only one-to-one relations support target entity edition. By default, |
403 self.warning('using explict subject type in display_ctrl.tag_object_of() ' |
388 the 'related' option is taken whenever the relation is composite and one-to-one. |
404 'has no effect, use ("*", %s, %s) instead of (%s, %s, %s)', |
389 """ |
405 rtype, obj, subj, rtype, obj) |
390 _keys = frozenset('default_value reload rvid edit_target'.split()) |
406 super(_ReleditTags, self).tag_object_of(key, *args, **kwargs) |
|
407 |
391 |
408 def tag_relation(self, key, tag): |
392 def tag_relation(self, key, tag): |
409 for tagkey in tag.iterkeys(): |
393 for tagkey in tag.iterkeys(): |
410 assert tagkey in self._keys, 'tag %r not in accepted tags: %r' % (tag, self._keys) |
394 assert tagkey in self._keys, 'tag %r not in accepted tags: %r' % (tag, self._keys) |
411 return super(_ReleditTags, self).tag_relation(key, tag) |
395 return super(ReleditTags, self).tag_relation(key, tag) |
412 |
396 |
413 reledit_ctrl = _ReleditTags('reledit') |
397 def init_reledit_ctrl(rtag, sschema, rschema, oschema, role): |
|
398 if rschema.final: |
|
399 return |
|
400 composite = rschema.rdef(sschema, oschema).composite == role |
|
401 if role == 'subject': |
|
402 oschema = '*' |
|
403 else: |
|
404 sschema = '*' |
|
405 values = rtag.get(sschema, rschema, oschema, role) |
|
406 edittarget = values.get('edit_target') |
|
407 if edittarget not in (None, 'rtype', 'related'): |
|
408 rtag.warning('reledit: wrong value for edit_target on relation %s: %s', |
|
409 rschema, edittarget) |
|
410 edittarget = None |
|
411 if not edittarget: |
|
412 edittarget = 'related' if composite else 'rtype' |
|
413 rtag.tag_relation((sschema, rschema, oschema, role), |
|
414 {'edit_target': edittarget}) |
|
415 |
|
416 reledit_ctrl = ReleditTags('reledit', init_reledit_ctrl) |
414 |
417 |
415 # boxes.EditBox configuration ################################################# |
418 # boxes.EditBox configuration ################################################# |
416 |
419 |
417 # 'link' / 'create' relation tags, used to control the "add entity" submenu |
420 # 'link' / 'create' relation tags, used to control the "add entity" submenu |
418 def init_actionbox_appearsin_addmenu(rtag, sschema, rschema, oschema, role): |
421 def init_actionbox_appearsin_addmenu(rtag, sschema, rschema, oschema, role): |