From 5dab01e885f619fc24b17b0f9034668740bdc3e1 Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Thu, 1 Mar 2018 15:41:55 +0000
Subject: [PATCH] Log the change of state in the activity

---
 opentech/apply/funds/views.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/opentech/apply/funds/views.py b/opentech/apply/funds/views.py
index 3a1f60d24..aa7754b7d 100644
--- a/opentech/apply/funds/views.py
+++ b/opentech/apply/funds/views.py
@@ -6,6 +6,7 @@ from django_filters.views import FilterView
 from django_tables2.views import SingleTableMixin
 
 from opentech.apply.activity.views import CommentContextMixin, CommentFormView, DelegatedViewMixin
+from opentech.apply.activity.models import Activity
 
 from .forms import ProgressSubmissionForm
 from .models import ApplicationSubmission
@@ -58,7 +59,15 @@ class ProgressSubmissionView(DelegatedViewMixin, UpdateView):
     context_name = 'progress_form'
 
     def form_valid(self, form):
-        return super().form_valid(form)
+        old_phase = form.instance.phase.name
+        response = super().form_valid(form)
+        new_phase = form.instance.phase.name
+        Activity.objects.create(
+            user=self.request.user,
+            submission=self.kwargs['submission'],
+            message=f'Progressed from {old_phase} to {new_phase}'
+        )
+        return response
 
 
 class SubmissionDetailView(CommentContextMixin, ProgressContextMixin, DetailView):
-- 
GitLab