Allow reprocessing all attachments via django command

This commit is contained in:
Gabriel Augendre 2020-12-27 19:13:21 +01:00
parent 79a284fb85
commit 83db1f43cf
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4
2 changed files with 19 additions and 5 deletions

View file

@ -0,0 +1,14 @@
from django.core.management.base import BaseCommand
from attachments.models import Attachment
class Command(BaseCommand):
help = "Reprocess all attachments"
def handle(self, *args, **options):
for attachment in Attachment.objects.all():
self.stdout.write(f"Processing {attachment}...")
attachment.processed_file = None
attachment.save()
self.stdout.write(self.style.SUCCESS("Successfully processed all attachments."))

View file

@ -41,15 +41,15 @@ class Attachment(models.Model):
return f"{self.description} ({self.original_file.name})"
def save(self, *args, **kwargs):
if self.processed_file:
return super().save(*args, **kwargs)
super().save(*args, **kwargs)
if self.processed_file:
return
if self.id is None:
super().save(*args, **kwargs)
try:
Image.open(self.original_file.path)
except IOError:
return super().save(*args, **kwargs)
return
# Submit job to shortpixel
base_data = {