Skip to content

Commit

Permalink
Do not depend on the text search for next transition
Browse files Browse the repository at this point in the history
  • Loading branch information
theskumar committed Nov 16, 2024
1 parent ae340d1 commit def0e76
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions hypha/apply/funds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1284,13 +1284,6 @@ class BaseSubmissionEditView(UpdateView):

model = ApplicationSubmission

@property
def transitions(self):
transitions = self.object.get_available_user_status_transitions(
self.request.user
)
return {transition.name: transition for transition in transitions}

def render_preview(self, request: HttpRequest, form: BaseModelForm) -> HttpResponse:
"""Gets a rendered preview of a form
Expand Down Expand Up @@ -1363,7 +1356,6 @@ def form_valid(self, form: BaseModelForm) -> HttpResponse:
Returns:
An `HttpResponse` depending on the actions taken in the edit view
"""

self.object.form_data = form.cleaned_data

is_draft = self.object.status == DRAFT_STATE
Expand Down Expand Up @@ -1394,6 +1386,7 @@ def form_valid(self, form: BaseModelForm) -> HttpResponse:
user=self.request.user,
source=self.object,
)

elif revision and not self.object.status == DRAFT_STATE:
messenger(
MESSAGES.APPLICANT_EDIT,
Expand All @@ -1403,18 +1396,25 @@ def form_valid(self, form: BaseModelForm) -> HttpResponse:
related=revision,
)

action = set(self.request.POST.keys()) & set(self.transitions.keys())
try:
transition = self.transitions[action.pop()]
except KeyError:
pass
else:
# Get the transition corresponding to the object's current phase name
transitions = self.object.get_available_user_status_transitions(
self.request.user
)
transition = next(
(t for t in transitions if t.source == self.object.phase.name),
None,
)
if transition:
# Only notify for initial submission or drafts
notify = (
not (revision or submitting_proposal)
or self.object.status == DRAFT_STATE
)
self.object.perform_transition(
transition.target,
self.request.user,
request=self.request,
notify=not (revision or submitting_proposal)
or self.object.status == DRAFT_STATE, # Use the other notification
notify=notify,
)

# Required for django-file-form: delete temporary files for the new files
Expand Down

0 comments on commit def0e76

Please sign in to comment.