web/views/actions.py
branchstable
changeset 5521 4c53a0cb186c
parent 5426 0d4853a6e5ee
child 5527 01a7228ab5a0
child 5745 d532fe79800b
--- 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)