Moved the form creating logic from the post() method to the get_form() method, and applied get_form() to the post() method in FormView in the Mia core application.
This commit is contained in:
parent
8f6c8f3497
commit
35b246077c
@ -75,9 +75,7 @@ class FormView(View):
|
||||
def post(self, request: HttpRequest, *args,
|
||||
**kwargs) -> HttpResponseRedirect:
|
||||
"""Handles the POST requests."""
|
||||
post = self.request.POST.dict()
|
||||
utils.strip_post(post)
|
||||
form = self.make_form_from_post(post)
|
||||
form = self.get_form(**kwargs)
|
||||
if not form.is_valid():
|
||||
return self.form_invalid(form)
|
||||
return self.form_valid(form)
|
||||
@ -112,6 +110,7 @@ class FormView(View):
|
||||
|
||||
def get_form(self, **kwargs) -> forms.Form:
|
||||
"""Returns the form for the template."""
|
||||
if self.request.method != "POST":
|
||||
previous_post = stored_post.get_previous_post(self.request)
|
||||
if previous_post is not None:
|
||||
return self.make_form_from_post(previous_post)
|
||||
@ -119,6 +118,10 @@ class FormView(View):
|
||||
if obj is not None:
|
||||
return self.make_form_from_model(obj)
|
||||
return self.get_form_class()()
|
||||
else:
|
||||
post = self.request.POST.dict()
|
||||
utils.strip_post(post)
|
||||
return self.make_form_from_post(post)
|
||||
|
||||
def get_template_name(self) -> str:
|
||||
"""Returns the name of the template."""
|
||||
|
Loading…
Reference in New Issue
Block a user