web/lib/photologue/management/commands/plinit.py
author ymh <ymh.work@gmail.com>
Thu, 21 Jan 2010 18:41:10 +0100
changeset 5 10b1f6d8a5d2
permissions -rw-r--r--
first debug version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
from django.core.management.base import BaseCommand, CommandError
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
from photologue.management.commands import get_response, create_photosize
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
from photologue.models import PhotoEffect
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
class Command(BaseCommand):
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
    help = ('Prompts the user to set up the default photo sizes required by Photologue.')
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
    requires_model_validation = True
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
    can_import_settings = True
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
    def handle(self, *args, **kwargs):
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
        return init(*args, **kwargs)
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
def init(*args, **kwargs):
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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):'
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    if get_response(msg, lambda inp: inp == 'yes', False):
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
        admin_thumbnail = create_photosize('admin_thumbnail', width=100, height=75, crop=True, pre_cache=True)
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
        msg = 'Would you like to apply a sample enhancement effect to your admin thumbnails? (yes, no):'
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
        if get_response(msg, lambda inp: inp == 'yes', False):
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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)
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
            admin_thumbnail.effect = effect
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
            admin_thumbnail.save()
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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):'
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    if get_response(msg, lambda inp: inp == 'yes', False):
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
        thumbnail = create_photosize('thumbnail', width=100, height=75)
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
        display = create_photosize('display', width=400, increment_count=True)
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
        msg = 'Would you like to apply a sample reflection effect to your display images? (yes, no):'
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
        if get_response(msg, lambda inp: inp == 'yes', False):
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
            effect, created = PhotoEffect.objects.get_or_create(name='Display Reflection', description="Generates a reflection with a white background", reflection_size=0.4)
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
            display.effect = effect
10b1f6d8a5d2 first debug version
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
            display.save()