mirror of
https://github.com/FuzzyGrim/Yamtrack.git
synced 2026-03-03 02:27:01 +00:00
convert hide zero rating from env var to user preference
This commit is contained in:
@@ -434,27 +434,17 @@ def get_pagination_range(current_page, total_pages, window):
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@register.filter
|
||||
def show_media_score(rating):
|
||||
def show_media_score(rating, user):
|
||||
"""
|
||||
Return if we should show the rating of a media.
|
||||
|
||||
Args:
|
||||
rating: the rating value of the media
|
||||
user: the user to check preferences for
|
||||
|
||||
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
|
||||
return rating is not None and (not user.hide_zero_rating or rating > 0)
|
||||
|
||||
@@ -359,10 +359,19 @@ class AppTagsTests(TestCase):
|
||||
|
||||
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
|
||||
# Create mock users
|
||||
mock_user_show = MagicMock()
|
||||
mock_user_show.hide_zero_rating = False
|
||||
|
||||
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
|
||||
mock_user_hide = MagicMock()
|
||||
mock_user_hide.hide_zero_rating = True
|
||||
|
||||
# With hide_zero_rating=False, show all non-None scores
|
||||
self.assertTrue(app_tags.show_media_score(1, mock_user_show))
|
||||
self.assertTrue(app_tags.show_media_score(0, mock_user_show))
|
||||
self.assertFalse(app_tags.show_media_score(None, mock_user_show))
|
||||
|
||||
# With hide_zero_rating=True, hide zero scores
|
||||
self.assertTrue(app_tags.show_media_score(1, mock_user_hide))
|
||||
self.assertFalse(app_tags.show_media_score(0, mock_user_hide))
|
||||
self.assertFalse(app_tags.show_media_score(None, mock_user_hide))
|
||||
|
||||
@@ -467,7 +467,6 @@ SIMKL_SECRET = config(
|
||||
),
|
||||
)
|
||||
|
||||
HIDE_ZERO_RATING = config("HIDE_ZERO_RATING", default=False, cast=bool)
|
||||
|
||||
TESTING = False
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if media.score|show_media_score %}
|
||||
{% if media.score|show_media_score:user %}
|
||||
<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|show_media_score %}
|
||||
{% if media.score|show_media_score:user %}
|
||||
<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>
|
||||
|
||||
@@ -108,6 +108,27 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Hide Zero Ratings #}
|
||||
<div class="mb-5">
|
||||
<div class="flex items-center justify-between p-3 bg-[#39404b] rounded-md">
|
||||
<div class="flex-1">
|
||||
<div class="flex items-center text-gray-200 mb-1">
|
||||
{% include "app/icons/star.svg" with classes="w-5 h-5 mr-2" %}
|
||||
<span class="text-sm font-medium">Hide zero ratings</span>
|
||||
</div>
|
||||
<p class="text-xs text-gray-400 ml-7">Hide the rating badge from media cards when the rating is zero.</p>
|
||||
</div>
|
||||
<label class="relative inline-flex items-center cursor-pointer ml-4">
|
||||
<input class="sr-only peer"
|
||||
type="checkbox"
|
||||
name="hide_zero_rating"
|
||||
{% if user.hide_zero_rating %}checked{% endif %}>
|
||||
<div class="w-9 h-5 bg-gray-600 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-px after:left-0.5 after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4.5 after:w-4.5 after:transition-all peer-checked:bg-indigo-600">
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Date Format #}
|
||||
<div class="mb-5">
|
||||
<div class="flex items-center justify-between p-3 bg-[#39404b] rounded-md">
|
||||
|
||||
18
src/users/migrations/0049_add_hide_zero_rating.py
Normal file
18
src/users/migrations/0049_add_hide_zero_rating.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django on 2026-02-08
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0048_add_hide_completed_recommendations'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='hide_zero_rating',
|
||||
field=models.BooleanField(default=False, help_text='Hide zero ratings from media cards'),
|
||||
),
|
||||
]
|
||||
@@ -324,6 +324,12 @@ class User(AbstractUser):
|
||||
help_text="Hide completed media in recommendations",
|
||||
)
|
||||
|
||||
# Hide zero ratings
|
||||
hide_zero_rating = models.BooleanField(
|
||||
default=False,
|
||||
help_text="Hide zero ratings from media cards",
|
||||
)
|
||||
|
||||
# Calendar preferences
|
||||
calendar_layout = models.CharField(
|
||||
max_length=20,
|
||||
|
||||
@@ -241,6 +241,7 @@ def preferences(request):
|
||||
request.user.hide_completed_recommendations = (
|
||||
"hide_completed_recommendations" in request.POST
|
||||
)
|
||||
request.user.hide_zero_rating = "hide_zero_rating" in request.POST
|
||||
request.user.date_format = request.POST.get(
|
||||
"date_format",
|
||||
DateFormatChoices.ISO,
|
||||
|
||||
Reference in New Issue
Block a user