Changed the _form pseudo @property to the get_form_class () method in the FormView in the Mia core application.
This commit is contained in:
parent
a2a47cdea2
commit
f932d5a0a7
@ -76,7 +76,7 @@ class FormView(View):
|
|||||||
elif obj is not None:
|
elif obj is not None:
|
||||||
form = self.make_form_from_model(obj)
|
form = self.make_form_from_model(obj)
|
||||||
else:
|
else:
|
||||||
form = self._form()
|
form = self.get_form_class()()
|
||||||
return render(self.request, self.get_template_name(), {
|
return render(self.request, self.get_template_name(), {
|
||||||
self.context_object_name: form
|
self.context_object_name: form
|
||||||
})
|
})
|
||||||
@ -104,8 +104,7 @@ class FormView(View):
|
|||||||
return redirect(str(UrlBuilder(self.get_success_url())
|
return redirect(str(UrlBuilder(self.get_success_url())
|
||||||
.query(r=self.request.GET.get("r"))))
|
.query(r=self.request.GET.get("r"))))
|
||||||
|
|
||||||
@property
|
def get_form_class(self):
|
||||||
def _form(self):
|
|
||||||
if self.form_class is None:
|
if self.form_class is None:
|
||||||
raise AttributeError("Please defined the form_class property.")
|
raise AttributeError("Please defined the form_class property.")
|
||||||
return self.form_class
|
return self.form_class
|
||||||
@ -141,12 +140,13 @@ class FormView(View):
|
|||||||
|
|
||||||
def make_form_from_post(self, post: Dict[str, str]) -> forms.Form:
|
def make_form_from_post(self, post: Dict[str, str]) -> forms.Form:
|
||||||
"""Creates and returns the form from the POST data."""
|
"""Creates and returns the form from the POST data."""
|
||||||
return self._form(post)
|
return self.get_form_class()(post)
|
||||||
|
|
||||||
def make_form_from_model(self, obj: Model) -> forms.Form:
|
def make_form_from_model(self, obj: Model) -> forms.Form:
|
||||||
"""Creates and returns the form from a data model."""
|
"""Creates and returns the form from a data model."""
|
||||||
return self._form({x: getattr(obj, x, None)
|
form_class = self.get_form_class()
|
||||||
for x in self._form.base_fields})
|
return form_class({x: getattr(obj, x, None)
|
||||||
|
for x in form_class.base_fields})
|
||||||
|
|
||||||
def fill_model_from_form(self, obj: Model, form: forms.Form) -> None:
|
def fill_model_from_form(self, obj: Model, form: forms.Form) -> None:
|
||||||
"""Fills in the data model from the form."""
|
"""Fills in the data model from the form."""
|
||||||
|
Loading…
Reference in New Issue
Block a user