[autoform] Fix display_fields handling 3.26
authorDenis Laxalde <denis.laxalde@logilab.fr>
Thu, 27 Jun 2019 12:20:22 +0200
branch3.26
changeset 12677 9f03df82f8de
parent 12676 c96aa316d06b
child 12678 4531a266f8b2
[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.
cubicweb/web/test/unittest_views_editforms.py
cubicweb/web/views/autoform.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': ()}):
--- 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'