Bundle trimed down alternative to photologue
This commit is contained in:
parent
2da3419b8d
commit
5368a51a76
40 changed files with 2652 additions and 70 deletions
43
photologue/management/commands/plcache.py
Normal file
43
photologue/management/commands/plcache.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# 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 = 'Manages Photologue cache file for the given sizes.'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('sizes',
|
||||
nargs='*',
|
||||
type=str,
|
||||
help='Name of the photosize.')
|
||||
parser.add_argument('--reset',
|
||||
action='store_true',
|
||||
default=False,
|
||||
dest='reset',
|
||||
help='Reset photo cache before generating.')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
reset = options['reset']
|
||||
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('Caching photos, this may take a while...')
|
||||
|
||||
for cls in ImageModel.__subclasses__():
|
||||
for photosize in photosizes:
|
||||
print('Cacheing %s size images' % photosize.name)
|
||||
for obj in cls.objects.all():
|
||||
if reset:
|
||||
obj.remove_size(photosize)
|
||||
obj.create_size(photosize)
|
||||
Loading…
Add table
Add a link
Reference in a new issue