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

Fix report form, allow saving as draft without filling required fields #4428

Merged
merged 1 commit into from
Mar 5, 2025
Merged
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
21 changes: 5 additions & 16 deletions hypha/apply/projects/views/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,7 @@ class ReportUpdateView(BaseStreamForm, UpdateView):
object = None
form_class = None
form_fields = None

def get_form_class(self, draft=False, form_data=None, user=None):
"""
Expects self.form_fields to have already been set.
"""
# This is where the magic happens.
fields = self.get_form_fields(draft, form_data, user)
the_class = type(
"WagtailStreamForm",
(ReportEditForm,),
fields,
)
return the_class
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📓 This is not needed as the Parent class "BaseStreamForm" implement this function that makes use of submission_form_class class property.

submission_form_class = ReportEditForm

def dispatch(self, request, *args, **kwargs):
report = self.get_object()
Expand Down Expand Up @@ -114,7 +102,7 @@ def get_context_data(self, *args, **kwargs):
}
return context_data

def get_form(self, form_class=None):
def get_form(self, form_class=None, draft=False):
if self.object.current is None or self.object.form_fields is None:
# Here is where we get the form_fields, the ProjectReportForm associated with the Fund:
report_form = (
Expand All @@ -128,7 +116,7 @@ def get_form(self, form_class=None):
self.form_fields = self.object.form_fields

if form_class is None:
form_class = self.get_form_class()
form_class = self.get_form_class(draft=draft)
report_instance = form_class(**self.get_form_kwargs())
return report_instance

Expand Down Expand Up @@ -159,7 +147,8 @@ def get_form_kwargs(self):
return form_kwargs

def post(self, request, *args, **kwargs):
form = self.get_form()
save_draft = "save" in request.POST # clicked on save button?
form = self.get_form(draft=save_draft)
if form.is_valid():
form.save(form_fields=self.form_fields)
form.delete_temporary_files()
Expand Down
Loading