From ee9dcda3df2111d705bb098208cacb1f5b4a665a Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Thu, 23 Aug 2018 15:38:46 +0100
Subject: [PATCH] Add the ability to pass kwargs through the transition

use notify to turn off messaging around status changes
---
 opentech/apply/funds/models/submissions.py | 7 ++++---
 opentech/apply/funds/views.py              | 1 +
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/opentech/apply/funds/models/submissions.py b/opentech/apply/funds/models/submissions.py
index 779f551c6..b0d8b7c06 100644
--- a/opentech/apply/funds/models/submissions.py
+++ b/opentech/apply/funds/models/submissions.py
@@ -176,7 +176,7 @@ class AddTransitions(models.base.ModelBase):
 
         attrs['get_actions_for_user'] = get_actions_for_user
 
-        def perform_transition(self, action, user, request=None):
+        def perform_transition(self, action, user, request=None, **kwargs):
             transition = self.get_transition(action)
             if not transition:
                 raise PermissionDenied(f'Invalid "{ action }" transition')
@@ -184,7 +184,7 @@ class AddTransitions(models.base.ModelBase):
                 action = self.phase.transitions[action]
                 raise PermissionDenied(f'You do not have permission to "{ action }"')
 
-            transition(by=user, request=request)
+            transition(by=user, request=request, **kwargs)
             self.save()
 
         attrs['perform_transition'] = perform_transition
@@ -551,8 +551,9 @@ def log_status_update(sender, **kwargs):
 
     by = kwargs['method_kwargs']['by']
     request = kwargs['method_kwargs']['request']
+    notify = kwargs['method_kwargs']['notify']
 
-    if request:
+    if request and notify:
         messenger(
             MESSAGES.TRANSITION,
             user=by,
diff --git a/opentech/apply/funds/views.py b/opentech/apply/funds/views.py
index 243b8696a..a506fc889 100644
--- a/opentech/apply/funds/views.py
+++ b/opentech/apply/funds/views.py
@@ -336,6 +336,7 @@ class ApplicantSubmissionEditView(BaseSubmissionEditView):
             transition.target,
             self.request.user,
             request=self.request,
+            notify=not created,  # Use the APPLICANT_EDIT notification
         )
 
         return HttpResponseRedirect(self.get_success_url())
-- 
GitLab