diff --git a/opentech/apply/funds/tables.py b/opentech/apply/funds/tables.py index 9a4f5c24018a6ae3329b67fae95e85ad39dce9d2..1af8da4cbbdac958ba70fbf26a76710368350538 100644 --- a/opentech/apply/funds/tables.py +++ b/opentech/apply/funds/tables.py @@ -154,13 +154,19 @@ class SubmissionFilterAndSearch(SubmissionFilter): class RoundsTable(tables.Table): title = tables.LinkColumn('funds:rounds:detail', args=[A('pk')], orderable=True, text=lambda record: record.title) - fund = tables.Column() - lead = tables.Column(order_by=('lead.full_name',)) - start_date = tables.Column() - end_date = tables.Column() + fund = tables.Column(accessor=A('specific.fund')) + lead = tables.Column(accessor=A('specific.lead'), order_by=('lead.full_name',)) + start_date = tables.Column(accessor=A('specific.start_date')) + end_date = tables.Column(accessor=A('specific.end_date')) + progress = tables.Column() class Meta: - fields = ('title', 'fund', 'lead', 'start_date', 'end_date') + fields = ('title', 'fund', 'lead', 'start_date', 'end_date', 'progress') def render_lead(self, value): return format_html('<span>{}</span>', value) + + def render_progress(self, record): + if record.progress < 0: + return '-' + return f'{record.progress}%' diff --git a/opentech/apply/funds/tests/test_views.py b/opentech/apply/funds/tests/test_views.py index 857f6cfa63d37b1973ff27ce7dfd3124554db94a..1f88bd27c665fbe0668c67645f399ceb88cf9052 100644 --- a/opentech/apply/funds/tests/test_views.py +++ b/opentech/apply/funds/tests/test_views.py @@ -7,9 +7,7 @@ from opentech.apply.funds.tests.factories import ( ApplicationSubmissionFactory, ApplicationRevisionFactory, InvitedToProposalFactory, - LabFactory, LabSubmissionFactory, - RoundFactory, ScreeningStatusFactory, SealedRoundFactory, SealedSubmissionFactory, diff --git a/opentech/apply/funds/views.py b/opentech/apply/funds/views.py index 8873d95271f63236c9f23c1c25c7696b89afb884..b62c2aa48e0b99405fe9a421b21d1134088c74df 100644 --- a/opentech/apply/funds/views.py +++ b/opentech/apply/funds/views.py @@ -3,7 +3,8 @@ 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.db.models import Q +from django.db.models import Count, FloatField, IntegerField, F, OuterRef, Subquery, Q, When, Case +from django.db.models.functions import Coalesce from django.http import HttpResponseRedirect, Http404 from django.shortcuts import get_object_or_404 from django.urls import reverse_lazy @@ -472,4 +473,31 @@ class RoundListView(SingleTableMixin, ListView): table_class = RoundsTable def get_queryset(self): - return Page.objects.type(SubmittableStreamForm).specific() + submissions = ApplicationSubmission.objects.filter(Q(round=OuterRef('pk')) | Q(page=OuterRef('pk'))).current() + closed_submissions = submissions.inactive() + + queryset = Page.objects.type(SubmittableStreamForm).annotate( + total_submissions=Coalesce( + Subquery( + submissions.values('round').annotate(count=Count('pk')).values('count'), + output_field=IntegerField(), + ), + 0, + ), + closed_submissions=Coalesce( + Subquery( + closed_submissions.values('round').annotate(count=Count('pk')).values('count'), + output_field=IntegerField(), + ), + 0, + ), + ).annotate( + progress=Case( + When(total_submissions=0, then=-1), + default=(F('closed_submissions') * 100) / F('total_submissions'), + output_fields=FloatField(), + ) + + ) + + return queryset