Skip to content

Commit

Permalink
Merge pull request #304 from danokp/add_achievements_page_265
Browse files Browse the repository at this point in the history
Add achievement list page
  • Loading branch information
fey committed Sep 14, 2023
2 parents 19bf5d6 + 130c9cd commit 604f980
Show file tree
Hide file tree
Showing 11 changed files with 663 additions and 177 deletions.
1 change: 1 addition & 0 deletions config/settings.py
Expand Up @@ -56,6 +56,7 @@
'crispy_forms',
"crispy_bootstrap5",
'django_extensions',
'mathfilters',
'django_filters',
]

Expand Down
10 changes: 10 additions & 0 deletions contributors/models/contributor.py
Expand Up @@ -40,6 +40,16 @@ def with_contributions(self):
comments=models.Count(
'contribution', filter=models.Q(contribution__type='cnt'),
),
editions=(models.F('additions') + models.F('deletions')),
contribution_amount=sum(
(
models.F('commits'),
models.F('editions'),
models.F('pull_requests'),
models.F('issues'),
models.F('comments'),
),
),
)

def for_month(self):
Expand Down
5 changes: 5 additions & 0 deletions contributors/urls.py
Expand Up @@ -81,4 +81,9 @@
),
path('event-handler', views.webhook.EventHandler.as_view()),
path('about', views.about.AboutView.as_view(), name="about"),
path(
'achievements',
views.achievements.AchievementListView.as_view(),
name='achievements',
),
]
1 change: 1 addition & 0 deletions contributors/views/__init__.py
@@ -1,5 +1,6 @@
from contributors.views import ( # noqa: WPS235
about,
achievements,
config,
contributor,
contributor_issues,
Expand Down
60 changes: 60 additions & 0 deletions contributors/views/achievements.py
@@ -0,0 +1,60 @@
from django.views import generic

from contributors.models import Contributor


class AchievementListView(generic.ListView):
"""Achievement list."""

template_name = '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()

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'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'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'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'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'contributors_editions_gte_{ed_num}'] = (
contributors.filter(editions__gte=ed_num).count()
)

return context
358 changes: 182 additions & 176 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Expand Up @@ -24,6 +24,7 @@ crispy-bootstrap5 = "^0.6"
django-extensions = "^3.2.1"
black = "^23.3.0"
django-debug-toolbar = "^3.8.1"
django-mathfilters = "^1.0.0"
django-filter = "^23.2"
sentry-sdk = "^1.29.2"

Expand Down
9 changes: 9 additions & 0 deletions templates/achievements_list.html
@@ -0,0 +1,9 @@
{% extends 'base.html' %}
{% load i18n static %}

{% block content %}
<h1>Achievements</h1>

{% include 'components/tables/achievements_list.html' %}

{% endblock %}
11 changes: 11 additions & 0 deletions templates/components/tables/achievement_percentage_field.html
@@ -0,0 +1,11 @@
{% load i18n static mathfilters %}

<div class="progress d-flex justify-content-between" style="height: max-content;">
<div class="bg-info text-dark text-start aligns-items-center" role="progressbar" style="width: {{ achievement_made_count|div:contributors_amount|mul:100|floatformat:0 }}%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
<dl class="p-2 fs-6 mb-0" style="width:50vw;">
<dt>{% trans achievement_name %}</dt>
<dd class="mb-0">{% trans achievement_description %}</dd>
</dl>
</div>
<div class="p-2 fs-6 d-flex justify-content-center align-items-center">{{ achievement_made_count|div:contributors_amount|mul:100|floatformat:1 }}%</div>
</div>

0 comments on commit 604f980

Please sign in to comment.