36 Button(stdmsgs.BUTTON_APPLY, cwaction='apply'), |
36 Button(stdmsgs.BUTTON_APPLY, cwaction='apply'), |
37 Button(stdmsgs.BUTTON_CANCEL, cwaction='cancel')] |
37 Button(stdmsgs.BUTTON_CANCEL, cwaction='cancel')] |
38 attrcategories = ('primary', 'secondary') |
38 attrcategories = ('primary', 'secondary') |
39 # class attributes below are actually stored in the uicfg module since we |
39 # class attributes below are actually stored in the uicfg module since we |
40 # don't want them to be reloaded |
40 # don't want them to be reloaded |
41 rcategories = uicfg.rcategories |
41 rcategories = uicfg.autoform_section |
42 rfields = uicfg.rfields |
42 rfields = uicfg.autoform_field |
43 rwidgets = uicfg.rwidgets |
43 rwidgets = uicfg.autoform_widget |
44 rinlined = uicfg.rinlined |
44 rinlined = uicfg.autoform_is_inlined |
45 rpermissions_overrides = uicfg.rpermissions_overrides |
45 rpermissions_overrides = uicfg.autoform_permissions_overrides |
46 |
46 |
47 @classmethod |
47 @classmethod |
48 def vreg_initialization_completed(cls): |
48 def vreg_initialization_completed(cls): |
49 """set default category tags for relations where it's not yet defined in |
49 """set default category tags for relations where it's not yet defined in |
50 the category relation tags |
50 the category relation tags |
51 """ |
51 """ |
52 for eschema in cls.schema.entities(): |
52 cls.rcategories.init(cls.schema) |
53 for rschema, tschemas, role in eschema.relation_definitions(True): |
53 cls.rfields.init(cls.schema) |
54 for tschema in tschemas: |
54 cls.rwidgets.init(cls.schema) |
55 if role == 'subject': |
55 cls.rinlined.init(cls.schema) |
56 X, Y = eschema, tschema |
56 cls.rpermissions_overrides.init(cls.schema) |
57 card = rschema.rproperty(X, Y, 'cardinality')[0] |
|
58 composed = rschema.rproperty(X, Y, 'composite') == 'object' |
|
59 else: |
|
60 X, Y = tschema, eschema |
|
61 card = rschema.rproperty(X, Y, 'cardinality')[1] |
|
62 composed = rschema.rproperty(X, Y, 'composite') == 'subject' |
|
63 if not cls.rcategories.get(X, rschema, Y, role): |
|
64 if eschema.is_metadata(rschema): |
|
65 category = 'generated' |
|
66 elif card in '1+': |
|
67 if not rschema.is_final() and composed: |
|
68 category = 'generated' |
|
69 else: |
|
70 category = 'primary' |
|
71 elif rschema.is_final(): |
|
72 category = 'secondary' |
|
73 else: |
|
74 category = 'generic' |
|
75 cls.rcategories.tag_relation(X, rschema, Y, category, |
|
76 tagged=role) |
|
77 |
57 |
78 @classmethod |
58 @classmethod |
79 def erelations_by_category(cls, entity, categories=None, permission=None, rtags=None): |
59 def erelations_by_category(cls, entity, categories=None, permission=None, |
|
60 rtags=None): |
80 """return a list of (relation schema, target schemas, role) matching |
61 """return a list of (relation schema, target schemas, role) matching |
81 categories and permission |
62 categories and permission |
82 """ |
63 """ |
83 if categories is not None: |
64 if categories is not None: |
84 if not isinstance(categories, (list, tuple, set, frozenset)): |
65 if not isinstance(categories, (list, tuple, set, frozenset)): |