From 5178c4e01f0c04cc033e008ea36ce4b22e93561a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Buslig=20G=C3=A1bor?= <191412336+busliggabor@users.noreply.github.com> Date: Mon, 12 Jan 2026 22:13:55 +0100 Subject: [PATCH] Hide media score if rating is 0 Enabled via HIDE_ZERO_RATING environment variable set to 'True' --- src/app/templatetags/app_tags.py | 25 ++++++++++++++++++++ src/app/tests/test_templatetags.py | 10 ++++++++ src/config/settings.py | 2 ++ src/templates/app/components/media_card.html | 2 +- src/templates/app/statistics.html | 2 +- 5 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/app/templatetags/app_tags.py b/src/app/templatetags/app_tags.py index bca743ca..d0c91391 100644 --- a/src/app/templatetags/app_tags.py +++ b/src/app/templatetags/app_tags.py @@ -388,3 +388,28 @@ def get_pagination_range(current_page, total_pages, window): result.append(total_pages) return result + +@register.filter +def show_media_score(rating): + """ + Return if we should show the rating of a media. + + Args: + rating: the rating value of the media + + Returns: + True if we should show the media score + """ + return show_media_score(rating, settings.HIDE_ZERO_RATING) + +def show_media_score(rating, hide_zero_rating): # noqa: F811 + """ + Return if we should show the rating of a media. + + Args: + rating: the rating value of the media + + Returns: + True if we should show the media score + """ + return rating is not None and (not hide_zero_rating or (hide_zero_rating and rating > 0)) # noqa: E501 diff --git a/src/app/tests/test_templatetags.py b/src/app/tests/test_templatetags.py index 19aca2c0..b653515f 100644 --- a/src/app/tests/test_templatetags.py +++ b/src/app/tests/test_templatetags.py @@ -360,3 +360,13 @@ class AppTagsTests(TestCase): self.assertTrue(len(inactive_result) > 0) except KeyError: self.fail(f"icon raised KeyError for {media_type}") + + def test_show_media_score(self): + """Test if we should show media rating or not.""" + self.assertTrue(app_tags.show_media_score(1, False)) # noqa: FBT003 + self.assertTrue(app_tags.show_media_score(0, False)) # noqa: FBT003 + self.assertFalse(app_tags.show_media_score(None, False)) # noqa: FBT003 + + self.assertTrue(app_tags.show_media_score(1, True)) # noqa: FBT003 + self.assertFalse(app_tags.show_media_score(0, True)) # noqa: FBT003 + self.assertFalse(app_tags.show_media_score(None, True)) # noqa: FBT003 diff --git a/src/config/settings.py b/src/config/settings.py index 19026208..5a77c051 100644 --- a/src/config/settings.py +++ b/src/config/settings.py @@ -452,6 +452,8 @@ SIMKL_SECRET = config( ), ) +HIDE_ZERO_RATING = config("HIDE_ZERO_RATING", default=False, cast=bool) + TESTING = False HEALTHCHECK_CELERY_PING_TIMEOUT = config( diff --git a/src/templates/app/components/media_card.html b/src/templates/app/components/media_card.html index b1693870..f228d6b0 100644 --- a/src/templates/app/components/media_card.html +++ b/src/templates/app/components/media_card.html @@ -46,7 +46,7 @@ {% endif %} - {% if media.score is not None %} + {% if media.score|show_media_score %}
{% include "app/icons/star.svg" with classes="w-4 h-4 text-yellow-400 mr-1 fill-current" %} {{ media.formatted_score }} diff --git a/src/templates/app/statistics.html b/src/templates/app/statistics.html index 5b355165..10caa716 100644 --- a/src/templates/app/statistics.html +++ b/src/templates/app/statistics.html @@ -379,7 +379,7 @@ {% if media.end_date %}{{ media.end_date|date_tracker_format }}{% endif %}

- {% if media.score is not None %} + {% if media.score|show_media_score %}
{% include "app/icons/star.svg" with classes="w-4 h-4 mr-1 fill-current" %} {{ media.formatted_score }}