35 |
35 |
36 title = _('actions') |
36 title = _('actions') |
37 order = 2 |
37 order = 2 |
38 # class attributes below are actually stored in the uicfg module since we |
38 # class attributes below are actually stored in the uicfg module since we |
39 # don't want them to be reloaded |
39 # don't want them to be reloaded |
40 rmode = uicfg.rmode |
40 appearsin_addmenu = uicfg.actionbox_appearsin_addmenu |
41 |
41 |
42 @classmethod |
42 @classmethod |
43 def vreg_initialization_completed(cls): |
43 def vreg_initialization_completed(cls): |
44 """set default category tags for relations where it's not yet defined in |
44 """set default category tags for relations where it's not yet defined in |
45 the category relation tags |
45 the category relation tags |
46 """ |
46 """ |
47 for eschema in cls.schema.entities(): |
47 cls.appearsin_addmenu.init(cls.schema) |
48 for rschema, tschemas, role in eschema.relation_definitions(True): |
|
49 for tschema in tschemas: |
|
50 if role == 'subject': |
|
51 X, Y = eschema, tschema |
|
52 card = rschema.rproperty(X, Y, 'cardinality')[0] |
|
53 else: |
|
54 X, Y = tschema, eschema |
|
55 card = rschema.rproperty(X, Y, 'cardinality')[1] |
|
56 if not cls.rmode.get(X, rschema, Y, role): |
|
57 if card in '?1': |
|
58 # by default, suppose link mode if cardinality doesn't allow |
|
59 # more than one relation |
|
60 mode = 'link' |
|
61 elif rschema.rproperty(X, Y, 'composite') == role: |
|
62 # if self is composed of the target type, create mode |
|
63 mode = 'create' |
|
64 else: |
|
65 # link mode by default |
|
66 mode = 'link' |
|
67 cls.rmode.tag_relation(X, rschema, Y, mode, tagged=role) |
|
68 |
|
69 @classmethod |
|
70 def relation_mode(cls, rtype, etype, targettype, role='subject'): |
|
71 """return a string telling if the given relation is usually created |
|
72 to a new entity ('create' mode) or to an existant entity ('link' mode) |
|
73 """ |
|
74 return cls.rmode.etype_get(etype, rtype, role, targettype) |
|
75 |
48 |
76 def call(self, view=None, **kwargs): |
49 def call(self, view=None, **kwargs): |
77 _ = self.req._ |
50 _ = self.req._ |
78 title = _(self.title) |
51 title = _(self.title) |
79 if self.rset: |
52 if self.rset: |
155 ('object', eschema.object_relations())): |
128 ('object', eschema.object_relations())): |
156 for rschema in rschemas: |
129 for rschema in rschemas: |
157 if rschema.is_final(): |
130 if rschema.is_final(): |
158 continue |
131 continue |
159 # check the relation can be added as well |
132 # check the relation can be added as well |
160 if role == 'subject'and not rschema.has_perm(req, 'add', fromeid=entity.eid): |
133 # XXX consider autoform_permissions_overrides? |
|
134 if role == 'subject'and not rschema.has_perm(req, 'add', |
|
135 fromeid=entity.eid): |
161 continue |
136 continue |
162 if role == 'object'and not rschema.has_perm(req, 'add', toeid=entity.eid): |
137 if role == 'object'and not rschema.has_perm(req, 'add', |
|
138 toeid=entity.eid): |
163 continue |
139 continue |
164 # check the target types can be added as well |
140 # check the target types can be added as well |
165 for teschema in rschema.targets(eschema, role): |
141 for teschema in rschema.targets(eschema, role): |
166 if not self.relation_mode(rschema, eschema, teschema, role) == 'create': |
142 if not self.appearsin_addmenu.etype_get(eschema, rschema, |
|
143 role, teschema): |
167 continue |
144 continue |
168 if teschema.has_local_role('add') or teschema.has_perm(req, 'add'): |
145 if teschema.has_local_role('add') or teschema.has_perm(req, 'add'): |
169 yield rschema, teschema, role |
146 yield rschema, teschema, role |
170 |
147 |
171 |
148 |