From: Radek Czajka Date: Tue, 23 May 2023 12:22:35 +0000 (+0200) Subject: admin filters, fix X-Git-Url: https://git.mdrn.pl/audio.git/commitdiff_plain/778bdfb196e004691368624d3f5af04b4cdad640 admin filters, fix --- diff --git a/src/archive/admin.py b/src/archive/admin.py index 94c3aaf..f9249af 100644 --- a/src/archive/admin.py +++ b/src/archive/admin.py @@ -6,7 +6,12 @@ admin.site.register(Project) class AudiobookAdmin(admin.ModelAdmin): list_display = ["title", "slug", "index", "part_name", "duration", "license", "youtube_volume"] - list_filter = ["license"] + list_filter = [ + "license", + "project", + ("mp3_published", admin.EmptyFieldListFilter), + ("youtube_published", admin.EmptyFieldListFilter), + ] search_fields = ["title", "slug", "part_name", "youtube_volume"] list_editable = ["youtube_volume"] readonly_fields = ['duration'] diff --git a/src/youtube/utils.py b/src/youtube/utils.py index 3b64018..d219dde 100644 --- a/src/youtube/utils.py +++ b/src/youtube/utils.py @@ -1,3 +1,4 @@ +import hashlib import os import shutil import subprocess @@ -31,7 +32,16 @@ def process_to_file(cmdline, prefix='', suffix='', cache_key=None, output_path=N output_path = tmp.name if cache_key: - cache_path = FILE_CACHE + cache_key.replace('/', '__') + cache_path = cache_key.replace('/', '__') + if len(cache_path) > 255: + parts = cache_path.rsplit('.', 1) + limit = 255 - 9 + if len(parts) > 1: + limit -= len(parts[1]) + 1 + cache_path = parts[0][:limit] + '.' + hashlib.sha1(cache_key.encode('utf-8')).hexdigest()[:8] + if len(parts) > 1: + cache_path += '.' + parts[1] + cache_path = FILE_CACHE + cache_path if cache_key and os.path.exists(cache_path): link_or_copy(cache_path, output_path)