Skip to content

Commit

Permalink
Avoid displaying ".0" decimals on question marks
Browse files Browse the repository at this point in the history
Fixes #699.
  • Loading branch information
zarino authored and lucascumsille committed Nov 5, 2024
1 parent f8e4c4f commit f32d0af
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
16 changes: 16 additions & 0 deletions caps/templatetags/caps_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ def percentage(value: float):
return f"{value * 100:.0f}%"


@register.filter
def format_mark(value):
"""
Display whole-number marks as a whole numbers, and
fractional marks as decimals, removing trailing zeroes.
"""
try:
value = float(value)
if value.is_integer():
return f"{int(value)}"
else:
return f"{value}"
except (ValueError, TypeError):
return value


@register.simple_tag(takes_context=True)
def council_card(context: dict, slug: str, title="", color: str = "red"):
"""
Expand Down
4 changes: 2 additions & 2 deletions scoring/templates/scoring/council.html
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,12 @@ <h3 class="exclamation text-white">Visit us again on a bigger screen</h3>
</td>

<td data-column="score" class="score border-bottom">
<span>{{ answer.score }}/{{ answer.max }}</span>
<span>{{ answer.score|format_mark }}/{{ answer.max }}</span>
</td>

{% for comparison in answer.comparisons %}
<td data-column="score" class="d-none d-md-table-cell score border-bottom">
<span>{{ comparison.score }}/{{ comparison.max }}</span>
<span>{{ comparison.score|format_mark }}/{{ comparison.max }}</span>
</td>
{% endfor %}

Expand Down
2 changes: 1 addition & 1 deletion scoring/templates/scoring/section.html
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ <h3 class="fs-5 mb-0 lh-base text-center">{{ council_type.name|title }}</h3>

{% for comparison in question.comparisons %}
<td data-column="score" class="text-start text-md-end d-none flex-row d-md-table-cell score">
<span class="me-2">{{ comparison.score }}/{{ question.details.max_score }}</span>
<span class="me-2">{{ comparison.score|format_mark }}/{{ question.details.max_score }}</span>
<span class="badge bg-secondary d-md-none">{{ comparison.council_name }}</span>
</td>
{% endfor %}
Expand Down

0 comments on commit f32d0af

Please sign in to comment.