Updated AJAX decorator
authorThierry Florac <thierry.florac@onf.fr>
Tue, 12 Jun 2018 10:49:14 +0200
changeset 115 0d6b79be4eb1
parent 114 883695a5bf7f
child 116 bf60719e676c
Updated AJAX decorator
src/pyams_form/form.py
--- a/src/pyams_form/form.py	Tue Jun 12 10:47:03 2018 +0200
+++ b/src/pyams_form/form.py	Tue Jun 12 10:49:14 2018 +0200
@@ -722,8 +722,15 @@
             new_class = type('AJAX' + ob.__name__, (base, ob), cdict)
             try:
                 # check if current form is overriding "get_ajax_output" method
-                if not ob.get_ajax_output.__qualname__.startswith('AJAXForm.'):  # redefined method
-                    new_class.get_ajax_output = ob.get_ajax_output
+                if base not in (AJAXAddForm, AJAXEditForm):  # custom base
+                    basename = base.__qualname__
+                    baseklassname, _ = base.get_ajax_output.__qualname__.split('.')
+                    if baseklassname != basename:  # overriden method
+                        new_class.get_ajax_output = ob.get_ajax_output
+                else:
+                    baseklassname, _ = ob.get_ajax_output.__qualname__.split('.')
+                    if baseklassname not in ('AJAXForm', 'AJAXEditForm'):  # overriden method
+                        new_class.get_ajax_output = ob.get_ajax_output
             except AttributeError:
                 pass