From 0ad3de9bf73c2e1b0c1ff0b65f17a8fac6b6eaab Mon Sep 17 00:00:00 2001 From: eqperes Date: Tue, 16 Jul 2024 11:23:06 +0200 Subject: [PATCH 1/2] populate item isolated to a separate method --- flask_appbuilder/baseviews.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/flask_appbuilder/baseviews.py b/flask_appbuilder/baseviews.py index ad1dc73795..5b11afe421 100644 --- a/flask_appbuilder/baseviews.py +++ b/flask_appbuilder/baseviews.py @@ -1222,7 +1222,7 @@ def _add(self): item = self.datamodel.obj() try: - form.populate_obj(item) + self.populate_item_from_form(form, item, True) self.pre_add(item) except Exception as e: flash(str(e), "danger") @@ -1266,7 +1266,7 @@ def _edit(self, pk): self.process_form(form, False) try: - form.populate_obj(item) + self.populate_item_from_form(form, item, False) self.pre_update(item) except Exception as e: flash(str(e), "danger") @@ -1380,6 +1380,13 @@ def is_get_mutation_allowed(self) -> bool: request.method == "GET" and self.appbuilder.app.extensions.get("csrf") ) + def populate_item_from_form(self, form, item, is_created): + """ + Populate the properties of the item to be created or updated based + on the content of the form. + """ + form.populate_obj(item) + def prefill_form(self, form, pk): """ Override this, will be called only if the current action is rendering From 83c8affabde1e124b47bcca7040e74ec0d19a9f1 Mon Sep 17 00:00:00 2001 From: eqperes Date: Tue, 16 Jul 2024 11:44:59 +0200 Subject: [PATCH 2/2] Respect black linting --- flask_appbuilder/baseviews.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask_appbuilder/baseviews.py b/flask_appbuilder/baseviews.py index 5b11afe421..0dc908c4b2 100644 --- a/flask_appbuilder/baseviews.py +++ b/flask_appbuilder/baseviews.py @@ -1382,7 +1382,7 @@ def is_get_mutation_allowed(self) -> bool: def populate_item_from_form(self, form, item, is_created): """ - Populate the properties of the item to be created or updated based + Populate the properties of the item to be created or updated based on the content of the form. """ form.populate_obj(item)