From 03bd0a9c9aae996d1fbf2c756f8b26154d41d7dc Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Thu, 21 Jun 2018 19:02:01 +0100
Subject: [PATCH] Make sure that the applicant see the draft details on the
 homepage

---
 opentech/apply/dashboard/tests/__init__.py   |  0
 opentech/apply/dashboard/tests/test_views.py | 12 +++++++++++-
 opentech/apply/dashboard/views.py            | 12 ++++++++++--
 opentech/apply/funds/views.py                |  4 +---
 4 files changed, 22 insertions(+), 6 deletions(-)
 create mode 100644 opentech/apply/dashboard/tests/__init__.py

diff --git a/opentech/apply/dashboard/tests/__init__.py b/opentech/apply/dashboard/tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/opentech/apply/dashboard/tests/test_views.py b/opentech/apply/dashboard/tests/test_views.py
index a6d3514a2..ac68727a2 100644
--- a/opentech/apply/dashboard/tests/test_views.py
+++ b/opentech/apply/dashboard/tests/test_views.py
@@ -1,4 +1,4 @@
-from opentech.apply.funds.tests.factories import ApplicationSubmissionFactory
+from opentech.apply.funds.tests.factories import ApplicationSubmissionFactory, ApplicationRevisionFactory
 from opentech.apply.users.tests.factories import UserFactory
 from opentech.apply.utils.tests import BaseViewTestCase
 
@@ -14,6 +14,16 @@ class TestApplicantDashboard(BaseViewTestCase):
         self.assertContains(response, application.title)
         self.assertNotContains(response, 'Submission history')
 
+    def test_can_has_draft_titles_on_dashboard(self):
+        submission = ApplicationSubmissionFactory(user=self.user)
+        draft_revision = ApplicationRevisionFactory(submission=submission)
+        submission.draft_revision = draft_revision
+        submission.save()
+        response = self.get_page()
+        self.assertNotContains(response, submission.title)
+        self.assertContains(response, submission.from_draft().title)
+        self.assertNotContains(response, 'Submission history')
+
     def test_can_not_access_other_users_active(self):
         application = ApplicationSubmissionFactory(form_data__title='Ruin the internet')
         response = self.get_page()
diff --git a/opentech/apply/dashboard/views.py b/opentech/apply/dashboard/views.py
index 27eae7b4e..00be4cf44 100644
--- a/opentech/apply/dashboard/views.py
+++ b/opentech/apply/dashboard/views.py
@@ -20,10 +20,18 @@ class ApplicantDashboardView(SingleTableView):
     table_class = SubmissionsTable
 
     def get_queryset(self):
-        return self.model.objects.filter(user=self.request.user).inactive().current()
+        return self.model.objects.filter(
+            user=self.request.user
+        ).inactive().current()
 
     def get_context_data(self, **kwargs):
-        my_active_submissions = self.model.objects.filter(user=self.request.user).active().current()
+        my_active_submissions = self.model.objects.filter(
+            user=self.request.user
+        ).active().current().select_related('draft_revision')
+
+        my_active_submissions = [
+            submission.from_draft() for submission in my_active_submissions
+        ]
 
         return super().get_context_data(
             my_active_submissions=my_active_submissions,
diff --git a/opentech/apply/funds/views.py b/opentech/apply/funds/views.py
index 088725775..371798dad 100644
--- a/opentech/apply/funds/views.py
+++ b/opentech/apply/funds/views.py
@@ -168,9 +168,7 @@ class ApplicantSubmissionDetailView(ActivityContextMixin, DelegateableView):
     form_views = [CommentFormView]
 
     def get_object(self):
-        object = super().get_object()
-        object = object.from_draft()
-        return object
+        return super().get_object().from_draft()
 
     def dispatch(self, request, *args, **kwargs):
         if self.get_object().user != request.user:
-- 
GitLab