71 from cubicweb.rtags import (RelationTags, RelationTagsBool, |
71 from cubicweb.rtags import (RelationTags, RelationTagsBool, |
72 RelationTagsSet, RelationTagsDict) |
72 RelationTagsSet, RelationTagsDict) |
73 from cubicweb.web import formwidgets |
73 from cubicweb.web import formwidgets |
74 |
74 |
75 |
75 |
76 def card_from_role(card, role): |
|
77 if role == 'subject': |
|
78 return card[0] |
|
79 assert role in ('object', 'sobject'), repr(role) |
|
80 return card[1] |
|
81 |
|
82 # primary view configuration ################################################## |
76 # primary view configuration ################################################## |
83 |
77 |
84 def init_primaryview_section(rtag, sschema, rschema, oschema, role): |
78 def init_primaryview_section(rtag, sschema, rschema, oschema, role): |
85 if rtag.get(sschema, rschema, oschema, role) is None: |
79 if rtag.get(sschema, rschema, oschema, role) is None: |
86 card = card_from_role(rschema.rproperty(sschema, oschema, 'cardinality'), role) |
80 rdef = rschema.rdef(sschema, oschema) |
87 composed = rschema.rproperty(sschema, oschema, 'composite') == neg_role(role) |
|
88 if rschema.final: |
81 if rschema.final: |
89 if rschema.meta or sschema.is_metadata(rschema) \ |
82 if rschema.meta or sschema.is_metadata(rschema) \ |
90 or oschema.type in ('Password', 'Bytes'): |
83 or oschema.type in ('Password', 'Bytes'): |
91 section = 'hidden' |
84 section = 'hidden' |
92 else: |
85 else: |
93 section = 'attributes' |
86 section = 'attributes' |
94 elif card in '1+': |
|
95 section = 'attributes' |
|
96 elif composed: |
|
97 section = 'relations' |
|
98 else: |
87 else: |
99 section = 'sideboxes' |
88 if rdef.role_cardinality(role) in '1+': |
|
89 section = 'attributes' |
|
90 elif rdef.composite == neg_role(role): |
|
91 section = 'relations' |
|
92 else: |
|
93 section = 'sideboxes' |
100 rtag.tag_relation((sschema, rschema, oschema, role), section) |
94 rtag.tag_relation((sschema, rschema, oschema, role), section) |
101 |
95 |
102 primaryview_section = RelationTags('primaryview_section', |
96 primaryview_section = RelationTags('primaryview_section', |
103 init_primaryview_section, |
97 init_primaryview_section, |
104 frozenset(('attributes', 'relations', |
98 frozenset(('attributes', 'relations', |
175 autoform_is_inlined.get(sschema, rschema, oschema, neg_role(role)): |
169 autoform_is_inlined.get(sschema, rschema, oschema, neg_role(role)): |
176 section = 'generated' |
170 section = 'generated' |
177 elif sschema.is_metadata(rschema): |
171 elif sschema.is_metadata(rschema): |
178 section = 'metadata' |
172 section = 'metadata' |
179 else: |
173 else: |
180 if role == 'subject': |
174 rdef = rschema.rdef(sschema, oschema) |
181 card = rschema.rproperty(sschema, oschema, 'cardinality')[0] |
175 if rdef.role_cardinality(role) in '1+': |
182 composed = rschema.rproperty(sschema, oschema, 'composite') == 'object' |
|
183 else: |
|
184 card = rschema.rproperty(sschema, oschema, 'cardinality')[1] |
|
185 composed = rschema.rproperty(sschema, oschema, 'composite') == 'subject' |
|
186 if card in '1+': |
|
187 section = 'primary' |
176 section = 'primary' |
188 elif rschema.final: |
177 elif rschema.final: |
189 section = 'secondary' |
178 section = 'secondary' |
190 else: |
179 else: |
191 section = 'generic' |
180 section = 'generic' |
215 # boxes.EditBox configuration ################################################# |
204 # boxes.EditBox configuration ################################################# |
216 |
205 |
217 # 'link' / 'create' relation tags, used to control the "add entity" submenu |
206 # 'link' / 'create' relation tags, used to control the "add entity" submenu |
218 def init_actionbox_appearsin_addmenu(rtag, sschema, rschema, oschema, role): |
207 def init_actionbox_appearsin_addmenu(rtag, sschema, rschema, oschema, role): |
219 if rtag.get(sschema, rschema, oschema, role) is None: |
208 if rtag.get(sschema, rschema, oschema, role) is None: |
220 card = rschema.rproperty(sschema, oschema, 'cardinality')[role == 'object'] |
209 rdef = rschema.rdef(sschema, oschema) |
221 if not card in '?1' and \ |
210 if not rdef.role_cardinality(role) in '?1' and rdef.composite == role: |
222 rschema.rproperty(sschema, oschema, 'composite') == role: |
|
223 rtag.tag_relation((sschema, rschema, oschema, role), True) |
211 rtag.tag_relation((sschema, rschema, oschema, role), True) |
224 |
212 |
225 actionbox_appearsin_addmenu = RelationTagsBool('actionbox_appearsin_addmenu', |
213 actionbox_appearsin_addmenu = RelationTagsBool('actionbox_appearsin_addmenu', |
226 init_actionbox_appearsin_addmenu) |
214 init_actionbox_appearsin_addmenu) |