Skip to content

Commit

Permalink
Fix report submit notification to stream field form flow (#4305)
Browse files Browse the repository at this point in the history
Fixes #4289
  • Loading branch information
sandeepsajan0 authored Jan 4, 2025
1 parent 1040d08 commit 9185a07
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions hypha/apply/projects/views/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,24 @@ def post(self, request, *args, **kwargs):
if form.is_valid():
form.save(form_fields=self.form_fields)
form.delete_temporary_files()

should_notify = True
if self.object.draft:
# It was a draft submission
should_notify = False
else:
if self.object.submitted != self.object.current.submitted:
# It was a staff edit - post submission
should_notify = False

if should_notify:
messenger(
MESSAGES.SUBMIT_REPORT,
request=self.request,
user=self.request.user,
source=self.object.project,
related=self.object,
)
response = HttpResponseRedirect(self.get_success_url())
else:
response = self.form_invalid(form)
Expand All @@ -170,32 +188,6 @@ def get_success_url(self):
success_url = self.object.project.get_absolute_url()
return success_url

def form_valid(self, form):
response = super().form_valid(form)

should_notify = True
if self.object.draft:
# It was a draft submission
should_notify = False
else:
if self.object.submitted != self.object.current.submitted:
# It was a staff edit - post submission
should_notify = False

if should_notify:
messenger(
MESSAGES.SUBMIT_REPORT,
request=self.request,
user=self.request.user,
source=self.object.project,
related=self.object,
)

# Required for django-file-form: delete temporary files for the new files
# that are uploaded.
form.delete_temporary_files()
return response


class ReportPrivateMedia(ReportAccessMixin, PrivateMediaView):
def dispatch(self, *args, **kwargs):
Expand Down

0 comments on commit 9185a07

Please sign in to comment.