# HG changeset patch # User Denis Laxalde # Date 1561630822 -7200 # Node ID 9f03df82f8de703db4f49d029585bb07847aea77 # Parent c96aa316d06bb56d2d78a160f94e5d08baf74943 [autoform] Fix display_fields handling This follows-up on changeset b2ceb483e056 (present in 3.25 as well), in which AutomaticEntityForm.editable_attributes() was turned into a generator. In this method, in case display_fields is not None, we previously returned a list of (rtype, role); this was changed into a yield, but the change was missing a return after the loop in order not to go through the remainder of the function. Add tests for editable_attributes() method. diff -r c96aa316d06b -r 9f03df82f8de cubicweb/web/test/unittest_views_editforms.py --- a/cubicweb/web/test/unittest_views_editforms.py Thu Jun 27 12:27:37 2019 +0200 +++ b/cubicweb/web/test/unittest_views_editforms.py Thu Jun 27 12:20:22 2019 +0200 @@ -181,6 +181,37 @@ [rschema.type for rschema, _ in mform.editable_attributes()]) + def test_editable_attributes(self): + with self.admin_access.web_request() as req: + entity = self.vreg['etypes'].etype_class('Personne')(req) + form = self.vreg['forms'].select('edition', req, entity=entity) + expected = [ + ('nom', 'subject'), + ('prenom', 'subject'), + ('sexe', 'subject'), + ('promo', 'subject'), + ('titre', 'subject'), + ('ass', 'subject'), + ('web', 'subject'), + ('tel', 'subject'), + ('fax', 'subject'), + ('datenaiss', 'subject'), + ('tzdatenaiss', 'subject'), + ('test', 'subject'), + ('description', 'subject'), + ('salary', 'subject'), + ] + self.assertEqual( + [(rschema.type, role) for rschema, role in form.editable_attributes()], + expected) + + # now with display_fields attribute set + form.display_fields = [('nom', 'subject')] + expected = [('nom', 'subject')] + self.assertEqual( + [(rschema.type, role) for rschema, role in form.editable_attributes()], + expected) + def test_inlined_relations(self): with self.admin_access.web_request() as req: with self.temporary_permissions(EmailAddress={'add': ()}): diff -r c96aa316d06b -r 9f03df82f8de cubicweb/web/views/autoform.py --- a/cubicweb/web/views/autoform.py Thu Jun 27 12:27:37 2019 +0200 +++ b/cubicweb/web/views/autoform.py Thu Jun 27 12:20:22 2019 +0200 @@ -871,6 +871,7 @@ schema = self._cw.vreg.schema for rtype, role in self.display_fields: yield (schema[rtype], role) + return if self.edited_entity.has_eid() and not self.edited_entity.cw_has_perm('update'): return action = 'update' if self.edited_entity.has_eid() else 'add'