Thumbnails for images and videos #87

Merged
Anna Sirota merged 28 commits from thumbnails into main 2024-04-25 17:50:58 +02:00
2 changed files with 7 additions and 10 deletions
Showing only changes of commit 7f3ff2db61 - Show all commits

View File

@ -19,18 +19,12 @@ def scan_selected_files(self, request, queryset):
files.signals.schedule_scan(instance) files.signals.schedule_scan(instance)
def schedule_thumbnails(self, request, queryset): def make_thumbnails(self, request, queryset):
"""Schedule thumbnails generationg for selected files.""" """Schedule thumbnails generationg for selected files."""
for instance in queryset.filter(type__in=(File.TYPES.IMAGE, File.TYPES.VIDEO)): for instance in queryset.filter(type__in=(File.TYPES.IMAGE, File.TYPES.VIDEO)):
files.tasks.make_thumbnails(file_id=instance.pk) files.tasks.make_thumbnails(file_id=instance.pk)
def make_thumbnails(self, request, queryset):
"""Make thumbnails for selected files."""
for instance in queryset.filter(type__in=(File.TYPES.IMAGE, File.TYPES.VIDEO)):
files.tasks.make_thumbnails.task_function(file_id=instance.pk)
class FileValidationInlineAdmin(admin.StackedInline): class FileValidationInlineAdmin(admin.StackedInline):
model = FileValidation model = FileValidation
readonly_fields = ('date_created', 'date_modified', 'is_ok', 'results') readonly_fields = ('date_created', 'date_modified', 'is_ok', 'results')
@ -146,7 +140,7 @@ class FileAdmin(admin.ModelAdmin):
) )
inlines = [FileValidationInlineAdmin] inlines = [FileValidationInlineAdmin]
actions = [scan_selected_files, schedule_thumbnails, make_thumbnails] actions = [scan_selected_files, make_thumbnails]
def is_ok(self, obj): def is_ok(self, obj):
return obj.validation.is_ok if hasattr(obj, 'validation') else None return obj.validation.is_ok if hasattr(obj, 'validation') else None

View File

@ -51,9 +51,12 @@ def _schedule_thumbnails(
if not created: if not created:
return return
if not instance.is_ok:
return
file = instance.file file = instance.file
if instance.is_ok and (file.is_image or file.is_video):
# Generate thumbnails if initial scan found no issues # Generate thumbnails if initial scan found no issues
if file.is_image or file.is_video:
schedule_thumbnails(file) schedule_thumbnails(file)