373 # schema action (add/update/delete/read), and when such a tag is found |
371 # schema action (add/update/delete/read), and when such a tag is found |
374 # permissions checking is by-passed and supposed to be ok |
372 # permissions checking is by-passed and supposed to be ok |
375 autoform_permissions_overrides = RelationTagsSet('autoform_permissions_overrides') |
373 autoform_permissions_overrides = RelationTagsSet('autoform_permissions_overrides') |
376 |
374 |
377 class ReleditTags(NoTargetRelationTagsDict): |
375 class ReleditTags(NoTargetRelationTagsDict): |
|
376 """Associate to relation a dictionnary to control `reledit` (e.g. edition of |
|
377 attributes / relations from within views). |
|
378 |
|
379 Possible keys and associated values are: |
|
380 |
|
381 * `default_value`, alternative default value (shown when there is no value). |
|
382 |
|
383 * `default_showlabel`, when `default_value` is not specified, this boolean |
|
384 flag control wether the generated default value should contains the |
|
385 relation label or not. Will be the opposite of the `showlabel` value found |
|
386 in the `primaryview_display_ctrl` rtag by default. |
|
387 |
|
388 * `reload`, boolean, eid (to reload to) or function taking subject and |
|
389 returning bool/eid. This is useful when editing a relation (or attribute) |
|
390 that impacts the url or another parts of the current displayed |
|
391 page. Defaults to False. |
|
392 |
|
393 * `rvid`, alternative view id (as str) for relation or composite edition. |
|
394 Default is 'incontext' or 'csv' depending on the cardinality. They can |
|
395 also be statically changed by subclassing :class:`ClickAndEditFormView` |
|
396 and redefining `_one_rvid` (resp. `_many_rvid`). |
|
397 |
|
398 * `edit_target`, may be either 'rtype' (to edit the relation) or 'related' |
|
399 (to edit the related entity). This controls whether to edit the relation |
|
400 or the target entity of the relation. Currently only one-to-one relations |
|
401 support target entity edition. By default, the 'related' option is taken |
|
402 whenever the relation is composite and one-to-one. |
378 """ |
403 """ |
379 default_value: alternative default value |
404 _keys = frozenset('default_value default_showlabel reload rvid edit_target'.split()) |
380 The default value is what is shown when there is no value. |
|
381 reload: boolean, eid (to reload to) or function taking subject and returning bool/eid |
|
382 This is useful when editing a relation (or attribute) that impacts the url |
|
383 or another parts of the current displayed page. Defaults to False. |
|
384 rvid: alternative view id (as str) for relation or composite edition |
|
385 Default is 'incontext' or 'csv' depending on the cardinality. They can also be |
|
386 statically changed by subclassing ClickAndEditFormView and redefining _one_rvid |
|
387 (resp. _many_rvid). |
|
388 edit_target: 'rtype' (to edit the relation) or 'related' (to edit the related entity) |
|
389 This controls whether to edit the relation or the target entity of the relation. |
|
390 Currently only one-to-one relations support target entity edition. By default, |
|
391 the 'related' option is taken whenever the relation is composite and one-to-one. |
|
392 """ |
|
393 _keys = frozenset('default_value reload rvid edit_target'.split()) |
|
394 |
405 |
395 def tag_relation(self, key, tag): |
406 def tag_relation(self, key, tag): |
396 for tagkey in tag.iterkeys(): |
407 for tagkey in tag.iterkeys(): |
397 assert tagkey in self._keys, 'tag %r not in accepted tags: %r' % (tag, self._keys) |
408 assert tagkey in self._keys, 'tag %r not in accepted tags: %r' % (tag, self._keys) |
398 return super(ReleditTags, self).tag_relation(key, tag) |
409 return super(ReleditTags, self).tag_relation(key, tag) |
413 edittarget = None |
424 edittarget = None |
414 if not edittarget: |
425 if not edittarget: |
415 edittarget = 'related' if composite else 'rtype' |
426 edittarget = 'related' if composite else 'rtype' |
416 rtag.tag_relation((sschema, rschema, oschema, role), |
427 rtag.tag_relation((sschema, rschema, oschema, role), |
417 {'edit_target': edittarget}) |
428 {'edit_target': edittarget}) |
|
429 if not 'default_showlabel' in values: |
|
430 showlabel = primaryview_display_ctrl.get( |
|
431 sschema, rschema, oschema, role).get('showlabel', True) |
|
432 rtag.tag_relation((sschema, rschema, oschema, role), |
|
433 {'default_showlabel': not showlabel}) |
418 |
434 |
419 reledit_ctrl = ReleditTags('reledit', init_reledit_ctrl) |
435 reledit_ctrl = ReleditTags('reledit', init_reledit_ctrl) |
420 |
436 |
421 # boxes.EditBox configuration ################################################# |
437 # boxes.EditBox configuration ################################################# |
422 |
438 |