mirror of
https://github.com/FuzzyGrim/Yamtrack.git
synced 2026-03-03 00:27:02 +00:00
Merge pull request #1097 from busliggabor/feature/hide_zero_rating
Hide media score if rating is 0
This commit is contained in:
@@ -433,3 +433,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
|
||||
|
||||
@@ -356,3 +356,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
|
||||
|
||||
@@ -467,6 +467,8 @@ SIMKL_SECRET = config(
|
||||
),
|
||||
)
|
||||
|
||||
HIDE_ZERO_RATING = config("HIDE_ZERO_RATING", default=False, cast=bool)
|
||||
|
||||
TESTING = False
|
||||
|
||||
HEALTHCHECK_CELERY_PING_TIMEOUT = config(
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if media.score is not None %}
|
||||
{% if media.score|show_media_score %}
|
||||
<div class="absolute {% if from_grid %}sm:top-2 sm:right-2 sm:left-auto{% endif %} top-10 left-2 bg-gray-900/90 text-white text-xs px-2 py-1 rounded-md flex items-center shadow-md">
|
||||
{% include "app/icons/star.svg" with classes="w-4 h-4 text-yellow-400 mr-1 fill-current" %}
|
||||
<span class="text-sm text-white">{{ media.formatted_score }}</span>
|
||||
|
||||
@@ -379,7 +379,7 @@
|
||||
{% if media.end_date %}{{ media.end_date|datetime_format:user }}{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
{% if media.score is not None %}
|
||||
{% if media.score|show_media_score %}
|
||||
<div class="flex items-center text-sm text-yellow-400 mt-2">
|
||||
{% include "app/icons/star.svg" with classes="w-4 h-4 mr-1 fill-current" %}
|
||||
<span>{{ media.formatted_score }}</span>
|
||||
|
||||
Reference in New Issue
Block a user