# HG changeset patch # User Stephanie Marcu # Date 1277458188 -7200 # Node ID 4125a8021956089fd1421f77be39e0c5c72c0608 # Parent b8ad49864928b0d9bad370b08c494579584d9056 [#969169] don't display remove link in edition forms if the cardinality is 1 diff -r b8ad49864928 -r 4125a8021956 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