From d663aa5effc2c8955219c26d6e431ece521cff42 Mon Sep 17 00:00:00 2001 From: "yuriy.kormin" Date: Wed, 14 Dec 2022 00:01:27 +0400 Subject: [PATCH 1/2] Correct an error on the members page #210 --- contributors/urls.py | 11 ++++++++++- contributors/views/__init__.py | 2 +- ...butors_for_month.py => contributors_for_period.py} | 10 ++++++++-- templates/components/time_note.html | 10 +++++----- ...rs_for_month.html => contributors_for_period.html} | 0 5 files changed, 24 insertions(+), 9 deletions(-) rename contributors/views/{contributors_for_month.py => contributors_for_period.py} (55%) rename templates/{contributors_for_month.html => contributors_for_period.html} (100%) diff --git a/contributors/urls.py b/contributors/urls.py index 473722dc..4a8af2b8 100644 --- a/contributors/urls.py +++ b/contributors/urls.py @@ -32,9 +32,18 @@ ), path( 'contributors/for-month', - views.contributors_for_month.ListView.as_view(), + views.contributors_for_period.ListView.as_view( + extra_context={'period': 'month'} + ), name='contributors_for_month', ), + path( + 'contributors/for-week', + views.contributors_for_period.ListView.as_view( + extra_context={'period': 'week'} + ), + name='contributors_for_week', + ), path( 'contributors/', views.contributor.DetailView.as_view(), diff --git a/contributors/views/__init__.py b/contributors/views/__init__.py index f1ac11a7..3f94d2f5 100644 --- a/contributors/views/__init__.py +++ b/contributors/views/__init__.py @@ -5,7 +5,7 @@ contributor_issues, contributor_prs, contributors, - contributors_for_month, + contributors_for_period, home, issues, organization, diff --git a/contributors/views/contributors_for_month.py b/contributors/views/contributors_for_period.py similarity index 55% rename from contributors/views/contributors_for_month.py rename to contributors/views/contributors_for_period.py index 812fd91b..3c32b0b8 100644 --- a/contributors/views/contributors_for_month.py +++ b/contributors/views/contributors_for_period.py @@ -6,12 +6,18 @@ class ListView(contributors.ListView): """A list of contributors with monthly contributions.""" - template_name = 'contributors_for_month.html' + template_name = 'contributors_for_period.html' context_object_name = 'contributors_list' - queryset = Contributor.objects.visible_with_monthly_stats() def get_context_data(self, **kwargs): """Add context.""" context = super().get_context_data(**kwargs) context['dt_month_ago'] = misc.datetime_month_ago() return context + + def get_queryset(self): + if self.extra_context.get('period') == 'week': + self.queryset = Contributor.objects.visible_with_weekly_stats() + elif self.extra_context.get('period') == 'month': + self.queryset = Contributor.objects.visible_with_monthly_stats() + return super().get_queryset() diff --git a/templates/components/time_note.html b/templates/components/time_note.html index 11964bba..73ad711b 100644 --- a/templates/components/time_note.html +++ b/templates/components/time_note.html @@ -2,14 +2,14 @@