diff --git a/opentech/apply/dashboard/tests/__init__.py b/opentech/apply/dashboard/tests/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/opentech/apply/dashboard/tests/test_views.py b/opentech/apply/dashboard/tests/test_views.py index a6d3514a248b1606089ebcd54e560e65db70fb31..ac68727a29d998ad6cae16c4e2251bcc25fec4b1 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 27eae7b4e308c9cd1db349b37d27ac36b7448a7c..00be4cf44d33fdf015e995c7eb2a20284f6903fc 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 08872577538ad9ff12cb9decfce81dc236b9c92c..371798dadf0557c1c69d7d89aeae212913baaa02 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: