Allow reprocessing all attachments via django command
This commit is contained in:
parent
79a284fb85
commit
83db1f43cf
2 changed files with 19 additions and 5 deletions
14
attachments/management/commands/reprocess_all_attachments.py
Normal file
14
attachments/management/commands/reprocess_all_attachments.py
Normal 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."))
|
|
@ -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)
|
||||
|
||||
if self.id is None:
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
if self.processed_file:
|
||||
return
|
||||
|
||||
try:
|
||||
Image.open(self.original_file.path)
|
||||
except IOError:
|
||||
return super().save(*args, **kwargs)
|
||||
return
|
||||
|
||||
# Submit job to shortpixel
|
||||
base_data = {
|
||||
|
|
Reference in a new issue