Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: isolate populate_obj in a separate method so that it can be easily overriden #2260

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions flask_appbuilder/baseviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
Loading