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