Skip to content

Commit e8140f7

Browse files
authored
populate item isolated to a separate method
1 parent 2d527aa commit e8140f7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

flask_appbuilder/baseviews.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ def _add(self):
12221222
item = self.datamodel.obj()
12231223

12241224
try:
1225-
form.populate_obj(item)
1225+
self.populate_item_from_form(form, item, True)
12261226
self.pre_add(item)
12271227
except Exception as e:
12281228
flash(str(e), "danger")
@@ -1266,7 +1266,7 @@ def _edit(self, pk):
12661266
self.process_form(form, False)
12671267

12681268
try:
1269-
form.populate_obj(item)
1269+
self.populate_item_from_form(form, item, False)
12701270
self.pre_update(item)
12711271
except Exception as e:
12721272
flash(str(e), "danger")
@@ -1380,6 +1380,13 @@ def is_get_mutation_allowed(self) -> bool:
13801380
request.method == "GET" and self.appbuilder.app.extensions.get("csrf")
13811381
)
13821382

1383+
def populate_item_from_form(self, form, item, is_created):
1384+
"""
1385+
Populate the properties of the item to be created or updated based
1386+
on the content of the form.
1387+
"""
1388+
form.populate_obj(item)
1389+
13831390
def prefill_form(self, form, pk):
13841391
"""
13851392
Override this, will be called only if the current action is rendering

0 commit comments

Comments
 (0)