admin filters, fix
authorRadek Czajka <rczajka@rczajka.pl>
Tue, 23 May 2023 12:22:35 +0000 (14:22 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Tue, 23 May 2023 12:22:35 +0000 (14:22 +0200)
src/archive/admin.py
src/youtube/utils.py

index 94c3aaf..f9249af 100644 (file)
@@ -6,7 +6,12 @@ admin.site.register(Project)
 
 class AudiobookAdmin(admin.ModelAdmin):
     list_display = ["title", "slug", "index", "part_name", "duration", "license", "youtube_volume"]
 
 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']
     search_fields = ["title", "slug", "part_name", "youtube_volume"]
     list_editable = ["youtube_volume"]
     readonly_fields = ['duration']
index 3b64018..d219dde 100644 (file)
@@ -1,3 +1,4 @@
+import hashlib
 import os
 import shutil
 import subprocess
 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:
         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)
 
     if cache_key and os.path.exists(cache_path):
         link_or_copy(cache_path, output_path)