From 62df6522ce2868572225192be707846f438b35f2 Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson <frjo@xdeb.org> Date: Mon, 18 May 2020 10:11:29 +0200 Subject: [PATCH] Renaming things. --- hypha/apply/funds/tables.py | 16 ++++----- ...erboard.html => reviewer_leaderboard.html} | 0 ....html => reviewer_leaderboard_detail.html} | 0 .../templates/funds/submissions_overview.html | 4 +-- hypha/apply/funds/tests/test_views.py | 4 +-- hypha/apply/funds/urls.py | 8 ++--- hypha/apply/funds/views.py | 36 +++++++++---------- 7 files changed, 33 insertions(+), 35 deletions(-) rename hypha/apply/funds/templates/funds/{review_leaderboard.html => reviewer_leaderboard.html} (100%) rename hypha/apply/funds/templates/funds/{review_leaderboard_detail.html => reviewer_leaderboard_detail.html} (100%) diff --git a/hypha/apply/funds/tables.py b/hypha/apply/funds/tables.py index 914409308..4b0644e11 100644 --- a/hypha/apply/funds/tables.py +++ b/hypha/apply/funds/tables.py @@ -366,12 +366,12 @@ class RoundsFilter(filters.FilterSet): round_state = OpenRoundFilter(label='Open') -class LeaderboardFilterForm(forms.ModelForm): +class ReviewerLeaderboardFilterForm(forms.ModelForm): """ Form to "clean" a list of User objects to their PKs. - The Leaderboard table is a list of User objects, however we also want the - ability to filter down to N Users (reviewers). Django filter is converting + The Reviewer Leaderboard table is a list of User objects, however we also want + the ability to filter down to N Users (reviewers). Django filter is converting the selected PKs to User objects, however we can't filter a User QuerySet with User objects. So this form converts back to a list of User PKs using the clean_reviewer method. @@ -384,7 +384,7 @@ class LeaderboardFilterForm(forms.ModelForm): return [u.id for u in self.cleaned_data['reviewer']] -class LeaderboardFilter(filters.FilterSet): +class ReviewerLeaderboardFilter(filters.FilterSet): query = filters.CharFilter(field_name='full_name', lookup_expr="icontains", widget=forms.HiddenInput) reviewer = Select2ModelMultipleChoiceFilter( @@ -409,12 +409,12 @@ class LeaderboardFilter(filters.FilterSet): 'funds', 'rounds', ] - form = LeaderboardFilterForm + form = ReviewerLeaderboardFilterForm model = User -class LeaderboardTable(tables.Table): - full_name = tables.LinkColumn('funds:submissions:leaderboard_detail', args=[A('pk')], orderable=True, verbose_name="Reviewer", attrs={'td': {'class': 'title'}}) +class ReviewerLeaderboardTable(tables.Table): + full_name = tables.LinkColumn('funds:submissions:reviewer_leaderboard_detail', args=[A('pk')], orderable=True, verbose_name="Reviewer", attrs={'td': {'class': 'title'}}) class Meta: model = User @@ -430,7 +430,7 @@ class LeaderboardTable(tables.Table): empty_text = _('No reviews available') -class LeaderboardDetailTable(tables.Table): +class ReviewerLeaderboardDetailTable(tables.Table): title = tables.LinkColumn('funds:submissions:reviews:review', text=render_title, args=[A('submission_id'), A('pk')], orderable=True, verbose_name="Submission", attrs={'td': {'data-title-tooltip': lambda record: record.submission.title, 'class': 'title js-title'}}) class Meta: diff --git a/hypha/apply/funds/templates/funds/review_leaderboard.html b/hypha/apply/funds/templates/funds/reviewer_leaderboard.html similarity index 100% rename from hypha/apply/funds/templates/funds/review_leaderboard.html rename to hypha/apply/funds/templates/funds/reviewer_leaderboard.html diff --git a/hypha/apply/funds/templates/funds/review_leaderboard_detail.html b/hypha/apply/funds/templates/funds/reviewer_leaderboard_detail.html similarity index 100% rename from hypha/apply/funds/templates/funds/review_leaderboard_detail.html rename to hypha/apply/funds/templates/funds/reviewer_leaderboard_detail.html diff --git a/hypha/apply/funds/templates/funds/submissions_overview.html b/hypha/apply/funds/templates/funds/submissions_overview.html index b055a0593..ed04c2dc7 100644 --- a/hypha/apply/funds/templates/funds/submissions_overview.html +++ b/hypha/apply/funds/templates/funds/submissions_overview.html @@ -15,8 +15,8 @@ {% if request.user.is_apply_staff %} <div class="tabs"> <div class="tabs__container"> - <a class="tab__item tab__item--right" href="{% url 'apply:submissions:leaderboard' %}"> - Leaderboard + <a class="tab__item tab__item--right" href="{% url 'apply:submissions:reviewer_leaderboard' %}"> + Reviews </a> <a class="tab__item tab__item--right" href="{% url 'apply:submissions:result' %}"> Results diff --git a/hypha/apply/funds/tests/test_views.py b/hypha/apply/funds/tests/test_views.py index 6c99325ed..46ad7bd97 100644 --- a/hypha/apply/funds/tests/test_views.py +++ b/hypha/apply/funds/tests/test_views.py @@ -1235,10 +1235,10 @@ class TestReviewerLeaderboard(TestCase): response = self.client.get('/apply/submissions/reviews/', follow=True, secure=True) self.assertEqual(response.status_code, 403) - def test_reviewer_can_access_leader_board(self): + def test_reviewer_cannot_access_leader_board(self): self.client.force_login(ReviewerFactory()) response = self.client.get('/apply/submissions/reviews/', follow=True, secure=True) - self.assertEqual(response.status_code, 200) + self.assertEqual(response.status_code, 403) def test_staff_can_access_leaderboard(self): self.client.force_login(StaffFactory()) diff --git a/hypha/apply/funds/urls.py b/hypha/apply/funds/urls.py index d96747af8..d63cbdf5b 100644 --- a/hypha/apply/funds/urls.py +++ b/hypha/apply/funds/urls.py @@ -4,8 +4,8 @@ from hypha.apply.projects import urls as projects_urls from .views import ( ReminderDeleteView, - ReviewLeaderboard, - ReviewLeaderboardDetail, + ReviewerLeaderboard, + ReviewerLeaderboardDetail, RevisionCompareView, RevisionListView, RoundListView, @@ -46,8 +46,8 @@ submission_urls = ([ path('staff/', SubmissionStaffFlaggedView.as_view(), name="staff_flagged"), ])), path('reviews/', include([ - path('', ReviewLeaderboard.as_view(), name="leaderboard"), - path('<int:pk>/', ReviewLeaderboardDetail.as_view(), name="leaderboard_detail"), + path('', ReviewerLeaderboard.as_view(), name="reviewer_leaderboard"), + path('<int:pk>/', ReviewerLeaderboardDetail.as_view(), name="reviewer_leaderboard_detail"), ])), path('<int:pk>/', include([ path('', SubmissionDetailView.as_view(), name="detail"), diff --git a/hypha/apply/funds/views.py b/hypha/apply/funds/views.py index a23aa20c1..c8af701c2 100644 --- a/hypha/apply/funds/views.py +++ b/hypha/apply/funds/views.py @@ -80,9 +80,9 @@ from .models import ( from .permissions import is_user_has_access_to_view_submission from .tables import ( AdminSubmissionsTable, - LeaderboardDetailTable, - LeaderboardFilter, - LeaderboardTable, + ReviewerLeaderboardDetailTable, + ReviewerLeaderboardFilter, + ReviewerLeaderboardTable, ReviewerSubmissionsTable, RoundsFilter, RoundsTable, @@ -1188,13 +1188,13 @@ class SubmissionResultView(FilterView): return {'total': total, 'average': average} -@method_decorator(login_required, name='dispatch') -class ReviewLeaderboard(UserPassesTestMixin, SingleTableMixin, FilterView): - filterset_class = LeaderboardFilter +@method_decorator(staff_required, name='dispatch') +class ReviewerLeaderboard(SingleTableMixin, FilterView): + filterset_class = ReviewerLeaderboardFilter filter_action = '' - table_class = LeaderboardTable + table_class = ReviewerLeaderboardTable table_pagination = False - template_name = 'funds/review_leaderboard.html' + template_name = 'funds/reviewer_leaderboard.html' def get_context_data(self, **kwargs): search_term = self.request.GET.get('query') @@ -1205,28 +1205,29 @@ class ReviewLeaderboard(UserPassesTestMixin, SingleTableMixin, FilterView): **kwargs, ) + def get_queryset(self): + # Only list reviewers. + return self.filterset_class._meta.model.objects.reviewers() + def get_table_data(self): ninety_days_ago = timezone.now() - timedelta(days=90) this_year = timezone.now().year last_year = timezone.now().year - 1 - return super().get_table_data().filter(submissions_reviewer__isnull=False).annotate( + return super().get_table_data().annotate( total=Count('assignedreviewers__review'), ninety_days=Count('assignedreviewers__review', filter=Q(assignedreviewers__review__created_at__date__gte=ninety_days_ago)), this_year=Count('assignedreviewers__review', filter=Q(assignedreviewers__review__created_at__year=this_year)), last_year=Count('assignedreviewers__review', filter=Q(assignedreviewers__review__created_at__year=last_year)), ) - def test_func(self): - return self.request.user.is_apply_staff or self.request.user.is_reviewer - -@method_decorator(login_required, name='dispatch') -class ReviewLeaderboardDetail(UserPassesTestMixin, SingleTableMixin, ListView): +@method_decorator(staff_required, name='dispatch') +class ReviewerLeaderboardDetail(SingleTableMixin, ListView): model = Review - table_class = LeaderboardDetailTable + table_class = ReviewerLeaderboardDetailTable paginator_class = LazyPaginator table_pagination = {'per_page': 25} - template_name = 'funds/review_leaderboard_detail.html' + template_name = 'funds/reviewer_leaderboard_detail.html' def get_context_data(self, **kwargs): User = get_user_model() @@ -1235,6 +1236,3 @@ class ReviewLeaderboardDetail(UserPassesTestMixin, SingleTableMixin, ListView): def get_table_data(self): return super().get_table_data().filter(author__reviewer_id=self.kwargs.get('pk')).select_related('submission') - - def test_func(self): - return self.request.user.is_apply_staff or self.request.user.is_reviewer -- GitLab