mirror of
https://github.com/FuzzyGrim/Yamtrack.git
synced 2026-03-03 02:37:02 +00:00
Merge pull request #1017 from busliggabor/feature/hide_completed
Hide completed related media if HIDE_COMPLETED is set
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from urllib.parse import parse_qsl, urlencode, urlparse
|
||||
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.db.models import Q
|
||||
from django.http import HttpResponseRedirect
|
||||
@@ -8,8 +9,9 @@ from django.shortcuts import redirect
|
||||
from django.utils.encoding import iri_to_uri
|
||||
from django.utils.http import url_has_allowed_host_and_scheme
|
||||
|
||||
from app.models import BasicMedia, MediaTypes
|
||||
from app.models import BasicMedia, MediaTypes, Status
|
||||
|
||||
hide_completed = settings.HIDE_COMPLETED
|
||||
|
||||
def minutes_to_hhmm(total_minutes):
|
||||
"""Convert total minutes to HH:MM format."""
|
||||
@@ -66,7 +68,7 @@ def format_search_response(page, per_page, total_results, results):
|
||||
}
|
||||
|
||||
|
||||
def enrich_items_with_user_data(request, items):
|
||||
def enrich_items_with_user_data(request, items, section_name = None):
|
||||
"""Enrich a list of items with user tracking data."""
|
||||
if not items:
|
||||
return []
|
||||
@@ -118,9 +120,13 @@ def enrich_items_with_user_data(request, items):
|
||||
else:
|
||||
key = (str(item["media_id"]), item["source"])
|
||||
|
||||
media_item = media_lookup.get(key)
|
||||
if hide_completed and section_name == "recommendations" and media_item and media_item.status == Status.COMPLETED.value:
|
||||
continue
|
||||
|
||||
enriched_item = {
|
||||
"item": item,
|
||||
"media": media_lookup.get(key),
|
||||
"media": media_item,
|
||||
}
|
||||
enriched_items.append(enriched_item)
|
||||
|
||||
|
||||
@@ -211,6 +211,7 @@ def media_details(request, source, media_type, media_id, title): # noqa: ARG001
|
||||
helpers.enrich_items_with_user_data(
|
||||
request,
|
||||
related_items,
|
||||
section_name
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -343,6 +343,8 @@ IMG_NONE = "https://www.themoviedb.org/assets/2/v4/glyphicons/basic/glyphicons-b
|
||||
REQUEST_TIMEOUT = 120 # seconds
|
||||
PER_PAGE = 24
|
||||
|
||||
HIDE_COMPLETED = config("HIDE_COMPLETED", default=False, cast=bool)
|
||||
|
||||
TMDB_API = config(
|
||||
"TMDB_API",
|
||||
default=secret(
|
||||
|
||||
Reference in New Issue
Block a user