[autoform] Make RelationField.fromcardinality a class method factory 3.26
authorDenis Laxalde <denis.laxalde@logilab.fr>
Wed, 22 Aug 2018 16:04:39 +0200
branch3.26
changeset 12348 6bcdd7278f7f
parent 12347 cb05926a99d0
child 12349 7e670235174f
[autoform] Make RelationField.fromcardinality a class method factory Instead of having the "RelationField" class hard-coded in this factory method (thus preventing any subclass to properly use it), we make that method a classmethod and instantiate the actual class instead of the base one.
cubicweb/web/formfields.py
--- a/cubicweb/web/formfields.py	Wed Aug 22 16:02:30 2018 +0200
+++ b/cubicweb/web/formfields.py	Wed Aug 22 16:04:39 2018 +0200
@@ -1074,10 +1074,10 @@
     :class:`~cubicweb.web.formwidgets.Select`.
     """
 
-    @staticmethod
-    def fromcardinality(card, **kwargs):
+    @classmethod
+    def fromcardinality(cls, card, **kwargs):
         kwargs.setdefault('widget', fw.Select(multiple=card in '*+'))
-        return RelationField(**kwargs)
+        return cls(**kwargs)
 
     def choices(self, form, limit=None):
         """Take care, choices function for relation field instance should take