From 489a9b732dbd0bf8938398f506ff752842b2c585 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Thu, 20 Dec 2018 11:15:56 +0000 Subject: [PATCH] Add in the submission by round page --- opentech/apply/funds/models/applications.py | 4 ++ .../templates/funds/submissions_by_round.html | 22 +++++++++++ opentech/apply/funds/tests/test_views.py | 38 +++++++++++++++++++ opentech/apply/funds/urls.py | 2 + opentech/apply/funds/views.py | 20 +++++++++- 5 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 opentech/apply/funds/templates/funds/submissions_by_round.html diff --git a/opentech/apply/funds/models/applications.py b/opentech/apply/funds/models/applications.py index 62a6e13fa..01a754b17 100644 --- a/opentech/apply/funds/models/applications.py +++ b/opentech/apply/funds/models/applications.py @@ -158,6 +158,10 @@ class RoundBase(WorkflowStreamForm, SubmittableStreamForm): # type: ignore # Make sure all children use the shared template return 'funds/round_landing.html' + @cached_property + def fund(self): + return self.get_parent() + @property def is_sealed(self): return self.sealed and self.is_open diff --git a/opentech/apply/funds/templates/funds/submissions_by_round.html b/opentech/apply/funds/templates/funds/submissions_by_round.html new file mode 100644 index 000000000..2e4391d16 --- /dev/null +++ b/opentech/apply/funds/templates/funds/submissions_by_round.html @@ -0,0 +1,22 @@ +{% extends "base-apply.html" %} +{% block title %}{{ object }}{% endblock %} + +{% block content %} +<div class="admin-bar"> + <div class="admin-bar__inner"> + <div> + <h5><a href="{% url "apply:submissions:list" %}">< Submissions</a></h5> + <h1 class="gamma heading heading--no-margin heading--bold">{{ object }}</h1> + <h5>{% if object.fund %}{{ object.fund }} | {% endif %}Lead: {{ object.lead }}</h5> + </div> + </div> +</div> + +<div class="wrapper wrapper--large"> + <div> + <h2>THERE WILL BE A TABLE HERE</h2> + </div> + +</div> + +{% endblock %} diff --git a/opentech/apply/funds/tests/test_views.py b/opentech/apply/funds/tests/test_views.py index 62c1c7928..5f6643b3b 100644 --- a/opentech/apply/funds/tests/test_views.py +++ b/opentech/apply/funds/tests/test_views.py @@ -7,7 +7,9 @@ from opentech.apply.funds.tests.factories import ( ApplicationSubmissionFactory, ApplicationRevisionFactory, InvitedToProposalFactory, + LabFactory, LabSubmissionFactory, + RoundFactory, SealedRoundFactory, SealedSubmissionFactory, ) @@ -547,3 +549,39 @@ class TestSuperUserSealedView(BaseSubmissionViewTestCase): self.assertTrue('peeked' in self.client.session) self.assertTrue(str(first.id) in self.client.session['peeked']) self.assertTrue(str(second.id) in self.client.session['peeked']) + + +class ByRoundTestCase(BaseViewTestCase): + url_name = 'apply:submissions:{}' + base_view_name = 'by_round' + + def get_kwargs(self, instance): + return {'pk': instance.id} + + +class TestStaffSubmissionByRound(ByRoundTestCase): + user_factory = StaffFactory + + def test_can_access_round_page(self): + new_round = RoundFactory() + response = self.get_page(new_round) + self.assertContains(response, new_round.title) + + def test_can_access_lab_page(self): + new_lab = LabFactory() + response = self.get_page(new_lab) + self.assertContains(response, new_lab.title) + + +class TestApplicantSubmissionByRound(ByRoundTestCase): + user_factory = UserFactory + + def test_cant_access_round_page(self): + new_round = RoundFactory() + response = self.get_page(new_round) + self.assertEqual(response.status_code, 403) + + def test_cant_access_lab_page(self): + new_lab = LabFactory() + response = self.get_page(new_lab) + self.assertEqual(response.status_code, 403) diff --git a/opentech/apply/funds/urls.py b/opentech/apply/funds/urls.py index 4e6d71099..d9f290724 100644 --- a/opentech/apply/funds/urls.py +++ b/opentech/apply/funds/urls.py @@ -3,6 +3,7 @@ from django.urls import include, path from .views import ( RevisionCompareView, RevisionListView, + SubmissionsByRound, SubmissionDetailView, SubmissionEditView, SubmissionListView, @@ -31,6 +32,7 @@ submission_urls = ([ path('', include('opentech.apply.determinations.urls', namespace="determinations")), path('revisions/', include(revision_urls, namespace="revisions")), ])), + path('rounds/<int:pk>/', SubmissionsByRound.as_view(), name="by_round"), ], 'submissions') diff --git a/opentech/apply/funds/views.py b/opentech/apply/funds/views.py index c8a6f2c13..b96a1fbe1 100644 --- a/opentech/apply/funds/views.py +++ b/opentech/apply/funds/views.py @@ -3,7 +3,7 @@ from copy import copy from django.contrib.auth.decorators import login_required from django.contrib import messages from django.core.exceptions import PermissionDenied -from django.http import HttpResponseRedirect +from django.http import HttpResponseRedirect, Http404 from django.shortcuts import get_object_or_404 from django.urls import reverse_lazy from django.utils.decorators import method_decorator @@ -14,6 +14,8 @@ from django.views.generic import DetailView, ListView, UpdateView from django_filters.views import FilterView from django_tables2.views import SingleTableMixin +from wagtail.core.models import Page + from opentech.apply.activity.views import ( AllActivityContextMixin, ActivityContextMixin, @@ -28,7 +30,7 @@ from opentech.apply.utils.views import DelegateableView, ViewDispatcher from .differ import compare from .forms import ProgressSubmissionForm, UpdateReviewersForm, UpdateSubmissionLeadForm -from .models import ApplicationSubmission, ApplicationRevision +from .models import ApplicationSubmission, ApplicationRevision, RoundBase, LabBase from .tables import AdminSubmissionsTable, SubmissionFilter, SubmissionFilterAndSearch from .workflow import STAGE_CHANGE_ACTIONS @@ -418,3 +420,17 @@ class RevisionCompareView(DetailView): to_revision = self.object.revisions.get(id=self.kwargs['to']) self.compare_revisions(from_revision, to_revision) return super().get_context_data(**kwargs) + + +@method_decorator(staff_required, name='dispatch') +class SubmissionsByRound(DetailView): + model = Page + template_name = 'funds/submissions_by_round.html' + + def get_object(self): + # We want to only show lab or Rounds in this view, their base class is Page + obj = super().get_object() + obj = obj.specific + if not isinstance(obj, (LabBase, RoundBase)): + raise Http404(_("No Round or Lab found matching the query")) + return obj -- GitLab