# HG changeset patch # User Sylvain Thénault # Date 1273660599 -7200 # Node ID 4c53a0cb186cceaa07c6af8a6de418c2d871dd0c # Parent 2d7f135846ee54e3c6ca9e9751fc2c99b103d125 [actions box] enhance add related menu generation: don't propose to add relation of single cardinality where entity already have the relation set diff -r 2d7f135846ee -r 4c53a0cb186c web/views/actions.py --- a/web/views/actions.py Wed May 12 12:20:47 2010 +0200 +++ b/web/views/actions.py Wed May 12 12:36:39 2010 +0200 @@ -263,12 +263,15 @@ def actual_actions(self): entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) eschema = entity.e_schema - for rschema, teschema, x in self.add_related_schemas(entity): - if x == 'subject': - label = 'add %s %s %s %s' % (eschema, rschema, teschema, x) + for rschema, teschema, role in self.add_related_schemas(entity): + if rschema.role_rdef(eschema, teschema, role).role_cardinality(role) in '1?': + if entity.related(rschema, role): + continue + if role == 'subject': + label = 'add %s %s %s %s' % (eschema, rschema, teschema, role) url = self.linkto_url(entity, rschema, teschema, 'object') else: - label = 'add %s %s %s %s' % (teschema, rschema, eschema, x) + label = 'add %s %s %s %s' % (teschema, rschema, eschema, role) url = self.linkto_url(entity, rschema, teschema, 'subject') yield self.build_action(self._cw._(label), url)