Skip to content

Commit

Permalink
Add helper function to calc achivements percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrKosmylev committed Jun 30, 2024
1 parent 3b4a8fa commit 883c439
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
10 changes: 10 additions & 0 deletions contributors/templatetags/contrib_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions templates/components/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<li><p class="h6">{% trans "Other projects" %}</p></li>
</div>
<div class="col">
<li> </li>
<li></li>
</div>
<div class="col">
<li><p class="h6">{% trans "Useful resources" %}</p></li>
Expand Down Expand Up @@ -44,7 +44,7 @@
<li><a target="_blank" href="http://ru.hexlet.io/blog">{% trans "Blog" %}</a></li>
</div>
<div class="col">
<li> </li>
<li></li>
</div>
</div>
</ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
{% load i18n static mathfilters %}
{% load i18n static contrib_extras %}

<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: {{ contribution|div:achievement_made_count|mul:100|floatformat:0 }}%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
<div class="bg-info text-dark text-start aligns-items-center" role="progressbar" style="width: {% calc_percent_achievement contribution achievement_made_count %}%;" 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">
{% 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 %}%
</div>
</div>

0 comments on commit 883c439

Please sign in to comment.