[actions box] enhance add related menu generation: don't propose to add relation of single cardinality where entity already have the relation set stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 12 May 2010 12:36:39 +0200
branchstable
changeset 5521 4c53a0cb186c
parent 5520 2d7f135846ee
child 5522 6be95896d49e
[actions box] enhance add related menu generation: don't propose to add relation of single cardinality where entity already have the relation set
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)