258 # when there is only one item in the sub-menu, replace the sub-menu by |
258 # when there is only one item in the sub-menu, replace the sub-menu by |
259 # item's title prefixed by 'add' |
259 # item's title prefixed by 'add' |
260 menu.label_prefix = self._cw._('add') |
260 menu.label_prefix = self._cw._('add') |
261 super(AddRelatedActions, self).fill_menu(box, menu) |
261 super(AddRelatedActions, self).fill_menu(box, menu) |
262 |
262 |
|
263 def redirect_params(self, entity): |
|
264 return {'__redirectpath': entity.rest_path(), # should not be url quoted! |
|
265 '__redirectvid': self._cw.form.get('vid', '')} |
|
266 |
263 def actual_actions(self): |
267 def actual_actions(self): |
264 entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
268 entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
265 eschema = entity.e_schema |
269 eschema = entity.e_schema |
|
270 params = self.redirect_params(entity) |
266 for rschema, teschema, role in self.add_related_schemas(entity): |
271 for rschema, teschema, role in self.add_related_schemas(entity): |
267 if rschema.role_rdef(eschema, teschema, role).role_cardinality(role) in '1?': |
272 if rschema.role_rdef(eschema, teschema, role).role_cardinality(role) in '1?': |
268 if entity.related(rschema, role): |
273 if entity.related(rschema, role): |
269 continue |
274 continue |
270 if role == 'subject': |
275 if role == 'subject': |
271 label = 'add %s %s %s %s' % (eschema, rschema, teschema, role) |
276 label = 'add %s %s %s %s' % (eschema, rschema, teschema, role) |
272 url = self.linkto_url(entity, rschema, teschema, 'object') |
277 url = self.linkto_url(entity, rschema, teschema, 'object') |
273 else: |
278 else: |
274 label = 'add %s %s %s %s' % (teschema, rschema, eschema, role) |
279 label = 'add %s %s %s %s' % (teschema, rschema, eschema, role) |
275 url = self.linkto_url(entity, rschema, teschema, 'subject') |
280 url = self.linkto_url(entity, rschema, teschema, 'subject') |
276 yield self.build_action(self._cw._(label), url) |
281 yield self.build_action(self._cw._(label), url, **params) |
277 |
282 |
278 def add_related_schemas(self, entity): |
283 def add_related_schemas(self, entity): |
279 """this is actually used ui method to generate 'addrelated' actions from |
284 """this is actually used ui method to generate 'addrelated' actions from |
280 the schema. |
285 the schema. |
281 |
286 |
306 continue |
311 continue |
307 # check the target types can be added as well |
312 # check the target types can be added as well |
308 if teschema.may_have_permission('add', req): |
313 if teschema.may_have_permission('add', req): |
309 yield rschema, teschema, role |
314 yield rschema, teschema, role |
310 |
315 |
311 def linkto_url(self, entity, rtype, etype, target): |
316 def linkto_url(self, entity, rtype, etype, target, **kwargs): |
312 return self._cw.build_url('add/%s' % etype, |
317 return self._cw.build_url('add/%s' % etype, |
313 __linkto='%s:%s:%s' % (rtype, entity.eid, target), |
318 __linkto='%s:%s:%s' % (rtype, entity.eid, target), **kwargs) |
314 __redirectpath=entity.rest_path(), # should not be url quoted! |
|
315 __redirectvid=self._cw.form.get('vid', '')) |
|
316 |
319 |
317 |
320 |
318 class ViewSameCWEType(action.Action): |
321 class ViewSameCWEType(action.Action): |
319 """when displaying the schema of a CWEType, offer to list entities of that type |
322 """when displaying the schema of a CWEType, offer to list entities of that type |
320 """ |
323 """ |