[PATCH 3.26 v2] [autoform] Fix display_fields handling

Denis Laxalde denis.laxalde at logilab.fr
Thu Jun 27 15:44:11 CEST 2019


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1561630822 -7200
#      jeu. juin 27 12:20:22 2019 +0200
# Branch 3.26
# Node ID 9f03df82f8de703db4f49d029585bb07847aea77
# Parent  c96aa316d06bb56d2d78a160f94e5d08baf74943
# Available At https://hg.logilab.org/review/cubicweb
#              hg pull https://hg.logilab.org/review/cubicweb -r 9f03df82f8de
[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 --git a/cubicweb/web/test/unittest_views_editforms.py b/cubicweb/web/test/unittest_views_editforms.py
--- a/cubicweb/web/test/unittest_views_editforms.py
+++ b/cubicweb/web/test/unittest_views_editforms.py
@@ -181,6 +181,37 @@ class AutomaticEntityFormTC(CubicWebTC):
                              [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 --git a/cubicweb/web/views/autoform.py b/cubicweb/web/views/autoform.py
--- a/cubicweb/web/views/autoform.py
+++ b/cubicweb/web/views/autoform.py
@@ -871,6 +871,7 @@ class AutomaticEntityForm(forms.EntityFi
             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'



More information about the cubicweb-devel mailing list