bgneal@1
|
1 from django.core.management.base import BaseCommand, CommandError
|
bgneal@1
|
2 from photologue.management.commands import get_response, create_photosize
|
bgneal@1
|
3 from photologue.models import PhotoEffect
|
bgneal@1
|
4
|
bgneal@1
|
5 class Command(BaseCommand):
|
bgneal@1
|
6 help = ('Prompts the user to set up the default photo sizes required by Photologue.')
|
bgneal@1
|
7 requires_model_validation = True
|
bgneal@1
|
8 can_import_settings = True
|
bgneal@1
|
9
|
bgneal@1
|
10 def handle(self, *args, **kwargs):
|
bgneal@1
|
11 return init(*args, **kwargs)
|
bgneal@1
|
12
|
bgneal@1
|
13 def init(*args, **kwargs):
|
bgneal@1
|
14 msg = '\nPhotologue requires a specific photo size to display thumbnail previews in the Django admin application.\nWould you like to generate this size now? (yes, no):'
|
bgneal@1
|
15 if get_response(msg, lambda inp: inp == 'yes', False):
|
bgneal@1
|
16 admin_thumbnail = create_photosize('admin_thumbnail', width=100, height=75, crop=True, pre_cache=True)
|
bgneal@1
|
17 msg = 'Would you like to apply a sample enhancement effect to your admin thumbnails? (yes, no):'
|
bgneal@1
|
18 if get_response(msg, lambda inp: inp == 'yes', False):
|
bgneal@1
|
19 effect, created = PhotoEffect.objects.get_or_create(name='Enhance Thumbnail', description="Increases sharpness and contrast. Works well for smaller image sizes such as thumbnails.", contrast=1.2, sharpness=1.3)
|
bgneal@1
|
20 admin_thumbnail.effect = effect
|
bgneal@1
|
21 admin_thumbnail.save()
|
bgneal@1
|
22 msg = '\nPhotologue comes with a set of templates for setting up a complete photo gallery. These templates require you to define both a "thumbnail" and "display" size.\nWould you like to define them now? (yes, no):'
|
bgneal@1
|
23 if get_response(msg, lambda inp: inp == 'yes', False):
|
bgneal@1
|
24 thumbnail = create_photosize('thumbnail', width=100, height=75)
|
bgneal@1
|
25 display = create_photosize('display', width=400, increment_count=True)
|
bgneal@1
|
26 msg = 'Would you like to apply a sample reflection effect to your display images? (yes, no):'
|
bgneal@1
|
27 if get_response(msg, lambda inp: inp == 'yes', False):
|
bgneal@1
|
28 effect, created = PhotoEffect.objects.get_or_create(name='Display Reflection', description="Generates a reflection with a white background", reflection_size=0.4)
|
bgneal@1
|
29 display.effect = effect
|
bgneal@1
|
30 display.save() |