Bundle trimed down alternative to photologue
This commit is contained in:
parent
2da3419b8d
commit
5368a51a76
40 changed files with 2652 additions and 70 deletions
34
photologue/management/commands/plflush.py
Normal file
34
photologue/management/commands/plflush.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Based on https://github.com/richardbarran/django-photologue/
|
||||
# by Richard Barran, BSD-3 licensed
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from photologue.models import ImageModel, PhotoSize
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Clears the Photologue cache for the given sizes.'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('sizes',
|
||||
nargs='*',
|
||||
type=str,
|
||||
help='Name of the photosize.')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
sizes = options['sizes']
|
||||
|
||||
if not sizes:
|
||||
photosizes = PhotoSize.objects.all()
|
||||
else:
|
||||
photosizes = PhotoSize.objects.filter(name__in=sizes)
|
||||
|
||||
if not len(photosizes):
|
||||
raise CommandError('No photo sizes were found.')
|
||||
|
||||
print('Flushing cache...')
|
||||
|
||||
for cls in ImageModel.__subclasses__():
|
||||
for photosize in photosizes:
|
||||
print('Flushing %s size images' % photosize.name)
|
||||
for obj in cls.objects.all():
|
||||
obj.remove_size(photosize)
|
||||
Loading…
Add table
Add a link
Reference in a new issue