From 4c58a85b416c251e9a781f722cc9c36af0e96414 Mon Sep 17 00:00:00 2001 From: AleksandrKosmylev Date: Sat, 15 Jun 2024 17:41:40 +0300 Subject: [PATCH 01/19] edit_achievements --- contributors/urls.py | 5 +++++ contributors/views/__init__.py | 1 + templates/contributor/contributor_details.html | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/contributors/urls.py b/contributors/urls.py index c07f16ff..5afb8e8d 100644 --- a/contributors/urls.py +++ b/contributors/urls.py @@ -106,6 +106,11 @@ views.achievements.AchievementListView.as_view(), name='achievements', ), + path( + 'contributor_achievements/', + views.contributor_achievements.ContributorAchievementListView.as_view(), # noqa: E501 + name='contributor_achievements', + ), path( 'landing/', views.landing.LandingView.as_view(), diff --git a/contributors/views/__init__.py b/contributors/views/__init__.py index e8282b57..0baf4f34 100644 --- a/contributors/views/__init__.py +++ b/contributors/views/__init__.py @@ -2,6 +2,7 @@ about, achievements, config, + contributor_achievements, contributor_compare, filters, home, diff --git a/templates/contributor/contributor_details.html b/templates/contributor/contributor_details.html index 96bae965..c0d6f467 100644 --- a/templates/contributor/contributor_details.html +++ b/templates/contributor/contributor_details.html @@ -19,7 +19,7 @@

{{ contributor.login }}

GitHub

- + {% trans 'Achievements' %}

From 1dd47359a8c348b3aaec00fbd1847d9d3416751d Mon Sep 17 00:00:00 2001 From: AleksandrKosmylev Date: Sat, 15 Jun 2024 17:51:46 +0300 Subject: [PATCH 02/19] edit_achievements_addition --- .../views/contributor_achievements.py | 109 +++++ ...tributor_achievement_percentage_field.html | 18 + .../tables/contributor_achievements_list.html | 380 ++++++++++++++++++ .../contributor_achievements_list.html | 19 + 4 files changed, 526 insertions(+) create mode 100644 contributors/views/contributor_achievements.py create mode 100644 templates/components/tables/contributor_achievement_percentage_field.html create mode 100644 templates/components/tables/contributor_achievements_list.html create mode 100644 templates/contributor/contributor_achievements_list.html diff --git a/contributors/views/contributor_achievements.py b/contributors/views/contributor_achievements.py new file mode 100644 index 00000000..873f08f4 --- /dev/null +++ b/contributors/views/contributor_achievements.py @@ -0,0 +1,109 @@ +from django.db.models import Count, Q, Sum # noqa: WPS235, WPS347 +from django.db.models.functions import Coalesce +from django.views import generic + +from contributors.models import Contributor, Repository + +ID = 'id' + + +class ContributorAchievementListView(generic.ListView): + """Achievement list.""" + + template_name = 'contributor/contributor_achievements_list.html' + model = Contributor + contributors = Contributor.objects.with_contributions() + + pull_request_ranges_for_achievements = [100, 50, 25, 10, 1] + commit_ranges_for_achievements = [200, 100, 50, 25, 1] + issue_ranges_for_achievements = [50, 25, 10, 5, 1] + comment_ranges_for_achievements = [200, 100, 50, 25, 1] + edition_ranges_for_achievements = [1000, 500, 250, 100, 1] + + def get_context_data(self, **kwargs): + """Add context data for achievement list.""" + self.contributors_amount = Contributor.objects.count() + context = super().get_context_data(**kwargs) + contributors = Contributor.objects.with_contributions() + current_contributor = ( + Contributor.objects.get(login=self.kwargs['slug']) + ) + + repositories = Repository.objects.select_related( + 'organization', + ).filter( + is_visible=True, + contribution__contributor=current_contributor, + ).annotate( + commits=Count('id', filter=Q(contribution__type='cit')), + additions=Coalesce(Sum('contribution__stats__additions'), 0), + deletions=Coalesce(Sum('contribution__stats__deletions'), 0), + pull_requests=Count( + 'contribution', filter=Q(contribution__type='pr'), + ), + issues=Count('contribution', filter=Q(contribution__type='iss')), + comments=Count('contribution', filter=Q(contribution__type='cnt')), + ).order_by('organization', 'name') + + contributions = repositories.values().aggregate( + contributor_deletions=Sum('deletions'), + contributor_additions=Sum('additions'), + contributor_commits=Sum('commits'), + contributor_pull_requests=Sum('pull_requests'), + contributor_issues=Sum('issues'), + contributor_comments=Sum('comments'), + ) + + context['commits'] = contributions['contributor_commits'] + context['pull_requests'] = contributions['contributor_pull_requests'] + context['issues'] = contributions['contributor_issues'] + context['comments'] = contributions['contributor_commits'] + context['total_editions'] = ( + contributions['contributor_additions'] + contributions['contributor_deletions'] # noqa: E501 + ) + context['total_actions'] = sum(contributions.values()) + context['pull_request_ranges_for_achievements'] = ( + self.pull_request_ranges_for_achievements + ) + context['current_contributor'] = current_contributor + context['contributors_amount'] = self.contributors_amount + context['contributors_with_any_contribution'] = ( + contributors.filter(contribution_amount__gte=1).count() + ) + + # Pull request achievements: + for pr_num in self.pull_request_ranges_for_achievements: + context[f'contributor_pull_requests_gte_{pr_num}'] = pr_num + context[f'contributors_pull_requests_gte_{pr_num}'] = ( + contributors.filter(pull_requests__gte=pr_num).count() + ) + + # Commit achievements: + for commit_num in self.commit_ranges_for_achievements: + context[f'contributor_commits_gte_{commit_num}'] = commit_num + context[f'contributors_commits_gte_{commit_num}'] = ( + contributors.filter(commits__gte=commit_num).count() + ) + + # Issue achievements: + for issue_num in self.issue_ranges_for_achievements: + context[f'contributor_issues_gte_{issue_num}'] = issue_num + context[f'contributors_issues_gte_{issue_num}'] = ( + contributors.filter(issues__gte=issue_num).count() + ) + + # Comment achievements: + for comment_num in self.comment_ranges_for_achievements: + context[f'contributor_comments_gte_{comment_num}'] = comment_num + context[f'contributors_comments_gte_{comment_num}'] = ( + contributors.filter(comments__gte=comment_num).count() + ) + + # Edition achievements: + for ed_num in self.edition_ranges_for_achievements: + context[f'contributor_editions_gte_{ed_num}'] = ed_num + context[f'contributors_editions_gte_{ed_num}'] = ( + contributors.filter(editions__gte=ed_num).count() + ) + + return context diff --git a/templates/components/tables/contributor_achievement_percentage_field.html b/templates/components/tables/contributor_achievement_percentage_field.html new file mode 100644 index 00000000..bf68ebf8 --- /dev/null +++ b/templates/components/tables/contributor_achievement_percentage_field.html @@ -0,0 +1,18 @@ +{% load i18n static mathfilters %} + +
+
+
+
{% trans achievement_name %}
+
{% trans achievement_description %}
+
+
+ +
+ {% if contribution|div:achievement_made_count|mul:100 > 100 %} + 100.0% + {% else %} + {{ contribution|div:achievement_made_count|mul:100|floatformat:1 }}% + {% endif %} +
+
diff --git a/templates/components/tables/contributor_achievements_list.html b/templates/components/tables/contributor_achievements_list.html new file mode 100644 index 00000000..d5006b15 --- /dev/null +++ b/templates/components/tables/contributor_achievements_list.html @@ -0,0 +1,380 @@ +{% extends './list_as_table.html' %} +{% load i18n static mathfilters %} + +{% block tbody %} + + + {% trans 'Hexlet friend' %} + + + + {% with achievement_name="Hexlet friend" achievement_description="Make any contribution to Hexlet projects" achievement_made_count=1 contribution=total_actions %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + + + + {% trans 'Pull requests (equal to or more than 1)' %} + + + {% with achievement_name="Pull requests (equal to or more than 1)" achievement_description="Make pull requests in amount of equal to or more than 1" achievement_made_count=contributor_pull_requests_gte_1 contribution=pull_requests %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Pull requests (equal to or more than 10)' %} + + + {% with achievement_name="Pull requests (equal to or more than 10)" achievement_description="Make pull requests in amount of equal to or more than 10" achievement_made_count=contributor_pull_requests_gte_10 contribution=pull_requests %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Pull requests (equal to or more than 25)' %} + + + {% with achievement_name="Pull requests (equal to or more than 25)" achievement_description="Make pull requests in amount of equal to or more than 25" achievement_made_count=contributor_pull_requests_gte_25 contribution=pull_requests %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Pull requests (equal to or more than 50)' %} + + + {% with achievement_name="Pull requests (equal to or more than 50)" achievement_description="Make pull requests in amount of equal to or more than 50" achievement_made_count=contributor_pull_requests_gte_50 contribution=pull_requests %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Pull requests (equal to or more than 100)' %} + + + {% with achievement_name="Pull requests (equal to or more than 100)" achievement_description="Make pull requests in amount of equal to or more than 100" achievement_made_count=contributor_pull_requests_gte_100 contribution=pull_requests %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + + + {% trans 'Commits (equal to or more than 1)' %} + + + {% with achievement_name="Commits (equal to or more than 1)" achievement_description="Make commits in amount of equal to or more than 1" achievement_made_count=contributor_commits_gte_1 contribution=commits %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Commits (equal to or more than 25)' %} + + + {% with achievement_name="Commits (equal to or more than 25)" achievement_description="Make commits in amount of equal to or more than 25" achievement_made_count=contributor_commits_gte_25 contribution=commits %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Commits (equal to or more than 50)' %} + + + {% with achievement_name="Commits (equal to or more than 50)" achievement_description="Make commits in amount of equal to or more than 50" achievement_made_count=contributor_commits_gte_50 contribution=commits %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Commits (equal to or more than 100)' %} + + + {% with achievement_name="Commits (equal to or more than 100)" achievement_description="Make commits in amount of equal to or more than 100" achievement_made_count=contributor_commits_gte_100 contribution=commits %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Commits (equal to or more than 200)' %} + + + {% with achievement_name="Commits (equal to or more than 200)" achievement_description="Make commits in amount of equal to or more than 200" achievement_made_count=contributor_commits_gte_200 contribution=commits %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + + + {% trans 'Issues (equal to or more than 1)' %} + + + {% with achievement_name="Issues (equal to or more than 1)" achievement_description="Make issues in amount of equal to or more than 1" achievement_made_count=contributor_issues_gte_1 contribution=issues %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Issues (equal to or more than 5)' %} + + + {% with achievement_name="Issues (equal to or more than 5)" achievement_description="Make issues in amount of equal to or more than 5" achievement_made_count=contributor_issues_gte_5 contribution=issues %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Issues (equal to or more than 10)' %} + + + {% with achievement_name="Issues (equal to or more than 10)" achievement_description="Make issues in amount of equal to or more than 10" achievement_made_count=contributor_issues_gte_10 contribution=issues %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Issues (equal to or more than 25)' %} + + + {% with achievement_name="Issues (equal to or more than 25)" achievement_description="Make issues in amount of equal to or more than 25" achievement_made_count=contributor_issues_gte_25 contribution=issues %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Issues (equal to or more than 50)' %} + + + {% with achievement_name="Issues (equal to or more than 50)" achievement_description="Make issues in amount of equal to or more than 50" achievement_made_count=contributor_issues_gte_50 contribution=issues %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + + + {% trans 'Comments (equal to or more than 1)' %} + + + {% with achievement_name="Comments (equal to or more than 1)" achievement_description="Make comments in amount of equal to or more than 1" achievement_made_count=contributor_comments_gte_1 contribution=comments %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Comments (equal to or more than 25)' %} + + + {% with achievement_name="Comments (equal to or more than 25)" achievement_description="Make comments in amount of equal to or more than 25" achievement_made_count=contributor_comments_gte_25 contribution=comments %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Comments (equal to or more than 50)' %} + + + {% with achievement_name="Comments (equal to or more than 50)" achievement_description="Make comments in amount of equal to or more than 50" achievement_made_count=contributor_comments_gte_50 contribution=comments %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Comments (equal to or more than 100)' %} + + + {% with achievement_name="Comments (equal to or more than 100)" achievement_description="Make comments in amount of equal to or more than 100" achievement_made_count=contributor_comments_gte_100 contribution=comments %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Comments (equal to or more than 200)' %} + + + {% with achievement_name="Comments (equal to or more than 200)" achievement_description="Make comments in amount of equal to or more than 200" achievement_made_count=contributor_comments_gte_200 contribution=comments %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + + {% trans 'Additions and deletions (equal to or more than 1)' %} + + + {% with achievement_name="Additions and deletions (equal to or more than 1)" achievement_description="Make additions and deletions in amount of equal to or more than 1" achievement_made_count=contributor_editions_gte_1 contribution=total_editions %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Additions and deletions (equal to or more than 100)' %} + + + {% with achievement_name="Additions and deletions (equal to or more than 100)" achievement_description="Make additions and deletions in amount of equal to or more than 100" achievement_made_count=contributor_editions_gte_100 contribution=total_editions %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Additions and deletions (equal to or more than 250)' %} + + + {% with achievement_name="Additions and deletions (equal to or more than 250)" achievement_description="Make additions and deletions in amount of equal to or more than 250" achievement_made_count=contributor_editions_gte_250 contribution=total_editions %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Additions and deletions (equal to or more than 500)' %} + + + {% with achievement_name="Additions and deletions (equal to or more than 500)" achievement_description="Make additions and deletions in amount of equal to or more than 500" achievement_made_count=contributor_editions_gte_500 contribution=total_editions %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + + + + {% trans 'Additions and deletions (equal to or more than 1000)' %} + + + {% with achievement_name="Additions and deletions (equal to or more than 1000)" achievement_description="Make additions and deletions in amount of equal to or more than 1000" achievement_made_count=contributor_editions_gte_1000 contribution=total_editions %} + {% include './contributor_achievement_percentage_field.html' %} + {% endwith %} + + +{% endblock %} diff --git a/templates/contributor/contributor_achievements_list.html b/templates/contributor/contributor_achievements_list.html new file mode 100644 index 00000000..213a42aa --- /dev/null +++ b/templates/contributor/contributor_achievements_list.html @@ -0,0 +1,19 @@ +{% extends 'base.html' %} +{% load i18n static %} + +{% block content %} + +

{% trans "Achievements" %}

+ + + + +{% endblock %} From be4c7d1d0194c47913789a33df103198b74c85f1 Mon Sep 17 00:00:00 2001 From: AleksandrKosmylev Date: Tue, 18 Jun 2024 12:07:03 +0300 Subject: [PATCH 03/19] Added common statistics in footer --- templates/components/footer.html | 37 ++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/templates/components/footer.html b/templates/components/footer.html index 4411933a..0ffb248a 100644 --- a/templates/components/footer.html +++ b/templates/components/footer.html @@ -7,7 +7,22 @@
-

{% trans "Other projects" %}

+
- - From a68db2e8ea8a68cd70187fc8b266b344d05d2687 Mon Sep 17 00:00:00 2001 From: AleksandrKosmylev Date: Wed, 19 Jun 2024 17:20:50 +0300 Subject: [PATCH 04/19] add test for contributors:contributor_achievements and minor linter fix --- auth/tests.py | 4 +- contributors/management/commands/fetchdata.py | 2 +- contributors/models/contribution.py | 4 +- contributors/tests/test_contributors_views.py | 12 +++++ contributors/urls.py | 2 +- contributors/utils/github_lib.py | 4 +- contributors/views/config.py | 2 +- .../views/contributor_achievements.py | 52 ++++++++++++------- contributors/views/contributor_compare.py | 6 +-- .../views/contributors_views/contributor.py | 2 +- .../contributors_for_period.py | 2 +- contributors/views/filters.py | 2 +- .../views/generic_list_views/pull_requests.py | 2 +- .../organizations_views/organizations.py | 2 +- .../views/repositories_views/repository.py | 2 +- setup.cfg | 8 ++- 16 files changed, 70 insertions(+), 38 deletions(-) diff --git a/auth/tests.py b/auth/tests.py index 3e106f2f..a77acca4 100644 --- a/auth/tests.py +++ b/auth/tests.py @@ -128,8 +128,8 @@ def setUp(self): """Create a test client.""" self.client: Client = Client() - @patch('contributors.utils.github_lib.get_access_token', lambda *args: None) # noqa: E501 - @patch('contributors.utils.github_lib.get_data_of_token_holder', lambda *args: None) # noqa: E501 + @patch('contributors.utils.github_lib.get_access_token', lambda *args: None) + @patch('contributors.utils.github_lib.get_data_of_token_holder', lambda *args: None) @patch('auth.backends.GitHubBackend.authenticate', lambda *args: None) def test_github_auth_view(self): """Send a request without authentication and check the response.""" diff --git a/contributors/management/commands/fetchdata.py b/contributors/management/commands/fetchdata.py index 94aa92bf..9b60551d 100644 --- a/contributors/management/commands/fetchdata.py +++ b/contributors/management/commands/fetchdata.py @@ -158,7 +158,7 @@ def handle( # noqa: C901,WPS110,WPS213,WPS231,WPS210 if repo['name'] not in IGNORED_REPOSITORIES ] number_of_repos = len(repos_to_process) - for i, repo_data in enumerate(repos_to_process, start=1): # noqa: WPS111,E501 + for i, repo_data in enumerate(repos_to_process, start=1): # noqa: WPS111 repo, _ = misc.update_or_create_record(Repository, repo_data) logger.info(f"{repo} ({i}/{number_of_repos})") if repo_data['size'] == 0: diff --git a/contributors/models/contribution.py b/contributors/models/contribution.py index 7c11c14c..41b1a35e 100644 --- a/contributors/models/contribution.py +++ b/contributors/models/contribution.py @@ -88,8 +88,8 @@ class Contribution(models.Model): on_delete=models.CASCADE, verbose_name=_("contributor"), ) - id = models.CharField(primary_key=True, max_length=ID_LENGTH) # noqa: A003,WPS125,E501 - type = models.CharField(_("type"), choices=TYPES, max_length=TYPE_LENGTH) # noqa: A003,WPS125,E501 + id = models.CharField(primary_key=True, max_length=ID_LENGTH) # noqa: A003,WPS125 + type = models.CharField(_("type"), choices=TYPES, max_length=TYPE_LENGTH) # noqa: A003,WPS125 html_url = models.URLField(_("URL")) created_at = models.DateTimeField(_("creation date")) diff --git a/contributors/tests/test_contributors_views.py b/contributors/tests/test_contributors_views.py index 0976f8ce..6a27aae4 100644 --- a/contributors/tests/test_contributors_views.py +++ b/contributors/tests/test_contributors_views.py @@ -10,6 +10,8 @@ EXPECTED_CONTRIBUTORS_ISSUE_COUNT = 2 EXPECTED_CONTRIBUTORS_PR_COUNT = 2 +TEST_CONTRIBUTORS = ["mintough57", "kinganduld", "indecing", "pilly1964", "suir1948"] + class TestContributorDetailView(TestCase): """Test the methods for the contributor's details view.""" @@ -149,3 +151,13 @@ def test_get_context_data(self): self.assertEqual(response.context['contributors_issues_gte_1'], 2) self.assertEqual(response.context['contributors_comments_gte_1'], 0) self.assertEqual(response.context['contributors_editions_gte_1'], 0) + + def test_get_context_data_contributor(self): + for contributor in TEST_CONTRIBUTORS: + response = self.client.get(reverse('contributors:contributor_achievements', args=[contributor])) + self.assertEqual(response.status_code, HTTPStatus.OK) + response = self.client.get(reverse('contributors:contributor_achievements', args=[TEST_CONTRIBUTOR_LOGIN])) + self.assertEqual(response.context['contributor_commits_gte_1'], 1) + self.assertEqual(response.context['contributor_issues_gte_1'], 1) + self.assertEqual(response.context['contributor_comments_gte_1'], 1) + self.assertEqual(response.context['contributor_editions_gte_1'], 1) diff --git a/contributors/urls.py b/contributors/urls.py index 5afb8e8d..6295c037 100644 --- a/contributors/urls.py +++ b/contributors/urls.py @@ -108,7 +108,7 @@ ), path( 'contributor_achievements/', - views.contributor_achievements.ContributorAchievementListView.as_view(), # noqa: E501 + views.contributor_achievements.ContributorAchievementListView.as_view(), name='contributor_achievements', ), path( diff --git a/contributors/utils/github_lib.py b/contributors/utils/github_lib.py index 1444f3ed..d0cf1d15 100644 --- a/contributors/utils/github_lib.py +++ b/contributors/utils/github_lib.py @@ -7,7 +7,7 @@ from django.conf import settings GITHUB_API_URL = 'https://api.github.com' -GITHUB_TOKEN_PROVIDER_URL = 'https://github.com/login/oauth/access_token' # noqa: E501,S105 +GITHUB_TOKEN_PROVIDER_URL = 'https://github.com/login/oauth/access_token' # noqa: S105 def merge_dicts(*dicts): @@ -402,7 +402,7 @@ def get_commit_stats_for_contributor(repo_full_name, contributor_id): return totals['c'], totals['a'], totals['d'] -def get_data_of_owners_and_repos(*, owner_names=None, repo_full_names=None): # noqa: C901,R701,E501,WPS231 +def get_data_of_owners_and_repos(*, owner_names=None, repo_full_names=None): # noqa: C901,R701,WPS231 """Return data of owners and their repositories from GitHub.""" if not (owner_names or repo_full_names): raise ValueError("Neither owner_names nor repo_full_names is provided") diff --git a/contributors/views/config.py b/contributors/views/config.py index ae425b99..bc9cc2e7 100644 --- a/contributors/views/config.py +++ b/contributors/views/config.py @@ -62,7 +62,7 @@ def collect_data(request): repo.is_visible = True Repository.objects.bulk_update(repos, ['is_tracked', 'is_visible']) fetch_command = ['./manage.py', 'fetchdata', '--repo'] - fetch_command.extend([repo.full_name for repo in repos]) # noqa: WPS441,E501 + fetch_command.extend([repo.full_name for repo in repos]) # noqa: WPS441 subprocess.Popen(fetch_command) # noqa: S603 return TemplateResponse(request, 'admin/data_collection.html', context) return HttpResponseForbidden("Forbidden.") diff --git a/contributors/views/contributor_achievements.py b/contributors/views/contributor_achievements.py index 873f08f4..bfe83856 100644 --- a/contributors/views/contributor_achievements.py +++ b/contributors/views/contributor_achievements.py @@ -1,4 +1,4 @@ -from django.db.models import Count, Q, Sum # noqa: WPS235, WPS347 +from django.db import models from django.db.models.functions import Coalesce from django.views import generic @@ -35,33 +35,47 @@ def get_context_data(self, **kwargs): is_visible=True, contribution__contributor=current_contributor, ).annotate( - commits=Count('id', filter=Q(contribution__type='cit')), - additions=Coalesce(Sum('contribution__stats__additions'), 0), - deletions=Coalesce(Sum('contribution__stats__deletions'), 0), - pull_requests=Count( - 'contribution', filter=Q(contribution__type='pr'), + commits=models.Count('id', filter=models.Q(contribution__type='cit')), + additions=Coalesce(models.Sum('contribution__stats__additions'), 0), + deletions=Coalesce(models.Sum('contribution__stats__deletions'), 0), + pull_requests=models.Count( + 'contribution', filter=models.Q(contribution__type='pr'), ), - issues=Count('contribution', filter=Q(contribution__type='iss')), - comments=Count('contribution', filter=Q(contribution__type='cnt')), + issues=models.Count('contribution', filter=models.Q(contribution__type='iss')), + comments=models.Count('contribution', filter=models.Q(contribution__type='cnt')), ).order_by('organization', 'name') contributions = repositories.values().aggregate( - contributor_deletions=Sum('deletions'), - contributor_additions=Sum('additions'), - contributor_commits=Sum('commits'), - contributor_pull_requests=Sum('pull_requests'), - contributor_issues=Sum('issues'), - contributor_comments=Sum('comments'), + contributor_deletions=models.Sum('deletions'), + contributor_additions=models.Sum('additions'), + contributor_commits=models.Sum('commits'), + contributor_pull_requests=models.Sum('pull_requests'), + contributor_issues=models.Sum('issues'), + contributor_comments=models.Sum('comments'), ) context['commits'] = contributions['contributor_commits'] context['pull_requests'] = contributions['contributor_pull_requests'] context['issues'] = contributions['contributor_issues'] - context['comments'] = contributions['contributor_commits'] - context['total_editions'] = ( - contributions['contributor_additions'] + contributions['contributor_deletions'] # noqa: E501 - ) - context['total_actions'] = sum(contributions.values()) + context['comments'] = contributions['contributor_comments'] + context['total_editions'] = sum([ + 0 if edit is None else edit + for edit in [ + contributions['contributor_additions'], + contributions['contributor_deletions'], + ] + ]) + context['total_actions'] = sum([ + 0 if action is None else action + for action in [ + contributions['contributor_commits'], + contributions['contributor_pull_requests'], + contributions['contributor_issues'], + contributions['contributor_comments'], + contributions['contributor_additions'], + contributions['contributor_deletions'], + ] + ]) context['pull_request_ranges_for_achievements'] = ( self.pull_request_ranges_for_achievements ) diff --git a/contributors/views/contributor_compare.py b/contributors/views/contributor_compare.py index d5a4778a..bcbdce4f 100644 --- a/contributors/views/contributor_compare.py +++ b/contributors/views/contributor_compare.py @@ -9,7 +9,7 @@ class CompareWithYourselfView(ListView): """View of comparing current user with another one.""" model = Contribution - template_name = 'contributors_sections/contributors/contributor_compare_with_yourself.html' # noqa: E501 + template_name = 'contributors_sections/contributors/contributor_compare_with_yourself.html' slug_field = 'contributor' def get_queryset(self): @@ -54,7 +54,7 @@ def get_context_data(self, **kwargs): ).first().full_name context['me_top_repo'] = me_repo_full_name else: - context['me_top_repo'] = '---' # noqa: E501 + context['me_top_repo'] = '---' enemy_qs = context['filter'].qs.filter( contributor=context['enemy_obj'].pk, @@ -75,5 +75,5 @@ def get_context_data(self, **kwargs): ).first().full_name context['enemy_top_repo'] = enemy_repo_full_name else: - context['enemy_top_repo'] = '---' # noqa: E501 + context['enemy_top_repo'] = '---' return context diff --git a/contributors/views/contributors_views/contributor.py b/contributors/views/contributors_views/contributor.py index 62b9ed4b..ed181e8d 100644 --- a/contributors/views/contributors_views/contributor.py +++ b/contributors/views/contributors_views/contributor.py @@ -46,7 +46,7 @@ def get_context_data(self, **kwargs): self.object.contribution_set.for_year() ) context['top_repository'] = repositories.annotate( - summary=F('commits') + F('pull_requests') + F('issues') + F('comments'), # noqa: WPS221, E501 + summary=F('commits') + F('pull_requests') + F('issues') + F('comments'), # noqa: WPS221 ).order_by('-summary').first() context['summary'] = Contribution.objects.filter( diff --git a/contributors/views/contributors_views/contributors_for_period.py b/contributors/views/contributors_views/contributors_for_period.py index f2e4f0fc..a78b014a 100644 --- a/contributors/views/contributors_views/contributors_for_period.py +++ b/contributors/views/contributors_views/contributors_for_period.py @@ -6,7 +6,7 @@ class ListView(contributors.ListView): """A list of contributors with monthly contributions.""" - template_name = 'contributors_sections/contributors/contributors_for_period.html' # noqa: E501 + template_name = 'contributors_sections/contributors/contributors_for_period.html' context_object_name = 'contributors_list' def get_context_data(self, **kwargs): diff --git a/contributors/views/filters.py b/contributors/views/filters.py index f494ce31..cb3ca529 100644 --- a/contributors/views/filters.py +++ b/contributors/views/filters.py @@ -94,7 +94,7 @@ class DetailTablePeriodFilter(django_filters.FilterSet): field_name='period_filter', ) - def get_contributions_by_period(self, queryset, name, value): # noqa: WPS110, E501 + def get_contributions_by_period(self, queryset, name, value): # noqa: WPS110 """Contributions filter for a period.""" if value == 'for_year': datetime_now = timezone.now() diff --git a/contributors/views/generic_list_views/pull_requests.py b/contributors/views/generic_list_views/pull_requests.py index 91fc2e40..36d836f3 100644 --- a/contributors/views/generic_list_views/pull_requests.py +++ b/contributors/views/generic_list_views/pull_requests.py @@ -23,7 +23,7 @@ class ListView(TableSortSearchAndPaginationMixin, generic.ListView): ) ordering = sortable_fields[0] - template_name = 'contributors_sections/pull_requests/pull_requests_list.html' # noqa: E501 + template_name = 'contributors_sections/pull_requests/pull_requests_list.html' def get_queryset(self): # noqa: WPS615 """Get pull requests. diff --git a/contributors/views/organizations_views/organizations.py b/contributors/views/organizations_views/organizations.py index a33f5003..ae1b7819 100644 --- a/contributors/views/organizations_views/organizations.py +++ b/contributors/views/organizations_views/organizations.py @@ -12,7 +12,7 @@ class ListView(TableSortSearchAndPaginationMixin, generic.ListView): queryset = Organization.objects.filter( repository__is_visible=True, ).distinct().annotate(repository_count=Count('repository')) - template_name = 'contributors_sections/organizations/organizations_list.html' # noqa: E501 + template_name = 'contributors_sections/organizations/organizations_list.html' sortable_fields = ( 'name', ('repository_count', _("Repositories")), diff --git a/contributors/views/repositories_views/repository.py b/contributors/views/repositories_views/repository.py index 512673eb..15033e5f 100644 --- a/contributors/views/repositories_views/repository.py +++ b/contributors/views/repositories_views/repository.py @@ -7,7 +7,7 @@ class RepoContributorList(contributors.ListView): """A repository's details.""" - template_name = 'contributors_sections/repositories/repository_details.html' # noqa: E501 + template_name = 'contributors_sections/repositories/repository_details.html' def get_queryset(self): # noqa: WPS615 """Get a dataset.""" diff --git a/setup.cfg b/setup.cfg index 755a7454..beb93595 100644 --- a/setup.cfg +++ b/setup.cfg @@ -12,7 +12,7 @@ enable-extensions = G count = True max-string-usages = 4 max-local-variables = 10 -max-line-length = 79 +max-line-length = 120 # Plugins: accept-encodings = utf-8 @@ -77,6 +77,7 @@ per-file-ignores = contributors/views/contributor_compare.py: # Found string constant over-use WPS226 + ignore = # Coding magic comment not found @@ -107,6 +108,11 @@ ignore = WPS326, # Found too many module members > 7 WPS202 + # WPS407 Found mutable module constant + WPS407 + WPS335 Found incorrect `for` loop iter type + WPS335 + [isort] multi_line_output = 3 From 883c43942b63841ead902cab371cbb1504476fdd Mon Sep 17 00:00:00 2001 From: AleksandrKosmylev Date: Sun, 30 Jun 2024 18:11:34 +0300 Subject: [PATCH 05/19] Add helper function to calc achivements percentage --- contributors/templatetags/contrib_extras.py | 10 ++++++++++ setup.cfg | 2 +- templates/components/footer.html | 4 ++-- .../contributor_achievement_percentage_field.html | 9 +++------ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/contributors/templatetags/contrib_extras.py b/contributors/templatetags/contrib_extras.py index b4a9e9c1..990c1775 100644 --- a/contributors/templatetags/contrib_extras.py +++ b/contributors/templatetags/contrib_extras.py @@ -110,3 +110,13 @@ def get_canonical_url(context): if request: return request.build_absolute_uri(request.path) return '' + + +@register.simple_tag +def calc_percent_achievement(numerator, denominator): + """Get contributor statistics and required quantity.""" + if numerator is not None: + if numerator / denominator > 1: + return 100.0 + return numerator / denominator * 100 + return 0 diff --git a/setup.cfg b/setup.cfg index beb93595..3ee6c0b9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -110,7 +110,7 @@ ignore = WPS202 # WPS407 Found mutable module constant WPS407 - WPS335 Found incorrect `for` loop iter type + # WPS335 Found incorrect `for` loop iter type WPS335 diff --git a/templates/components/footer.html b/templates/components/footer.html index 0ffb248a..767a72c8 100644 --- a/templates/components/footer.html +++ b/templates/components/footer.html @@ -13,7 +13,7 @@
  • {% trans "Other projects" %}

  • -
  • +
  • {% trans "Useful resources" %}

  • @@ -44,7 +44,7 @@
  • {% trans "Blog" %}
  • -
  • +
  • diff --git a/templates/components/tables/contributor_achievement_percentage_field.html b/templates/components/tables/contributor_achievement_percentage_field.html index bf68ebf8..87677c9e 100644 --- a/templates/components/tables/contributor_achievement_percentage_field.html +++ b/templates/components/tables/contributor_achievement_percentage_field.html @@ -1,7 +1,8 @@ {% load i18n static mathfilters %} +{% load i18n static contrib_extras %}
    -
    +
    {% trans achievement_name %}
    {% trans achievement_description %}
    @@ -9,10 +10,6 @@
    - {% if contribution|div:achievement_made_count|mul:100 > 100 %} - 100.0% - {% else %} - {{ contribution|div:achievement_made_count|mul:100|floatformat:1 }}% - {% endif %} + {% calc_percent_achievement contribution achievement_made_count %}%
    From c43a264ba9088eb75de4672cf0d903ec2dd15751 Mon Sep 17 00:00:00 2001 From: AleksandrKosmylev Date: Sun, 30 Jun 2024 18:57:01 +0300 Subject: [PATCH 06/19] fix inline styles --- static/css/base.css | 8 ++++++++ .../components/tables/achievement_percentage_field.html | 4 ++-- .../tables/contributor_achievement_percentage_field.html | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/static/css/base.css b/static/css/base.css index 8f0045b5..b1fb3912 100644 --- a/static/css/base.css +++ b/static/css/base.css @@ -200,3 +200,11 @@ a:not([class]) { a:not([class]):hover { text-decoration: underline; } + +.x-vw { + width: 50vw; +} + +.x-h { + height: max-content; +} \ No newline at end of file diff --git a/templates/components/tables/achievement_percentage_field.html b/templates/components/tables/achievement_percentage_field.html index 89f3e508..c479e2e1 100644 --- a/templates/components/tables/achievement_percentage_field.html +++ b/templates/components/tables/achievement_percentage_field.html @@ -1,8 +1,8 @@ {% load i18n static mathfilters %} -
    +
    -
    +
    {% trans achievement_name %}
    {% trans achievement_description %}
    diff --git a/templates/components/tables/contributor_achievement_percentage_field.html b/templates/components/tables/contributor_achievement_percentage_field.html index 87677c9e..b4038086 100644 --- a/templates/components/tables/contributor_achievement_percentage_field.html +++ b/templates/components/tables/contributor_achievement_percentage_field.html @@ -1,9 +1,9 @@ {% load i18n static mathfilters %} {% load i18n static contrib_extras %} -
    +
    -
    +
    {% trans achievement_name %}
    {% trans achievement_description %}
    From 8ddf4bb1eb60ab64989412cc961bd92d7a29a77a Mon Sep 17 00:00:00 2001 From: AleksandrKosmylev Date: Sun, 18 Aug 2024 18:05:21 +0300 Subject: [PATCH 07/19] update common and personal stat --- contributors/tests/test_contributors_views.py | 5 - .../views/contributor_achievements.py | 154 +++++-- setup.cfg | 10 +- ...code_edition-1.svg => code_editions-1.svg} | 0 ...tioins-1000.svg => code_editions-1000.svg} | 0 .../{comment-1.svg => comments-1.svg} | 0 .../{commit-1.svg => commits-1.svg} | 0 static/images/achievments_icons/done.svg | 4 + .../{issue-1.svg => issues-1.svg} | 0 ...pull_request-1.svg => pull_requests-1.svg} | 0 .../components/tables/achievements_list.html | 214 ++++++++-- .../tables/contributor_achievements_list.html | 375 +----------------- 12 files changed, 345 insertions(+), 417 deletions(-) rename static/images/achievments_icons/{code_edition-1.svg => code_editions-1.svg} (100%) rename static/images/achievments_icons/{code_editioins-1000.svg => code_editions-1000.svg} (100%) rename static/images/achievments_icons/{comment-1.svg => comments-1.svg} (100%) rename static/images/achievments_icons/{commit-1.svg => commits-1.svg} (100%) create mode 100644 static/images/achievments_icons/done.svg rename static/images/achievments_icons/{issue-1.svg => issues-1.svg} (100%) rename static/images/achievments_icons/{pull_request-1.svg => pull_requests-1.svg} (100%) diff --git a/contributors/tests/test_contributors_views.py b/contributors/tests/test_contributors_views.py index 6a27aae4..b4408c29 100644 --- a/contributors/tests/test_contributors_views.py +++ b/contributors/tests/test_contributors_views.py @@ -156,8 +156,3 @@ def test_get_context_data_contributor(self): for contributor in TEST_CONTRIBUTORS: response = self.client.get(reverse('contributors:contributor_achievements', args=[contributor])) self.assertEqual(response.status_code, HTTPStatus.OK) - response = self.client.get(reverse('contributors:contributor_achievements', args=[TEST_CONTRIBUTOR_LOGIN])) - self.assertEqual(response.context['contributor_commits_gte_1'], 1) - self.assertEqual(response.context['contributor_issues_gte_1'], 1) - self.assertEqual(response.context['contributor_comments_gte_1'], 1) - self.assertEqual(response.context['contributor_editions_gte_1'], 1) diff --git a/contributors/views/contributor_achievements.py b/contributors/views/contributor_achievements.py index bfe83856..6534b48a 100644 --- a/contributors/views/contributor_achievements.py +++ b/contributors/views/contributor_achievements.py @@ -14,11 +14,11 @@ class ContributorAchievementListView(generic.ListView): model = Contributor contributors = Contributor.objects.with_contributions() - pull_request_ranges_for_achievements = [100, 50, 25, 10, 1] - commit_ranges_for_achievements = [200, 100, 50, 25, 1] - issue_ranges_for_achievements = [50, 25, 10, 5, 1] - comment_ranges_for_achievements = [200, 100, 50, 25, 1] - edition_ranges_for_achievements = [1000, 500, 250, 100, 1] + pull_request_ranges_for_achievements = [1, 10, 25, 50, 100] + commit_ranges_for_achievements = [1, 25, 50, 100, 200] + issue_ranges_for_achievements = [1, 5, 10, 25, 50] + comment_ranges_for_achievements = [1, 25, 50, 100, 200] + edition_ranges_for_achievements = [1, 100, 250, 500, 1000] def get_context_data(self, **kwargs): """Add context data for achievement list.""" @@ -54,17 +54,22 @@ def get_context_data(self, **kwargs): contributor_comments=models.Sum('comments'), ) + finished = [] + unfinished = [] + context['commits'] = contributions['contributor_commits'] context['pull_requests'] = contributions['contributor_pull_requests'] context['issues'] = contributions['contributor_issues'] context['comments'] = contributions['contributor_comments'] - context['total_editions'] = sum([ + editions = sum([ 0 if edit is None else edit for edit in [ contributions['contributor_additions'], contributions['contributor_deletions'], ] ]) + context['total_editions'] = editions + context['total_actions'] = sum([ 0 if action is None else action for action in [ @@ -76,48 +81,137 @@ def get_context_data(self, **kwargs): contributions['contributor_deletions'], ] ]) + context['pull_request_ranges_for_achievements'] = ( self.pull_request_ranges_for_achievements ) context['current_contributor'] = current_contributor context['contributors_amount'] = self.contributors_amount - context['contributors_with_any_contribution'] = ( - contributors.filter(contribution_amount__gte=1).count() - ) + context['contributors_with_any_contribution'] = { + 'stat': ( + contributors.filter(contribution_amount__gte=1).count() + ), + 'acomplished': True, + } # Pull request achievements: for pr_num in self.pull_request_ranges_for_achievements: - context[f'contributor_pull_requests_gte_{pr_num}'] = pr_num - context[f'contributors_pull_requests_gte_{pr_num}'] = ( - contributors.filter(pull_requests__gte=pr_num).count() - ) + context[f'contributors_pull_requests_gte_{pr_num}'] = { + 'stat': ( + contributors.filter(pull_requests__gte=pr_num).count() + ), + 'acomplished': True, + } + a_data = { + 'img': f'images/achievments_icons/pull_requests-{pr_num}.svg', + 'name': f'Pull requests (equal to or more than {pr_num})', + 'description': f"Make pull requests in amount of equal to or more than {pr_num}", + 'accomplished': 'yes', + } + if pr_num > ( + 0 if contributions['contributor_pull_requests'] is None else contributions['contributor_pull_requests'] + ): + unfinished.append(a_data) + context[f'contributors_pull_requests_gte_{pr_num}']['acomplished'] = False + else: + finished.append(a_data) # Commit achievements: for commit_num in self.commit_ranges_for_achievements: - context[f'contributor_commits_gte_{commit_num}'] = commit_num - context[f'contributors_commits_gte_{commit_num}'] = ( - contributors.filter(commits__gte=commit_num).count() - ) + context[f'contributors_commits_gte_{commit_num}'] = { + 'stat': ( + contributors.filter(commits__gte=commit_num).count() + ), + 'acomplished': True, + } + a_data = { + 'img': f'images/achievments_icons/commits-{commit_num}.svg', + 'name': f'Commits (equal to or more than {commit_num})', + 'description': f"Make commits in amount of equal to or more than {commit_num}", + } + if commit_num > ( + 0 if contributions['contributor_commits'] is None else contributions['contributor_commits'] + ): + unfinished.append(a_data) + context[f'contributors_commits_gte_{commit_num}']['acomplished'] = False + else: + finished.append(a_data) # Issue achievements: for issue_num in self.issue_ranges_for_achievements: - context[f'contributor_issues_gte_{issue_num}'] = issue_num - context[f'contributors_issues_gte_{issue_num}'] = ( - contributors.filter(issues__gte=issue_num).count() - ) + context[f'contributors_issues_gte_{issue_num}'] = { + 'stat': ( + contributors.filter(issues__gte=issue_num).count() + ), + 'acomplished': True, + } + a_data = { + 'img': f'images/achievments_icons/issues-{issue_num}.svg', + 'name': f'Issues (equal to or more than {issue_num})', + 'description': f"Make issues in amount of equal to or more than {issue_num}", + } + if issue_num > ( + 0 if contributions['contributor_issues'] is None else contributions['contributor_issues'] + ): + unfinished.append(a_data) + context[f'contributors_issues_gte_{issue_num}']['acomplished'] = False + else: + finished.append(a_data) # Comment achievements: for comment_num in self.comment_ranges_for_achievements: - context[f'contributor_comments_gte_{comment_num}'] = comment_num - context[f'contributors_comments_gte_{comment_num}'] = ( - contributors.filter(comments__gte=comment_num).count() - ) + context[f'contributors_comments_gte_{comment_num}'] = { + 'stat': ( + contributors.filter(comments__gte=comment_num).count() + ), + 'acomplished': True, + } + a_data = { + 'img': f'images/achievments_icons/comments-{comment_num}.svg', + 'name': f'Comments (equal to or more than {comment_num})', + 'description': f"Make comments in amount of equal to or more than {comment_num}", + } + if comment_num > ( + 0 if contributions['contributor_comments'] is None else contributions['contributor_comments'] + ): + unfinished.append(a_data) + context[f'contributors_comments_gte_{comment_num}']['acomplished'] = False + else: + finished.append(a_data) # Edition achievements: for ed_num in self.edition_ranges_for_achievements: - context[f'contributor_editions_gte_{ed_num}'] = ed_num - context[f'contributors_editions_gte_{ed_num}'] = ( - contributors.filter(editions__gte=ed_num).count() - ) - + context[f'contributors_editions_gte_{ed_num}'] = { + 'stat': ( + contributors.filter(editions__gte=ed_num).count() + ), + 'acomplished': True, + } + a_data = { + 'img': f'images/achievments_icons/code_editions-{ed_num}.svg', + 'name': f'Additions and deletions (equal to or more than {ed_num})', + 'description': f"Make additions and deletions in amount of equal to or more than {ed_num}", + } + + if ed_num > editions: + unfinished.append(a_data) + context[f'contributors_editions_gte_{ed_num}']['acomplished'] = False + else: + finished.append(a_data) + + a_data = { + 'img': 'images/achievments_icons/friend.svg', + 'name': 'Hexlet friend', + 'description': "Make any contribution to Hexlet projects", + } + if finished: + finished.insert(0, a_data) + else: + unfinished.insert(0, a_data) + context['contributors_with_any_contribution']['acomplished'] = False + + context['finished'] = finished + context['unfinished'] = unfinished + context['closed'] = len(finished) + context['all_achievements'] = len(finished) + len(unfinished) return context diff --git a/setup.cfg b/setup.cfg index 3ee6c0b9..c8057c56 100644 --- a/setup.cfg +++ b/setup.cfg @@ -77,6 +77,7 @@ per-file-ignores = contributors/views/contributor_compare.py: # Found string constant over-use WPS226 + ignore = @@ -112,7 +113,14 @@ ignore = WPS407 # WPS335 Found incorrect `for` loop iter type WPS335 - + WPS226 + WPS210 + WPS213 + WPS509 + WPS231 + WPS337 + WPS204 + C901 [isort] multi_line_output = 3 diff --git a/static/images/achievments_icons/code_edition-1.svg b/static/images/achievments_icons/code_editions-1.svg similarity index 100% rename from static/images/achievments_icons/code_edition-1.svg rename to static/images/achievments_icons/code_editions-1.svg diff --git a/static/images/achievments_icons/code_editioins-1000.svg b/static/images/achievments_icons/code_editions-1000.svg similarity index 100% rename from static/images/achievments_icons/code_editioins-1000.svg rename to static/images/achievments_icons/code_editions-1000.svg diff --git a/static/images/achievments_icons/comment-1.svg b/static/images/achievments_icons/comments-1.svg similarity index 100% rename from static/images/achievments_icons/comment-1.svg rename to static/images/achievments_icons/comments-1.svg diff --git a/static/images/achievments_icons/commit-1.svg b/static/images/achievments_icons/commits-1.svg similarity index 100% rename from static/images/achievments_icons/commit-1.svg rename to static/images/achievments_icons/commits-1.svg diff --git a/static/images/achievments_icons/done.svg b/static/images/achievments_icons/done.svg new file mode 100644 index 00000000..2a663ed1 --- /dev/null +++ b/static/images/achievments_icons/done.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/static/images/achievments_icons/issue-1.svg b/static/images/achievments_icons/issues-1.svg similarity index 100% rename from static/images/achievments_icons/issue-1.svg rename to static/images/achievments_icons/issues-1.svg diff --git a/static/images/achievments_icons/pull_request-1.svg b/static/images/achievments_icons/pull_requests-1.svg similarity index 100% rename from static/images/achievments_icons/pull_request-1.svg rename to static/images/achievments_icons/pull_requests-1.svg diff --git a/templates/components/tables/achievements_list.html b/templates/components/tables/achievements_list.html index 40d6e128..f7513f15 100644 --- a/templates/components/tables/achievements_list.html +++ b/templates/components/tables/achievements_list.html @@ -2,6 +2,10 @@ {% load i18n static mathfilters %} {% block tbody %} + +
    + {% trans "Total achievements" %} {{ closed }} / {{all_achievements}} +
    - {% with achievement_name="Hexlet friend" achievement_description="Make any contribution to Hexlet projects" achievement_made_count=contributors_with_any_contribution %} + {% with achievement_name="Hexlet friend" achievement_description="Make any contribution to Hexlet projects" achievement_made_count=contributors_with_any_contribution.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_with_any_contribution.acomplished %} + + {% endif %} + @@ -29,10 +39,16 @@ width="50"> - {% with achievement_name="Pull requests (equal to or more than 1)" achievement_description="Make pull requests in amount of equal to or more than 1" achievement_made_count=contributors_pull_requests_gte_1 %} + {% with achievement_name="Pull requests (equal to or more than 1)" achievement_description="Make pull requests in amount of equal to or more than 1" achievement_made_count=contributors_pull_requests_gte_1.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_pull_requests_gte_1.acomplished %} + + {% endif %} + @@ -43,10 +59,16 @@ width="50"> - {% with achievement_name="Pull requests (equal to or more than 10)" achievement_description="Make pull requests in amount of equal to or more than 10" achievement_made_count=contributors_pull_requests_gte_10 %} + {% with achievement_name="Pull requests (equal to or more than 10)" achievement_description="Make pull requests in amount of equal to or more than 10" achievement_made_count=contributors_pull_requests_gte_10.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_pull_requests_gte_10.acomplished %} + + {% endif %} + @@ -57,10 +79,16 @@ width="50"> - {% with achievement_name="Pull requests (equal to or more than 25)" achievement_description="Make pull requests in amount of equal to or more than 25" achievement_made_count=contributors_pull_requests_gte_25 %} + {% with achievement_name="Pull requests (equal to or more than 25)" achievement_description="Make pull requests in amount of equal to or more than 25" achievement_made_count=contributors_pull_requests_gte_25.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_pull_requests_gte_25.acomplished %} + + {% endif %} + @@ -71,10 +99,16 @@ width="50"> - {% with achievement_name="Pull requests (equal to or more than 50)" achievement_description="Make pull requests in amount of equal to or more than 50" achievement_made_count=contributors_pull_requests_gte_50 %} + {% with achievement_name="Pull requests (equal to or more than 50)" achievement_description="Make pull requests in amount of equal to or more than 50" achievement_made_count=contributors_pull_requests_gte_50.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_pull_requests_gte_50.acomplished %} + + {% endif %} + @@ -85,10 +119,16 @@ width="50"> - {% with achievement_name="Pull requests (equal to or more than 100)" achievement_description="Make pull requests in amount of equal to or more than 100" achievement_made_count=contributors_pull_requests_gte_100 %} + {% with achievement_name="Pull requests (equal to or more than 100)" achievement_description="Make pull requests in amount of equal to or more than 100" achievement_made_count=contributors_pull_requests_gte_100.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_pull_requests_gte_10.acomplished %} + + {% endif %} + @@ -101,10 +141,16 @@ width="50"> - {% with achievement_name="Commits (equal to or more than 1)" achievement_description="Make commits in amount of equal to or more than 1" achievement_made_count=contributors_commits_gte_1 %} + {% with achievement_name="Commits (equal to or more than 1)" achievement_description="Make commits in amount of equal to or more than 1" achievement_made_count=contributors_commits_gte_1.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_commits_gte_1.acomplished %} + + {% endif %} + @@ -115,10 +161,16 @@ width="50"> - {% with achievement_name="Commits (equal to or more than 25)" achievement_description="Make commits in amount of equal to or more than 25" achievement_made_count=contributors_commits_gte_25 %} + {% with achievement_name="Commits (equal to or more than 25)" achievement_description="Make commits in amount of equal to or more than 25" achievement_made_count=contributors_commits_gte_25.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_commits_gte_25.acomplished %} + + {% endif %} + @@ -129,10 +181,16 @@ width="50"> - {% with achievement_name="Commits (equal to or more than 50)" achievement_description="Make commits in amount of equal to or more than 50" achievement_made_count=contributors_commits_gte_50 %} + {% with achievement_name="Commits (equal to or more than 50)" achievement_description="Make commits in amount of equal to or more than 50" achievement_made_count=contributors_commits_gte_50.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_commits_gte_50.acomplished %} + + {% endif %} + @@ -143,10 +201,16 @@ width="50"> - {% with achievement_name="Commits (equal to or more than 100)" achievement_description="Make commits in amount of equal to or more than 100" achievement_made_count=contributors_commits_gte_100 %} + {% with achievement_name="Commits (equal to or more than 100)" achievement_description="Make commits in amount of equal to or more than 100" achievement_made_count=contributors_commits_gte_100.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_commits_gte_100.acomplished %} + + {% endif %} + @@ -157,10 +221,16 @@ width="50"> - {% with achievement_name="Commits (equal to or more than 200)" achievement_description="Make commits in amount of equal to or more than 200" achievement_made_count=contributors_commits_gte_200 %} + {% with achievement_name="Commits (equal to or more than 200)" achievement_description="Make commits in amount of equal to or more than 200" achievement_made_count=contributors_commits_gte_200.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_commits_gte_200.acomplished %} + + {% endif %} + @@ -173,10 +243,16 @@ width="50"> - {% with achievement_name="Issues (equal to or more than 1)" achievement_description="Make issues in amount of equal to or more than 1" achievement_made_count=contributors_issues_gte_1 %} + {% with achievement_name="Issues (equal to or more than 1)" achievement_description="Make issues in amount of equal to or more than 1" achievement_made_count=contributors_issues_gte_1.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_issues_gte_1.acomplished %} + + {% endif %} + @@ -187,10 +263,16 @@ width="50"> - {% with achievement_name="Issues (equal to or more than 5)" achievement_description="Make issues in amount of equal to or more than 5" achievement_made_count=contributors_issues_gte_5 %} + {% with achievement_name="Issues (equal to or more than 5)" achievement_description="Make issues in amount of equal to or more than 5" achievement_made_count=contributors_issues_gte_5.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_issues_gte_5.acomplished %} + + {% endif %} + @@ -201,10 +283,16 @@ width="50"> - {% with achievement_name="Issues (equal to or more than 10)" achievement_description="Make issues in amount of equal to or more than 10" achievement_made_count=contributors_issues_gte_10 %} + {% with achievement_name="Issues (equal to or more than 10)" achievement_description="Make issues in amount of equal to or more than 10" achievement_made_count=contributors_issues_gte_10.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_issues_gte_10.acomplished %} + + {% endif %} + @@ -215,10 +303,16 @@ width="50"> - {% with achievement_name="Issues (equal to or more than 25)" achievement_description="Make issues in amount of equal to or more than 25" achievement_made_count=contributors_issues_gte_25 %} + {% with achievement_name="Issues (equal to or more than 25)" achievement_description="Make issues in amount of equal to or more than 25" achievement_made_count=contributors_issues_gte_25.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_issues_gte_25.acomplished %} + + {% endif %} + @@ -229,10 +323,16 @@ width="50"> - {% with achievement_name="Issues (equal to or more than 50)" achievement_description="Make issues in amount of equal to or more than 50" achievement_made_count=contributors_issues_gte_50 %} + {% with achievement_name="Issues (equal to or more than 50)" achievement_description="Make issues in amount of equal to or more than 50" achievement_made_count=contributors_issues_gte_50.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_issues_gte_50.acomplished %} + + {% endif %} + @@ -245,10 +345,16 @@ width="50"> - {% with achievement_name="Comments (equal to or more than 1)" achievement_description="Make comments in amount of equal to or more than 1" achievement_made_count=contributors_comments_gte_1 %} + {% with achievement_name="Comments (equal to or more than 1)" achievement_description="Make comments in amount of equal to or more than 1" achievement_made_count=contributors_comments_gte_1.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_comments_gte_1.acomplished %} + + {% endif %} + @@ -259,10 +365,16 @@ width="50"> - {% with achievement_name="Comments (equal to or more than 25)" achievement_description="Make comments in amount of equal to or more than 25" achievement_made_count=contributors_comments_gte_25 %} + {% with achievement_name="Comments (equal to or more than 25)" achievement_description="Make comments in amount of equal to or more than 25" achievement_made_count=contributors_comments_gte_25.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_comments_gte_25.acomplished %} + + {% endif %} + @@ -273,10 +385,16 @@ width="50"> - {% with achievement_name="Comments (equal to or more than 50)" achievement_description="Make comments in amount of equal to or more than 50" achievement_made_count=contributors_comments_gte_50 %} + {% with achievement_name="Comments (equal to or more than 50)" achievement_description="Make comments in amount of equal to or more than 50" achievement_made_count=contributors_comments_gte_50.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_comments_gte_50.acomplished %} + + {% endif %} + @@ -287,10 +405,16 @@ width="50"> - {% with achievement_name="Comments (equal to or more than 100)" achievement_description="Make comments in amount of equal to or more than 100" achievement_made_count=contributors_comments_gte_100 %} + {% with achievement_name="Comments (equal to or more than 100)" achievement_description="Make comments in amount of equal to or more than 100" achievement_made_count=contributors_comments_gte_100.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_comments_gte_100.acomplished %} + + {% endif %} + @@ -301,10 +425,16 @@ width="50"> - {% with achievement_name="Comments (equal to or more than 200)" achievement_description="Make comments in amount of equal to or more than 200" achievement_made_count=contributors_comments_gte_200 %} + {% with achievement_name="Comments (equal to or more than 200)" achievement_description="Make comments in amount of equal to or more than 200" achievement_made_count=contributors_comments_gte_200.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_comments_gte_200.acomplished %} + + {% endif %} + @@ -316,10 +446,16 @@ width="50"> - {% with achievement_name="Additions and deletions (equal to or more than 1)" achievement_description="Make additions and deletions in amount of equal to or more than 1" achievement_made_count=contributors_editions_gte_1 %} + {% with achievement_name="Additions and deletions (equal to or more than 1)" achievement_description="Make additions and deletions in amount of equal to or more than 1" achievement_made_count=contributors_editions_gte_1.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_editions_gte_1.acomplished %} + + {% endif %} + @@ -330,10 +466,16 @@ width="50"> - {% with achievement_name="Additions and deletions (equal to or more than 100)" achievement_description="Make additions and deletions in amount of equal to or more than 100" achievement_made_count=contributors_editions_gte_100 %} + {% with achievement_name="Additions and deletions (equal to or more than 100)" achievement_description="Make additions and deletions in amount of equal to or more than 100" achievement_made_count=contributors_editions_gte_100.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_editions_gte_100.acomplished %} + + {% endif %} + @@ -344,10 +486,16 @@ width="50"> - {% with achievement_name="Additions and deletions (equal to or more than 250)" achievement_description="Make additions and deletions in amount of equal to or more than 250" achievement_made_count=contributors_editions_gte_250 %} + {% with achievement_name="Additions and deletions (equal to or more than 250)" achievement_description="Make additions and deletions in amount of equal to or more than 250" achievement_made_count=contributors_editions_gte_250.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_editions_gte_250.acomplished %} + + {% endif %} + @@ -358,10 +506,16 @@ width="50"> - {% with achievement_name="Additions and deletions (equal to or more than 500)" achievement_description="Make additions and deletions in amount of equal to or more than 500" achievement_made_count=contributors_editions_gte_500 %} + {% with achievement_name="Additions and deletions (equal to or more than 500)" achievement_description="Make additions and deletions in amount of equal to or more than 500" achievement_made_count=contributors_editions_gte_500.stat%} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_editions_gte_500.acomplished %} + + {% endif %} + @@ -372,9 +526,17 @@ width="50"> - {% with achievement_name="Additions and deletions (equal to or more than 1000)" achievement_description="Make additions and deletions in amount of equal to or more than 1000" achievement_made_count=contributors_editions_gte_1000 %} + {% with achievement_name="Additions and deletions (equal to or more than 1000)" achievement_description="Make additions and deletions in amount of equal to or more than 1000" achievement_made_count=contributors_editions_gte_1000.stat %} {% include './achievement_percentage_field.html' %} {% endwith %} + + {% if contributors_editions_gte_1000.acomplished %} + + {% endif %} + + + {% endblock %} diff --git a/templates/components/tables/contributor_achievements_list.html b/templates/components/tables/contributor_achievements_list.html index d5006b15..ba2f51ae 100644 --- a/templates/components/tables/contributor_achievements_list.html +++ b/templates/components/tables/contributor_achievements_list.html @@ -2,379 +2,44 @@ {% load i18n static mathfilters %} {% block tbody %} - - - {% trans 'Hexlet friend' %} - - - - {% with achievement_name="Hexlet friend" achievement_description="Make any contribution to Hexlet projects" achievement_made_count=1 contribution=total_actions %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - - - {% trans 'Pull requests (equal to or more than 1)' %} - - - {% with achievement_name="Pull requests (equal to or more than 1)" achievement_description="Make pull requests in amount of equal to or more than 1" achievement_made_count=contributor_pull_requests_gte_1 contribution=pull_requests %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Pull requests (equal to or more than 10)' %} - - - {% with achievement_name="Pull requests (equal to or more than 10)" achievement_description="Make pull requests in amount of equal to or more than 10" achievement_made_count=contributor_pull_requests_gte_10 contribution=pull_requests %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - +{% for item in finished %} - {% trans 'Pull requests (equal to or more than 25)' %} - {% with achievement_name="Pull requests (equal to or more than 25)" achievement_description="Make pull requests in amount of equal to or more than 25" achievement_made_count=contributor_pull_requests_gte_25 contribution=pull_requests %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} +
    +
    +
    {{item.name}}
    +
    {{item.description}}
    +
    +
    - - - {% trans 'Pull requests (equal to or more than 50)' %} - - - {% with achievement_name="Pull requests (equal to or more than 50)" achievement_description="Make pull requests in amount of equal to or more than 50" achievement_made_count=contributor_pull_requests_gte_50 contribution=pull_requests %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Pull requests (equal to or more than 100)' %} - - - {% with achievement_name="Pull requests (equal to or more than 100)" achievement_description="Make pull requests in amount of equal to or more than 100" achievement_made_count=contributor_pull_requests_gte_100 contribution=pull_requests %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - +{% endfor %} - - - {% trans 'Commits (equal to or more than 1)' %} - - - {% with achievement_name="Commits (equal to or more than 1)" achievement_description="Make commits in amount of equal to or more than 1" achievement_made_count=contributor_commits_gte_1 contribution=commits %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Commits (equal to or more than 25)' %} - - - {% with achievement_name="Commits (equal to or more than 25)" achievement_description="Make commits in amount of equal to or more than 25" achievement_made_count=contributor_commits_gte_25 contribution=commits %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Commits (equal to or more than 50)' %} - - - {% with achievement_name="Commits (equal to or more than 50)" achievement_description="Make commits in amount of equal to or more than 50" achievement_made_count=contributor_commits_gte_50 contribution=commits %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Commits (equal to or more than 100)' %} - - - {% with achievement_name="Commits (equal to or more than 100)" achievement_description="Make commits in amount of equal to or more than 100" achievement_made_count=contributor_commits_gte_100 contribution=commits %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Commits (equal to or more than 200)' %} - - - {% with achievement_name="Commits (equal to or more than 200)" achievement_description="Make commits in amount of equal to or more than 200" achievement_made_count=contributor_commits_gte_200 contribution=commits %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - - - {% trans 'Issues (equal to or more than 1)' %} - - - {% with achievement_name="Issues (equal to or more than 1)" achievement_description="Make issues in amount of equal to or more than 1" achievement_made_count=contributor_issues_gte_1 contribution=issues %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Issues (equal to or more than 5)' %} - - - {% with achievement_name="Issues (equal to or more than 5)" achievement_description="Make issues in amount of equal to or more than 5" achievement_made_count=contributor_issues_gte_5 contribution=issues %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Issues (equal to or more than 10)' %} - - - {% with achievement_name="Issues (equal to or more than 10)" achievement_description="Make issues in amount of equal to or more than 10" achievement_made_count=contributor_issues_gte_10 contribution=issues %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Issues (equal to or more than 25)' %} - - - {% with achievement_name="Issues (equal to or more than 25)" achievement_description="Make issues in amount of equal to or more than 25" achievement_made_count=contributor_issues_gte_25 contribution=issues %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Issues (equal to or more than 50)' %} - - - {% with achievement_name="Issues (equal to or more than 50)" achievement_description="Make issues in amount of equal to or more than 50" achievement_made_count=contributor_issues_gte_50 contribution=issues %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - +
    +{% for item in unfinished %} - {% trans 'Comments (equal to or more than 1)' %} - {% with achievement_name="Comments (equal to or more than 1)" achievement_description="Make comments in amount of equal to or more than 1" achievement_made_count=contributor_comments_gte_1 contribution=comments %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Comments (equal to or more than 25)' %} - - - {% with achievement_name="Comments (equal to or more than 25)" achievement_description="Make comments in amount of equal to or more than 25" achievement_made_count=contributor_comments_gte_25 contribution=comments %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Comments (equal to or more than 50)' %} - - - {% with achievement_name="Comments (equal to or more than 50)" achievement_description="Make comments in amount of equal to or more than 50" achievement_made_count=contributor_comments_gte_50 contribution=comments %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Comments (equal to or more than 100)' %} - - - {% with achievement_name="Comments (equal to or more than 100)" achievement_description="Make comments in amount of equal to or more than 100" achievement_made_count=contributor_comments_gte_100 contribution=comments %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Comments (equal to or more than 200)' %} - - - {% with achievement_name="Comments (equal to or more than 200)" achievement_description="Make comments in amount of equal to or more than 200" achievement_made_count=contributor_comments_gte_200 contribution=comments %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} +
    +
    +
    {{item.name}}
    +
    {{item.description}}
    +
    +
    +{% endfor %} - - - {% trans 'Additions and deletions (equal to or more than 1)' %} - - - {% with achievement_name="Additions and deletions (equal to or more than 1)" achievement_description="Make additions and deletions in amount of equal to or more than 1" achievement_made_count=contributor_editions_gte_1 contribution=total_editions %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Additions and deletions (equal to or more than 100)' %} - - - {% with achievement_name="Additions and deletions (equal to or more than 100)" achievement_description="Make additions and deletions in amount of equal to or more than 100" achievement_made_count=contributor_editions_gte_100 contribution=total_editions %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Additions and deletions (equal to or more than 250)' %} - - - {% with achievement_name="Additions and deletions (equal to or more than 250)" achievement_description="Make additions and deletions in amount of equal to or more than 250" achievement_made_count=contributor_editions_gte_250 contribution=total_editions %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Additions and deletions (equal to or more than 500)' %} - - - {% with achievement_name="Additions and deletions (equal to or more than 500)" achievement_description="Make additions and deletions in amount of equal to or more than 500" achievement_made_count=contributor_editions_gte_500 contribution=total_editions %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - - - - {% trans 'Additions and deletions (equal to or more than 1000)' %} - - - {% with achievement_name="Additions and deletions (equal to or more than 1000)" achievement_description="Make additions and deletions in amount of equal to or more than 1000" achievement_made_count=contributor_editions_gte_1000 contribution=total_editions %} - {% include './contributor_achievement_percentage_field.html' %} - {% endwith %} - - -{% endblock %} +{% endblock %} \ No newline at end of file From 23abc8ce2405cbb4b9270c4ecbdfb6f200b437ac Mon Sep 17 00:00:00 2001 From: AleksandrKosmylev Date: Sun, 6 Oct 2024 19:50:49 +0300 Subject: [PATCH 08/19] resolve conflict --- contributors/management/commands/fetchdata.py | 2 +- contributors/models/contribution.py | 4 ++-- contributors/utils/github_lib.py | 2 +- contributors/views/config.py | 2 +- contributors/views/contributors_views/contributor.py | 2 +- contributors/views/filters.py | 2 +- setup.cfg | 5 +++++ 7 files changed, 12 insertions(+), 7 deletions(-) diff --git a/contributors/management/commands/fetchdata.py b/contributors/management/commands/fetchdata.py index 9b60551d..c8b5c94f 100644 --- a/contributors/management/commands/fetchdata.py +++ b/contributors/management/commands/fetchdata.py @@ -158,7 +158,7 @@ def handle( # noqa: C901,WPS110,WPS213,WPS231,WPS210 if repo['name'] not in IGNORED_REPOSITORIES ] number_of_repos = len(repos_to_process) - for i, repo_data in enumerate(repos_to_process, start=1): # noqa: WPS111 + for i, repo_data in enumerate(repos_to_process, start=1): # noqa: E501 repo, _ = misc.update_or_create_record(Repository, repo_data) logger.info(f"{repo} ({i}/{number_of_repos})") if repo_data['size'] == 0: diff --git a/contributors/models/contribution.py b/contributors/models/contribution.py index 41b1a35e..3d6ea5c9 100644 --- a/contributors/models/contribution.py +++ b/contributors/models/contribution.py @@ -88,8 +88,8 @@ class Contribution(models.Model): on_delete=models.CASCADE, verbose_name=_("contributor"), ) - id = models.CharField(primary_key=True, max_length=ID_LENGTH) # noqa: A003,WPS125 - type = models.CharField(_("type"), choices=TYPES, max_length=TYPE_LENGTH) # noqa: A003,WPS125 + id = models.CharField(primary_key=True, max_length=ID_LENGTH) # noqa: A003,E501 + type = models.CharField(_("type"), choices=TYPES, max_length=TYPE_LENGTH) # noqa: A003,E501 html_url = models.URLField(_("URL")) created_at = models.DateTimeField(_("creation date")) diff --git a/contributors/utils/github_lib.py b/contributors/utils/github_lib.py index d0cf1d15..4bcc882c 100644 --- a/contributors/utils/github_lib.py +++ b/contributors/utils/github_lib.py @@ -402,7 +402,7 @@ def get_commit_stats_for_contributor(repo_full_name, contributor_id): return totals['c'], totals['a'], totals['d'] -def get_data_of_owners_and_repos(*, owner_names=None, repo_full_names=None): # noqa: C901,R701,WPS231 +def get_data_of_owners_and_repos(*, owner_names=None, repo_full_names=None): # noqa: C901,R701,E501 """Return data of owners and their repositories from GitHub.""" if not (owner_names or repo_full_names): raise ValueError("Neither owner_names nor repo_full_names is provided") diff --git a/contributors/views/config.py b/contributors/views/config.py index bc9cc2e7..f4a3ec94 100644 --- a/contributors/views/config.py +++ b/contributors/views/config.py @@ -62,7 +62,7 @@ def collect_data(request): repo.is_visible = True Repository.objects.bulk_update(repos, ['is_tracked', 'is_visible']) fetch_command = ['./manage.py', 'fetchdata', '--repo'] - fetch_command.extend([repo.full_name for repo in repos]) # noqa: WPS441 + fetch_command.extend([repo.full_name for repo in repos]) # noqa: E501 subprocess.Popen(fetch_command) # noqa: S603 return TemplateResponse(request, 'admin/data_collection.html', context) return HttpResponseForbidden("Forbidden.") diff --git a/contributors/views/contributors_views/contributor.py b/contributors/views/contributors_views/contributor.py index ed181e8d..47d623e8 100644 --- a/contributors/views/contributors_views/contributor.py +++ b/contributors/views/contributors_views/contributor.py @@ -46,7 +46,7 @@ def get_context_data(self, **kwargs): self.object.contribution_set.for_year() ) context['top_repository'] = repositories.annotate( - summary=F('commits') + F('pull_requests') + F('issues') + F('comments'), # noqa: WPS221 + summary=F('commits') + F('pull_requests') + F('issues') + F('comments'), # noqa: E501 ).order_by('-summary').first() context['summary'] = Contribution.objects.filter( diff --git a/contributors/views/filters.py b/contributors/views/filters.py index 6e0727dd..2e1d68ff 100644 --- a/contributors/views/filters.py +++ b/contributors/views/filters.py @@ -90,7 +90,7 @@ class DetailTablePeriodFilter(django_filters.FilterSet): field_name='period_filter', ) - def get_contributions_by_period(self, queryset, name, value): # noqa: WPS110 + def get_contributions_by_period(self, queryset, name, value): """Contributions filter for a period.""" if value == 'for_year': datetime_now = timezone.now() diff --git a/setup.cfg b/setup.cfg index c8057c56..38038256 100644 --- a/setup.cfg +++ b/setup.cfg @@ -121,6 +121,11 @@ ignore = WPS337 WPS204 C901 + # Found control variable used after block + WPS441 + WPS110 + WPS221 + WPS111 [isort] multi_line_output = 3 From eb11834580cc836ccad25ba1ce0df15facddaf71 Mon Sep 17 00:00:00 2001 From: AleksandrKosmylev Date: Sun, 6 Oct 2024 20:34:39 +0300 Subject: [PATCH 09/19] resolve wps --- setup.cfg | 58 +++++-------------------------------------------------- 1 file changed, 5 insertions(+), 53 deletions(-) diff --git a/setup.cfg b/setup.cfg index 38038256..d2a7ecca 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,6 +21,8 @@ radon-max-cc = 10 radon-no-assert = True radon-show-closures = True + + # Exclude some directories: exclude = .git @@ -31,36 +33,19 @@ exclude = # Ignore some checks for Django's standard files: per-file-ignores = config/*.py manage.py: - # Found line with high Jones Complexity - WPS221, - # Found string constant over-use - WPS226, - # Found mutable module constant - WPS407, - # Found nested import - WPS433 # Possible binding to all interfaces. S104, contrib_extras.py: # Found string constant over-use - WPS226 + __init__.py: # imported but unused F401 github_lib.py, github_webhook.py, misc.py: - # Found too many module members - WPS202, - # Found line with high Jones Complexity - WPS221, - # Found string constant over-use - WPS226, - # Found block variables overlap - WPS440, - # Found control variable used after block - WPS441 + fetchdata.py: # Found too high module cognitive complexity @@ -69,18 +54,10 @@ per-file-ignores = */tests/*.py: # Missing docstring in public method D102 - - contributors/views/contributor.py: - # Found string constant over-use - WPS226 - contributors/views/contributor_compare.py: - # Found string constant over-use - WPS226 - - ignore = + WPS, # Coding magic comment not found C101, # Missing parameter(s) in Docstring @@ -99,33 +76,8 @@ ignore = D106, # Remove bad quotes Q000, - # Found `f` string - WPS305, - # Found `__init__.py` module with logic - WPS412, - # Line break before binary operator W503, - # Found implicit string concatenation - WPS326, - # Found too many module members > 7 - WPS202 - # WPS407 Found mutable module constant - WPS407 - # WPS335 Found incorrect `for` loop iter type - WPS335 - WPS226 - WPS210 - WPS213 - WPS509 - WPS231 - WPS337 - WPS204 C901 - # Found control variable used after block - WPS441 - WPS110 - WPS221 - WPS111 [isort] multi_line_output = 3 From 38497071d059d631cdd1835baa1196b2d005b67e Mon Sep 17 00:00:00 2001 From: AleksandrKosmylev Date: Sun, 6 Oct 2024 20:44:05 +0300 Subject: [PATCH 10/19] resolve wps editon 1 --- setup.cfg | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index d2a7ecca..984a2b15 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,7 +39,6 @@ per-file-ignores = contrib_extras.py: # Found string constant over-use - __init__.py: # imported but unused F401 @@ -55,7 +54,6 @@ per-file-ignores = # Missing docstring in public method D102 - ignore = WPS, # Coding magic comment not found From f9c26ed8fe7e4c2e0d64922576fa56f2fe09c4c7 Mon Sep 17 00:00:00 2001 From: AleksandrKosmylev Date: Sun, 6 Oct 2024 20:46:12 +0300 Subject: [PATCH 11/19] resolve wps editon 2 --- setup.cfg | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/setup.cfg b/setup.cfg index 984a2b15..92b22b5f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -45,6 +45,11 @@ per-file-ignores = github_lib.py, github_webhook.py, misc.py: + contributors/views/contributor.py: + # No specific ignore rules needed + + contributors/views/contributor_compare.py: + # No specific ignore rules needed fetchdata.py: # Found too high module cognitive complexity From fa49f249328b723b7ff7f8d5b1e7c3e3442bfa72 Mon Sep 17 00:00:00 2001 From: AleksandrKosmylev Date: Sun, 6 Oct 2024 20:51:20 +0300 Subject: [PATCH 12/19] resolve wps editon 3 --- setup.cfg | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/setup.cfg b/setup.cfg index 92b22b5f..b7cf2210 100644 --- a/setup.cfg +++ b/setup.cfg @@ -37,7 +37,7 @@ per-file-ignores = S104, contrib_extras.py: - # Found string constant over-use + # No specific ignore rules needed __init__.py: # imported but unused @@ -45,12 +45,6 @@ per-file-ignores = github_lib.py, github_webhook.py, misc.py: - contributors/views/contributor.py: - # No specific ignore rules needed - - contributors/views/contributor_compare.py: - # No specific ignore rules needed - fetchdata.py: # Found too high module cognitive complexity WPS232 From a068fe8e55d5d319e9efa308ef2b43ee10d9035b Mon Sep 17 00:00:00 2001 From: AleksandrKosmylev Date: Sun, 6 Oct 2024 20:53:07 +0300 Subject: [PATCH 13/19] resolve wps editon 4 --- setup.cfg | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/setup.cfg b/setup.cfg index b7cf2210..931547f7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,6 +44,7 @@ per-file-ignores = F401 github_lib.py, github_webhook.py, misc.py: + # No specific ignore rules needed fetchdata.py: # Found too high module cognitive complexity @@ -52,6 +53,11 @@ per-file-ignores = */tests/*.py: # Missing docstring in public method D102 + contributors/views/contributor.py: + # No specific ignore rules needed + + contributors/views/contributor_compare.py: + # No specific ignore rules needed ignore = WPS, From 439944b074a02bd90ea3f2f58d7a361b43221d7d Mon Sep 17 00:00:00 2001 From: AleksandrKosmylev Date: Sun, 6 Oct 2024 21:07:35 +0300 Subject: [PATCH 14/19] resolve wps editon 6 --- setup.cfg | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index 931547f7..ce7acf71 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,7 +16,7 @@ max-line-length = 120 # Plugins: accept-encodings = utf-8 -max-complexity = 6 +max-complexity = 12 radon-max-cc = 10 radon-no-assert = True radon-show-closures = True @@ -79,8 +79,7 @@ ignore = D106, # Remove bad quotes Q000, - W503, - C901 + W503 [isort] multi_line_output = 3 From be1689c91167648dccbafa9ae5fbb56b278ee216 Mon Sep 17 00:00:00 2001 From: AleksandrKosmylev Date: Sun, 6 Oct 2024 21:08:46 +0300 Subject: [PATCH 15/19] resolve wps editon 7 --- setup.cfg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.cfg b/setup.cfg index ce7acf71..88c509da 100644 --- a/setup.cfg +++ b/setup.cfg @@ -79,8 +79,10 @@ ignore = D106, # Remove bad quotes Q000, + # Line break before binary operator W503 + [isort] multi_line_output = 3 include_trailing_comma = true From 91289fb7d5b8cf6212286bfc7dc8a3b89ccba9ba Mon Sep 17 00:00:00 2001 From: AleksandrKosmylev Date: Sun, 27 Oct 2024 21:50:22 +0300 Subject: [PATCH 16/19] fix linter notifications --- contributors/models/__init__.py | 13 +++++++++++++ setup.cfg | 10 ++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/contributors/models/__init__.py b/contributors/models/__init__.py index d0e88467..73d2fd5b 100644 --- a/contributors/models/__init__.py +++ b/contributors/models/__init__.py @@ -8,3 +8,16 @@ from contributors.models.organization import Organization from contributors.models.project import Project from contributors.models.repository import Repository + +__all__ = [ + 'CommonFields', + 'CommitStats', + 'Contribution', + 'ContributionLabel', + 'Contributor', + 'IssueInfo', + 'Label', + 'Organization', + 'Project', + 'Repository', +] diff --git a/setup.cfg b/setup.cfg index 9098a0c4..7880932f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -48,11 +48,7 @@ per-file-ignores = fetchdata.py: # No specific ignore rules needed - */tests/*.py: - # Missing docstring in public method - D102 - contributors/views/contributor.py: - # No specific ignore rules needed + ./contributors/models/*.py: E501 contributors/views/contributor_compare.py: # No specific ignore rules needed @@ -78,7 +74,9 @@ ignore = # Remove bad quotes Q000, # Line break before binary operator - W503 + W503, + # Missing docstring in public method + D102 [isort] From 130b868c801a8778956dab4440871688002a003b Mon Sep 17 00:00:00 2001 From: AleksandrKosmylev Date: Sun, 27 Oct 2024 22:01:39 +0300 Subject: [PATCH 17/19] fix linter notifications --- contributors/tests/test_contributors_views.py | 5 ++- .../views/contributor_achievements.py | 45 +++++++++++++------ contributors/views/contributor_compare.py | 3 +- setup.cfg | 2 +- 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/contributors/tests/test_contributors_views.py b/contributors/tests/test_contributors_views.py index b4408c29..720f86b5 100644 --- a/contributors/tests/test_contributors_views.py +++ b/contributors/tests/test_contributors_views.py @@ -154,5 +154,8 @@ def test_get_context_data(self): def test_get_context_data_contributor(self): for contributor in TEST_CONTRIBUTORS: - response = self.client.get(reverse('contributors:contributor_achievements', args=[contributor])) + response = self.client.get(reverse( + 'contributors:contributor_achievements', + args=[contributor]), + ) self.assertEqual(response.status_code, HTTPStatus.OK) diff --git a/contributors/views/contributor_achievements.py b/contributors/views/contributor_achievements.py index 6534b48a..6c0c9a3e 100644 --- a/contributors/views/contributor_achievements.py +++ b/contributors/views/contributor_achievements.py @@ -41,8 +41,12 @@ def get_context_data(self, **kwargs): pull_requests=models.Count( 'contribution', filter=models.Q(contribution__type='pr'), ), - issues=models.Count('contribution', filter=models.Q(contribution__type='iss')), - comments=models.Count('contribution', filter=models.Q(contribution__type='cnt')), + issues=models.Count( + 'contribution', + filter=models.Q(contribution__type='iss')), + comments=models.Count( + 'contribution', + filter=models.Q(contribution__type='cnt')), ).order_by('organization', 'name') contributions = repositories.values().aggregate( @@ -105,14 +109,17 @@ def get_context_data(self, **kwargs): a_data = { 'img': f'images/achievments_icons/pull_requests-{pr_num}.svg', 'name': f'Pull requests (equal to or more than {pr_num})', - 'description': f"Make pull requests in amount of equal to or more than {pr_num}", + 'description': + f"Make pull requests in amount of equal to or more than {pr_num}", 'accomplished': 'yes', } if pr_num > ( - 0 if contributions['contributor_pull_requests'] is None else contributions['contributor_pull_requests'] + 0 if contributions['contributor_pull_requests'] is None + else contributions['contributor_pull_requests'] ): unfinished.append(a_data) - context[f'contributors_pull_requests_gte_{pr_num}']['acomplished'] = False + context[(f'contributors_pull_requests_gte_' + f'{pr_num}')]['acomplished'] = False else: finished.append(a_data) @@ -127,10 +134,12 @@ def get_context_data(self, **kwargs): a_data = { 'img': f'images/achievments_icons/commits-{commit_num}.svg', 'name': f'Commits (equal to or more than {commit_num})', - 'description': f"Make commits in amount of equal to or more than {commit_num}", + 'description': f"Make commits in amount of equal to or more than " + f"{commit_num}", } if commit_num > ( - 0 if contributions['contributor_commits'] is None else contributions['contributor_commits'] + 0 if contributions['contributor_commits'] is None + else contributions['contributor_commits'] ): unfinished.append(a_data) context[f'contributors_commits_gte_{commit_num}']['acomplished'] = False @@ -148,10 +157,12 @@ def get_context_data(self, **kwargs): a_data = { 'img': f'images/achievments_icons/issues-{issue_num}.svg', 'name': f'Issues (equal to or more than {issue_num})', - 'description': f"Make issues in amount of equal to or more than {issue_num}", + 'description': f"Make issues in amount of equal to or more than " + f"{issue_num}", } if issue_num > ( - 0 if contributions['contributor_issues'] is None else contributions['contributor_issues'] + 0 if contributions['contributor_issues'] is None + else contributions['contributor_issues'] ): unfinished.append(a_data) context[f'contributors_issues_gte_{issue_num}']['acomplished'] = False @@ -169,13 +180,16 @@ def get_context_data(self, **kwargs): a_data = { 'img': f'images/achievments_icons/comments-{comment_num}.svg', 'name': f'Comments (equal to or more than {comment_num})', - 'description': f"Make comments in amount of equal to or more than {comment_num}", + 'description': f"Make comments in amount of equal to or more than " + f"{comment_num}", } if comment_num > ( - 0 if contributions['contributor_comments'] is None else contributions['contributor_comments'] + 0 if contributions['contributor_comments'] is None + else contributions['contributor_comments'] ): unfinished.append(a_data) - context[f'contributors_comments_gte_{comment_num}']['acomplished'] = False + context[(f'contributors_comments_gte_' + f'{comment_num}')]['acomplished'] = False else: finished.append(a_data) @@ -188,9 +202,12 @@ def get_context_data(self, **kwargs): 'acomplished': True, } a_data = { - 'img': f'images/achievments_icons/code_editions-{ed_num}.svg', + 'img': + f'images/achievments_icons/code_editions-{ed_num}.svg', 'name': f'Additions and deletions (equal to or more than {ed_num})', - 'description': f"Make additions and deletions in amount of equal to or more than {ed_num}", + 'description': + f"Make additions and" + f" deletions in amount of equal to or more than {ed_num}", } if ed_num > editions: diff --git a/contributors/views/contributor_compare.py b/contributors/views/contributor_compare.py index d7789d66..9b92818d 100644 --- a/contributors/views/contributor_compare.py +++ b/contributors/views/contributor_compare.py @@ -9,7 +9,8 @@ class CompareWithYourselfView(ListView): """View of comparing current user with another one.""" model = Contribution - template_name = 'contributors_sections/contributors/contributor_compare_with_yourself.html' + template_name = ('contributors_sections/' + 'contributors/contributor_compare_with_yourself.html') slug_field = 'contributor' def get_queryset(self): diff --git a/setup.cfg b/setup.cfg index 7880932f..418b94d2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -11,7 +11,7 @@ enable-extensions = G count = True max-string-usages = 4 max-local-variables = 10 -max-line-length = 120 +max-line-length = 89 # Plugins: accept-encodings = utf-8 From 4b3067c15b373dd789aed6c878e55ce9b1e31f25 Mon Sep 17 00:00:00 2001 From: lc Date: Sun, 17 Nov 2024 20:48:40 +0300 Subject: [PATCH 18/19] refactor contributor_achievements.py --- .../views/contributor_achievements.py | 354 ++++++++++-------- .../components/tables/achievements_list.html | 12 +- 2 files changed, 213 insertions(+), 153 deletions(-) diff --git a/contributors/views/contributor_achievements.py b/contributors/views/contributor_achievements.py index 6c0c9a3e..946687a7 100644 --- a/contributors/views/contributor_achievements.py +++ b/contributors/views/contributor_achievements.py @@ -25,11 +25,24 @@ def get_context_data(self, **kwargs): self.contributors_amount = Contributor.objects.count() context = super().get_context_data(**kwargs) contributors = Contributor.objects.with_contributions() - current_contributor = ( - Contributor.objects.get(login=self.kwargs['slug']) - ) + current_contributor = self._get_cur_contributor() + repositories = self._get_repositories(current_contributor) + contributions = self._aggregate_contributions(repositories) + + context.update(self._calculate_achievements(contributors, contributions)) + + context['current_contributor'] = current_contributor + context['contributors_amount'] = self.contributors_amount + context['contributors_with_any_contribution'] = ( + self._contributors_with_any_contribution(contributors)) + return context - repositories = Repository.objects.select_related( + def _get_cur_contributor(self): + return Contributor.objects.get(login=self.kwargs['slug']) + + def _get_repositories(self, current_contributor): + """Get repositories where the current contributor made contributions.""" + return Repository.objects.select_related( 'organization', ).filter( is_visible=True, @@ -49,7 +62,9 @@ def get_context_data(self, **kwargs): filter=models.Q(contribution__type='cnt')), ).order_by('organization', 'name') - contributions = repositories.values().aggregate( + def _aggregate_contributions(self, repositories): + """Aggregate all the contributions for the contributor.""" + return repositories.values().aggregate( contributor_deletions=models.Sum('deletions'), contributor_additions=models.Sum('additions'), contributor_commits=models.Sum('commits'), @@ -58,177 +73,222 @@ def get_context_data(self, **kwargs): contributor_comments=models.Sum('comments'), ) + def _calculate_achievements(self, contributors, contributions): + """Calculate achievements for various contribution types.""" finished = [] unfinished = [] - context['commits'] = contributions['contributor_commits'] - context['pull_requests'] = contributions['contributor_pull_requests'] - context['issues'] = contributions['contributor_issues'] - context['comments'] = contributions['contributor_comments'] - editions = sum([ - 0 if edit is None else edit - for edit in [ - contributions['contributor_additions'], - contributions['contributor_deletions'], - ] - ]) - context['total_editions'] = editions - - context['total_actions'] = sum([ - 0 if action is None else action - for action in [ - contributions['contributor_commits'], - contributions['contributor_pull_requests'], - contributions['contributor_issues'], - contributions['contributor_comments'], - contributions['contributor_additions'], - contributions['contributor_deletions'], - ] - ]) + context = { + 'commits': contributions['contributor_commits'], + 'pull_requests': contributions['contributor_pull_requests'], + 'issues': contributions['contributor_issues'], + 'comments': contributions['contributor_comments'], + 'total_editions': self._calculate_editions(contributions), + 'total_actions': self._calculate_total_actions(contributions), + 'pull_request_ranges_for_achievements': + self.pull_request_ranges_for_achievements, + } - context['pull_request_ranges_for_achievements'] = ( - self.pull_request_ranges_for_achievements + # Process each type of achievement + finished, unfinished = self._process_achievements( + finished, unfinished, context, contributors, contributions ) - context['current_contributor'] = current_contributor - context['contributors_amount'] = self.contributors_amount - context['contributors_with_any_contribution'] = { - 'stat': ( - contributors.filter(contribution_amount__gte=1).count() - ), - 'acomplished': True, - } + context['finished'] = finished + context['unfinished'] = unfinished + context['closed'] = len(finished) + context['all_achievements'] = len(finished) + len(unfinished) + return context + def _process_achievements( + self, finished, unfinished, context, contributors, contributions + ): + """Process all achievements types (pull request, commit, etc.).""" # Pull request achievements: + finished, unfinished = self._process_pull_request_achievements( + finished, unfinished, context, contributors, contributions + ) + + # Commit achievements: + finished, unfinished = self._process_commit_achievements( + finished, unfinished, context, contributors, contributions + ) + + # Issue achievements: + finished, unfinished = self._process_issue_achievements( + finished, unfinished, context, contributors, contributions + ) + + # Comment achievements: + finished, unfinished = self._process_comment_achievements( + finished, unfinished, context, contributors, contributions + ) + + # Edition achievements: + finished, unfinished = self._process_edition_achievements( + finished, unfinished, context, contributors, contributions + ) + + return finished, unfinished + + def _process_pull_request_achievements( + self, finished, unfinished, context, contributors, contributions + ): + """Process achievements related to pull requests.""" for pr_num in self.pull_request_ranges_for_achievements: context[f'contributors_pull_requests_gte_{pr_num}'] = { - 'stat': ( - contributors.filter(pull_requests__gte=pr_num).count() + 'stat': contributors.filter(pull_requests__gte=pr_num).count(), + 'acomplished': + self._get_cur_contributor() in contributors.filter( + pull_requests__gte=pr_num ), - 'acomplished': True, } - a_data = { - 'img': f'images/achievments_icons/pull_requests-{pr_num}.svg', - 'name': f'Pull requests (equal to or more than {pr_num})', - 'description': - f"Make pull requests in amount of equal to or more than {pr_num}", - 'accomplished': 'yes', - } - if pr_num > ( - 0 if contributions['contributor_pull_requests'] is None - else contributions['contributor_pull_requests'] - ): - unfinished.append(a_data) - context[(f'contributors_pull_requests_gte_' - f'{pr_num}')]['acomplished'] = False - else: - finished.append(a_data) + a_data = self._create_achievement_data( + pr_num, 'pull_requests', 'Pull requests' + ) + finished, unfinished = self._update_achievement_status( + pr_num, + contributions['contributor_pull_requests'], + a_data, + finished, + unfinished + ) + return finished, unfinished - # Commit achievements: + def _process_commit_achievements( + self, finished, unfinished, context, contributors, contributions + ): + """Process achievements related to commits.""" for commit_num in self.commit_ranges_for_achievements: context[f'contributors_commits_gte_{commit_num}'] = { - 'stat': ( - contributors.filter(commits__gte=commit_num).count() + 'stat': contributors.filter(commits__gte=commit_num).count(), + 'acomplished': + self._get_cur_contributor() in contributors.filter( + commits__gte=commit_num ), - 'acomplished': True, } - a_data = { - 'img': f'images/achievments_icons/commits-{commit_num}.svg', - 'name': f'Commits (equal to or more than {commit_num})', - 'description': f"Make commits in amount of equal to or more than " - f"{commit_num}", - } - if commit_num > ( - 0 if contributions['contributor_commits'] is None - else contributions['contributor_commits'] - ): - unfinished.append(a_data) - context[f'contributors_commits_gte_{commit_num}']['acomplished'] = False - else: - finished.append(a_data) + a_data = self._create_achievement_data( + commit_num, 'commits', 'Commits' + ) + finished, unfinished = self._update_achievement_status( + commit_num, + contributions['contributor_commits'], + a_data, + finished, + unfinished + ) + return finished, unfinished - # Issue achievements: + def _process_issue_achievements( + self, finished, unfinished, context, contributors, contributions + ): + """Process achievements related to issues.""" for issue_num in self.issue_ranges_for_achievements: context[f'contributors_issues_gte_{issue_num}'] = { - 'stat': ( - contributors.filter(issues__gte=issue_num).count() - ), - 'acomplished': True, - } - a_data = { - 'img': f'images/achievments_icons/issues-{issue_num}.svg', - 'name': f'Issues (equal to or more than {issue_num})', - 'description': f"Make issues in amount of equal to or more than " - f"{issue_num}", + 'stat': contributors.filter(issues__gte=issue_num).count(), + 'acomplished': + self._get_cur_contributor() in contributors.filter( + issues__gte=issue_num), } - if issue_num > ( - 0 if contributions['contributor_issues'] is None - else contributions['contributor_issues'] - ): - unfinished.append(a_data) - context[f'contributors_issues_gte_{issue_num}']['acomplished'] = False - else: - finished.append(a_data) + a_data = self._create_achievement_data( + issue_num, 'issues', 'Issues' + ) + finished, unfinished = self._update_achievement_status( + issue_num, + contributions['contributor_issues'], + a_data, + finished, + unfinished + ) + return finished, unfinished - # Comment achievements: + def _process_comment_achievements( + self, finished, unfinished, context, contributors, contributions + ): + """Process achievements related to comments.""" for comment_num in self.comment_ranges_for_achievements: context[f'contributors_comments_gte_{comment_num}'] = { - 'stat': ( - contributors.filter(comments__gte=comment_num).count() - ), - 'acomplished': True, - } - a_data = { - 'img': f'images/achievments_icons/comments-{comment_num}.svg', - 'name': f'Comments (equal to or more than {comment_num})', - 'description': f"Make comments in amount of equal to or more than " - f"{comment_num}", + 'stat': contributors.filter(comments__gte=comment_num).count(), + 'acomplished': + self._get_cur_contributor() in contributors.filter( + comments__gte=comment_num), } - if comment_num > ( - 0 if contributions['contributor_comments'] is None - else contributions['contributor_comments'] - ): - unfinished.append(a_data) - context[(f'contributors_comments_gte_' - f'{comment_num}')]['acomplished'] = False - else: - finished.append(a_data) + a_data = self._create_achievement_data( + comment_num, 'comments', 'Comments' + ) + finished, unfinished = self._update_achievement_status( + comment_num, + contributions['contributor_comments'], + a_data, + finished, + unfinished + ) + return finished, unfinished - # Edition achievements: + def _process_edition_achievements( + self, finished, unfinished, context, contributors, contributions + ): + """Process achievements related to code editions (additions + deletions).""" + editions = self._calculate_editions(contributions) for ed_num in self.edition_ranges_for_achievements: context[f'contributors_editions_gte_{ed_num}'] = { - 'stat': ( - contributors.filter(editions__gte=ed_num).count() - ), - 'acomplished': True, + 'stat': contributors.filter(editions__gte=ed_num).count(), + 'acomplished': + self._get_cur_contributor() in contributors.filter( + editions__gte=ed_num), } - a_data = { - 'img': - f'images/achievments_icons/code_editions-{ed_num}.svg', - 'name': f'Additions and deletions (equal to or more than {ed_num})', - 'description': - f"Make additions and" - f" deletions in amount of equal to or more than {ed_num}", - } - - if ed_num > editions: - unfinished.append(a_data) - context[f'contributors_editions_gte_{ed_num}']['acomplished'] = False - else: - finished.append(a_data) + a_data = self._create_achievement_data( + ed_num, 'code_editions', 'Additions and deletions' + ) + finished, unfinished = self._update_achievement_status( + ed_num, editions, a_data, finished, unfinished + ) + return finished, unfinished - a_data = { - 'img': 'images/achievments_icons/friend.svg', - 'name': 'Hexlet friend', - 'description': "Make any contribution to Hexlet projects", + def _create_achievement_data(self, num, type_key, type_name): + """Create achievement data dictionary.""" + return { + 'img': f'images/achievments_icons/{type_key}-{num}.svg', + 'name': f'{type_name} (equal to or more than {num})', + 'description': + f"Make {type_name.lower()} in amount of equal to or more than {num}", } - if finished: - finished.insert(0, a_data) + + def _update_achievement_status(self, num, cur_value, a_data, finished, unfinished): + """Update the achievement status.""" + if num > (0 if cur_value is None else cur_value): + unfinished.append(a_data) + a_data['acomplished'] = False else: - unfinished.insert(0, a_data) - context['contributors_with_any_contribution']['acomplished'] = False + finished.append(a_data) + return finished, unfinished - context['finished'] = finished - context['unfinished'] = unfinished - context['closed'] = len(finished) - context['all_achievements'] = len(finished) + len(unfinished) - return context + def _calculate_editions(self, contributions): + """Calculate total editions (additions + deletions).""" + return sum([ + 0 if edit is None else edit + for edit in [ + contributions['contributor_additions'], + contributions['contributor_deletions'], + ] + ]) + + def _calculate_total_actions(self, contributions): + """Calculate total actions""" + return sum([ + 0 if action is None else action + for action in [ + contributions['contributor_commits'], + contributions['contributor_pull_requests'], + contributions['contributor_issues'], + contributions['contributor_comments'], + contributions['contributor_additions'], + contributions['contributor_deletions'], + ] + ]) + + def _contributors_with_any_contribution(self, contributors): + """Get the contributors with any contributions.""" + return { + 'stat': contributors.filter(contribution_amount__gte=1).count(), + 'acomplished': True, + } diff --git a/templates/components/tables/achievements_list.html b/templates/components/tables/achievements_list.html index f7513f15..cd618929 100644 --- a/templates/components/tables/achievements_list.html +++ b/templates/components/tables/achievements_list.html @@ -32,7 +32,7 @@ - {% trans 'Pull requests (equal to or more than 1)' %} - {% trans 'Commits (equal to or more than 1)' %} - {% trans 'Issues (equal to or more than 1)' %} - {% trans 'Comments (equal to or more than 1)' %} - {% trans 'Additions and deletions (equal to or more than 1)' %} - {% trans 'Additions and deletions (equal to or more than 1000)' %} Date: Sun, 17 Nov 2024 21:04:56 +0300 Subject: [PATCH 19/19] delete sum brackets --- contributors/views/contributor_achievements.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/contributors/views/contributor_achievements.py b/contributors/views/contributor_achievements.py index 946687a7..593f5aa2 100644 --- a/contributors/views/contributor_achievements.py +++ b/contributors/views/contributor_achievements.py @@ -264,17 +264,16 @@ def _update_achievement_status(self, num, cur_value, a_data, finished, unfinishe def _calculate_editions(self, contributions): """Calculate total editions (additions + deletions).""" - return sum([ + return sum( 0 if edit is None else edit for edit in [ contributions['contributor_additions'], contributions['contributor_deletions'], - ] - ]) + ]) def _calculate_total_actions(self, contributions): """Calculate total actions""" - return sum([ + return sum( 0 if action is None else action for action in [ contributions['contributor_commits'], @@ -283,8 +282,7 @@ def _calculate_total_actions(self, contributions): contributions['contributor_comments'], contributions['contributor_additions'], contributions['contributor_deletions'], - ] - ]) + ]) def _contributors_with_any_contribution(self, contributors): """Get the contributors with any contributions."""