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,
|
def post(self, request: HttpRequest, *args,
|
||||||
**kwargs) -> HttpResponseRedirect:
|
**kwargs) -> HttpResponseRedirect:
|
||||||
"""Handles the POST requests."""
|
"""Handles the POST requests."""
|
||||||
post = self.request.POST.dict()
|
form = self.get_form(**kwargs)
|
||||||
utils.strip_post(post)
|
|
||||||
form = self.make_form_from_post(post)
|
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
return self.form_valid(form)
|
return self.form_valid(form)
|
||||||
@ -112,6 +110,7 @@ class FormView(View):
|
|||||||
|
|
||||||
def get_form(self, **kwargs) -> forms.Form:
|
def get_form(self, **kwargs) -> forms.Form:
|
||||||
"""Returns the form for the template."""
|
"""Returns the form for the template."""
|
||||||
|
if self.request.method != "POST":
|
||||||
previous_post = stored_post.get_previous_post(self.request)
|
previous_post = stored_post.get_previous_post(self.request)
|
||||||
if previous_post is not None:
|
if previous_post is not None:
|
||||||
return self.make_form_from_post(previous_post)
|
return self.make_form_from_post(previous_post)
|
||||||
@ -119,6 +118,10 @@ class FormView(View):
|
|||||||
if obj is not None:
|
if obj is not None:
|
||||||
return self.make_form_from_model(obj)
|
return self.make_form_from_model(obj)
|
||||||
return self.get_form_class()()
|
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:
|
def get_template_name(self) -> str:
|
||||||
"""Returns the name of the template."""
|
"""Returns the name of the template."""
|
||||||
|
Loading…
Reference in New Issue
Block a user