[#969169] don't display remove link in edition forms if the cardinality is 1 stable
authorStephanie Marcu <stephanie.marcu@logilab.fr>
Fri, 25 Jun 2010 11:29:48 +0200
branchstable
changeset 5835 4125a8021956
parent 5834 b8ad49864928
child 5836 e654c13b57b8
[#969169] don't display remove link in edition forms if the cardinality is 1
web/views/autoform.py
--- a/web/views/autoform.py	Thu Jun 24 16:03:57 2010 +0200
+++ b/web/views/autoform.py	Fri Jun 25 11:29:48 2010 +0200
@@ -238,13 +238,29 @@
             self.peid, self.rtype, entity.eid)
         self.render_form(i18nctx, divonclick=divonclick, **kwargs)
 
+    def _get_removejs(self):
+        """
+        Don't display the remove link in edition form if the
+        cardinality is 1. Handled in InlineEntityCreationFormView for
+        creation form.
+        """
+        entity = self._entity()
+        if isinstance(self.peid, int):
+            pentity = self._cw.entity_from_eid(self.peid)
+            petype = pentity.e_schema.type
+            rdef = entity.e_schema.rdef(self.rtype, neg_role(self.role), petype)
+            card= rdef.role_cardinality(self.role)
+            if card == '1': # don't display remove link
+                return None
+        return self.removejs and self.removejs % (
+            self.peid, self.rtype, entity.eid)
+
     def render_form(self, i18nctx, **kwargs):
         """fetch and render the form"""
         entity = self._entity()
         divid = '%s-%s-%s' % (self.peid, self.rtype, entity.eid)
         title = self.form_title(entity, i18nctx)
-        removejs = self.removejs and self.removejs % (
-            self.peid, self.rtype, entity.eid)
+        removejs = self._get_removejs()
         countkey = '%s_count' % self.rtype
         try:
             self._cw.data[countkey] += 1