From 2dcc313aabbfbd4a70288ad9283d970cc1fcc44b Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson <frjo@xdeb.org> Date: Wed, 26 Jun 2024 17:40:42 +0200 Subject: [PATCH] Delete unused overview views for submissions and projects. (#4003) --- .../templates/funds/submissions_overview.html | 34 ------- hypha/apply/funds/views.py | 65 +------------ .../application_projects/overview.html | 82 ----------------- hypha/apply/projects/tests/test_views.py | 24 ----- hypha/apply/projects/views/__init__.py | 2 - hypha/apply/projects/views/project.py | 91 +------------------ 6 files changed, 5 insertions(+), 293 deletions(-) delete mode 100644 hypha/apply/funds/templates/funds/submissions_overview.html delete mode 100644 hypha/apply/projects/templates/application_projects/overview.html diff --git a/hypha/apply/funds/templates/funds/submissions_overview.html b/hypha/apply/funds/templates/funds/submissions_overview.html deleted file mode 100644 index 65d7fe64e..000000000 --- a/hypha/apply/funds/templates/funds/submissions_overview.html +++ /dev/null @@ -1,34 +0,0 @@ -{% extends "funds/base_submissions_table.html" %} -{% load render_table from django_tables2 %} -{% load i18n %} -{% block title %}{% trans "Submissions" %}{% endblock %} - -{% block content %} - - {% adminbar %} - {% slot header %}{% trans "Submissions" %}{% endslot %} - {% slot sub_heading %}{% trans "Track and explore recent submissions" %}{% endslot %} - - {% endadminbar %} - - <div class="wrapper wrapper--large wrapper--inner-space-medium"> - - {% include "funds/includes/status-block.html" with type="Applications" %} - - {% if closed_rounds or open_rounds %} - {% include "funds/includes/round-block.html" with can_export=can_export closed_rounds=closed_rounds open_rounds=open_rounds title=rounds_title page_type='submission' %} - {% endif %} - - {% block table %} - <div class="wrapper wrapper--bottom-space"> - {% trans "All Submissions" as all_submissions %} - {% include "funds/includes/table_filter_and_search.html" with filter_form=filter_form search_term=search_term use_search=True filter_action=filter_action search_action=search_action use_batch_actions=False heading=all_submissions %} - - {% render_table table %} - <div class="all-submissions-table__more"> - <a href="{% url 'apply:submissions:list' %}">{% trans "Show all" %}</a> - </div> - </div> - {% endblock %} - </div> -{% endblock %} diff --git a/hypha/apply/funds/views.py b/hypha/apply/funds/views.py index 01295cd50..083ce3db8 100644 --- a/hypha/apply/funds/views.py +++ b/hypha/apply/funds/views.py @@ -11,7 +11,7 @@ from django.contrib.auth.mixins import UserPassesTestMixin from django.contrib.auth.models import Group from django.contrib.humanize.templatetags.humanize import intcomma from django.core.exceptions import PermissionDenied -from django.db.models import Count, F, Q +from django.db.models import Count, Q from django.forms import BaseModelForm from django.http import ( FileResponse, @@ -122,7 +122,6 @@ from .tables import ( StaffAssignmentsTable, SubmissionFilterAndSearch, SubmissionReviewerFilterAndSearch, - SummarySubmissionsTable, ) from .utils import ( export_submissions_to_csv, @@ -453,68 +452,6 @@ class AwaitingReviewSubmissionsListView(SingleTableMixin, ListView): return submissions.for_table(self.request.user) -@method_decorator(staff_required, name="dispatch") -class SubmissionOverviewView(BaseAdminSubmissionsTable): - template_name = "funds/submissions_overview.html" - table_class = SummarySubmissionsTable - table_pagination = False - filter_action = reverse_lazy("funds:submissions:list") - search_action = reverse_lazy("funds:submissions:list") - - def get_table_data(self): - limit = 5 - return ( - super() - .get_table_data() - .order_by(F("last_update").desc(nulls_last=True))[:limit] - ) - - def get_context_data(self, **kwargs): - limit = 6 - base_query = ( - RoundsAndLabs.objects.with_progress().active().order_by("-end_date") - ) - can_export = can_export_submissions(self.request.user) - open_rounds = base_query.open()[:limit] - open_query = "?round_state=open" - closed_rounds = base_query.closed()[:limit] - closed_query = "?round_state=closed" - rounds_title = "All Rounds and Labs" - - status_counts = dict( - ApplicationSubmission.objects.current() - .values("status") - .annotate( - count=Count("status"), - ) - .values_list("status", "count") - ) - - grouped_statuses = { - status: { - "name": data["name"], - "count": sum( - status_counts.get(status, 0) for status in data["statuses"] - ), - "url": reverse_lazy( - "funds:submissions:status", kwargs={"status": status} - ), - } - for status, data in PHASES_MAPPING.items() - } - - return super().get_context_data( - open_rounds=open_rounds, - open_query=open_query, - can_export=can_export, - closed_rounds=closed_rounds, - closed_query=closed_query, - rounds_title=rounds_title, - status_counts=grouped_statuses, - **kwargs, - ) - - class SubmissionAdminListView(BaseAdminSubmissionsTable, DelegateableListView): template_name = "funds/submissions.html" form_views = [ diff --git a/hypha/apply/projects/templates/application_projects/overview.html b/hypha/apply/projects/templates/application_projects/overview.html deleted file mode 100644 index 7e7408837..000000000 --- a/hypha/apply/projects/templates/application_projects/overview.html +++ /dev/null @@ -1,82 +0,0 @@ -{% extends "base-apply.html" %} - -{% load render_table from django_tables2 %} -{% load i18n static %} - -{% block title %}{% trans "Projects" %}{% endblock %} - -{% block extra_css %} - <link rel="stylesheet" href="{% static 'css/fancybox.css' %}"> - {{ projects.filterset.form.media.css }} -{% endblock %} - -{% block content %} - - {% adminbar %} - {% slot header %}{% trans "Projects" %}{% endslot %} - {% slot sub_heading %} {% trans "Track and explore recent projects" %} {% endslot %} - {% endadminbar %} - - - <div class="wrapper wrapper--large wrapper--inner-space-medium"> - - {% include "funds/includes/status-block.html" with type="Projects" %} - - {% if projects.table.data %} - <div class="wrapper wrapper--bottom-space"> - - {% trans "Projects" as heading %} - {% include "funds/includes/table_filter_and_search.html" with filter=projects.filterset filter_action=projects.url search_term=search_term search_placeholder=heading search_action=projects.url use_search=True use_batch_actions=False heading=heading %} - - {% render_table projects.table %} - - <div class="all-submissions-table__more"> - <a href="{{ projects.url }}">{% trans "Show all" %}</a> - </div> - - </div> - {% endif %} - {% if invoices.table.data %} - <div class="wrapper wrapper--bottom-space"> - - {% trans "Project Invoices" as heading %} - {% include "funds/includes/table_filter_and_search.html" with filter=invoices.filterset filter_action=invoices.url heading=heading %} - - {% render_table invoices.table %} - - <div class="all-submissions-table__more"> - <a href="{{ invoices.url }}">{% trans "Show all" %}</a> - </div> - - </div> - {% endif %} - - {% if reports.table.data %} - <div class="wrapper wrapper--bottom-space"> - - {% trans "Reports" as heading %} - {% include "funds/includes/table_filter_and_search.html" with filter=reports.filterset filter_action=reports.url heading=heading filter_classes="filters--dates" %} - - {% render_table reports.table %} - - <div class="all-submissions-table__more"> - <a href="{{ reports.url }}">{% trans "Show all" %}</a> - </div> - - </div> - {% endif %} - </div> - -{% endblock %} - -{% block extra_js %} - {{ projects.filterset.form.media.js }} - <script src="{% static 'js/jquery.fancybox.min.js' %}"></script> - <script src="{% static 'js/fancybox-global.js' %}"></script> - <script src="{% static 'js/all-submissions-table.js' %}"></script> - <script src="{% static 'js/symbol-es6.min.js' %}"></script> - <script src="{% static 'js/url-search-params.js' %}"></script> - <script src="{% static 'js/submission-filters.js' %}"></script> - <script src="{% static 'js/tabs.js' %}"></script> - <script src="{% static 'js/batch-actions.js' %}"></script> -{% endblock %} diff --git a/hypha/apply/projects/tests/test_views.py b/hypha/apply/projects/tests/test_views.py index c3b885ebb..d5cbadf65 100644 --- a/hypha/apply/projects/tests/test_views.py +++ b/hypha/apply/projects/tests/test_views.py @@ -1188,30 +1188,6 @@ class TestProjectListView(TestCase): self.assertEqual(response.status_code, 403) -class TestProjectOverviewView(TestCase): - def test_staff_can_access(self): - ProjectFactory(status=CONTRACTING) - ProjectFactory(status=INVOICING_AND_REPORTING) - - self.client.force_login(StaffFactory()) - - url = reverse("apply:projects:overview") - - response = self.client.get(url, follow=True) - self.assertEqual(response.status_code, 200) - - def test_applicants_cannot_access(self): - ProjectFactory(status=CONTRACTING) - ProjectFactory(status=INVOICING_AND_REPORTING) - - self.client.force_login(UserFactory()) - - url = reverse("apply:projects:overview") - - response = self.client.get(url, follow=True) - self.assertEqual(response.status_code, 403) - - class TestStaffSubmitReport(BaseViewTestCase): base_view_name = "edit" url_name = "funds:projects:reports:{}" diff --git a/hypha/apply/projects/views/__init__.py b/hypha/apply/projects/views/__init__.py index d66746dda..0d53a3676 100644 --- a/hypha/apply/projects/views/__init__.py +++ b/hypha/apply/projects/views/__init__.py @@ -20,7 +20,6 @@ from .project import ( ProjectDetailView, ProjectFormEditView, ProjectListView, - ProjectOverviewView, ProjectPrivateMediaView, ProjectSOWDownloadView, ProjectSOWView, @@ -72,7 +71,6 @@ __all__ = [ "ProjectSOWDownloadView", "ProjectFormEditView", "ProjectListView", - "ProjectOverviewView", "ReportDetailView", "ReportUpdateView", "ReportPrivateMedia", diff --git a/hypha/apply/projects/views/project.py b/hypha/apply/projects/views/project.py index d4f90b5af..50efccccc 100644 --- a/hypha/apply/projects/views/project.py +++ b/hypha/apply/projects/views/project.py @@ -9,11 +9,11 @@ from django.contrib.auth.mixins import UserPassesTestMixin from django.contrib.auth.models import Group from django.core.exceptions import ObjectDoesNotExist, PermissionDenied from django.db import transaction -from django.db.models import Count, Q +from django.db.models import Q from django.http import Http404, HttpResponse, HttpResponseRedirect from django.shortcuts import get_object_or_404, redirect from django.template.loader import get_template -from django.urls import reverse, reverse_lazy +from django.urls import reverse from django.utils import timezone from django.utils.decorators import method_decorator from django.utils.functional import cached_property @@ -25,7 +25,6 @@ from django.views.generic import ( CreateView, DetailView, FormView, - TemplateView, UpdateView, ) from django.views.generic.detail import SingleObjectMixin @@ -68,7 +67,7 @@ from hypha.apply.utils.views import DelegateableView, DelegatedViewMixin, ViewDi from ...funds.files import generate_private_file_path from ..files import get_files -from ..filters import InvoiceListFilter, ProjectListFilter, ReportListFilter +from ..filters import ProjectListFilter from ..forms import ( ApproveContractForm, ApproversForm, @@ -89,7 +88,6 @@ from ..forms import ( UploadContractForm, UploadDocumentForm, ) -from ..models.payment import Invoice from ..models.project import ( APPROVE, CONTRACTING, @@ -98,7 +96,6 @@ from ..models.project import ( INVOICING_AND_REPORTING, PROJECT_ACTION_MESSAGE_TAG, PROJECT_PUBLIC_STATUSES, - PROJECT_STATUS_CHOICES, REQUEST_CHANGE, Contract, ContractDocumentCategory, @@ -109,9 +106,8 @@ from ..models.project import ( Project, ProjectSettings, ) -from ..models.report import Report from ..permissions import has_permission -from ..tables import InvoiceListTable, ProjectsListTable, ReportListTable +from ..tables import ProjectsListTable from ..utils import ( get_paf_status_display, get_placeholder_file, @@ -1991,82 +1987,3 @@ class ProjectListView(SingleTableMixin, FilterView): queryset = Project.objects.for_table() table_class = ProjectsListTable template_name = "application_projects/project_list.html" - - -@method_decorator(staff_or_finance_or_contracting_required, name="dispatch") -class ProjectOverviewView(TemplateView): - template_name = "application_projects/overview.html" - - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - context["projects"] = self.get_projects(self.request) - context["invoices"] = self.get_invoices(self.request) - context["reports"] = self.get_reports(self.request) - context["status_counts"] = self.get_status_counts() - return context - - def get_reports(self, request): - if request.user.is_contracting: - return { - "filterset": None, - "table": None, - "url": None, - } - reports = Report.objects.for_table().submitted()[:10] - return { - "filterset": ReportListFilter( - request.GET or None, request=request, queryset=reports - ), - "table": ReportListTable(reports, order_by=()), - "url": reverse("apply:projects:reports:all"), - } - - def get_projects(self, request): - projects = Project.objects.for_table()[:10] - - return { - "filterset": ProjectListFilter( - request.GET or None, request=request, queryset=projects - ), - "table": ProjectsListTable(projects, order_by=()), - "url": reverse("apply:projects:all"), - } - - def get_invoices(self, request): - if request.user.is_contracting: - return { - "filterset": None, - "table": None, - "url": None, - } - invoices = Invoice.objects.order_by("-requested_at")[:10] - - return { - "filterset": InvoiceListFilter( - request.GET or None, request=request, queryset=invoices - ), - "table": InvoiceListTable(invoices, order_by=()), - "url": reverse("apply:projects:invoices"), - } - - def get_status_counts(self): - status_counts = dict( - Project.objects.all() - .values("status") - .annotate( - count=Count("status"), - ) - .values_list( - "status", - "count", - ) - ) - - return { - key: { - "name": display, - "count": status_counts.get(key, 0), - "url": reverse_lazy("funds:projects:all") + "?project_status=" + key, - } - for key, display in PROJECT_STATUS_CHOICES - } -- GitLab