annotate photologue/management/commands/__init__.py @ 190:55c4d2c0ee27

Center of the Surf Cover. Update copyright date.
author Brian Neal <bgneal@gmail.com>
date Wed, 04 Apr 2018 19:30:41 -0500
parents e2868ad47a1e
children
rev   line source
bgneal@1 1 from photologue.models import PhotoSize
bgneal@1 2
bgneal@1 3 def get_response(msg, func=int, default=None):
bgneal@1 4 while True:
bgneal@1 5 resp = raw_input(msg)
bgneal@1 6 if not resp and default is not None:
bgneal@1 7 return default
bgneal@1 8 try:
bgneal@1 9 return func(resp)
bgneal@1 10 except:
bgneal@1 11 print 'Invalid input.'
bgneal@1 12
bgneal@1 13 def create_photosize(name, width=0, height=0, crop=False, pre_cache=False, increment_count=False):
bgneal@1 14 try:
bgneal@1 15 size = PhotoSize.objects.get(name=name)
bgneal@1 16 exists = True
bgneal@1 17 except PhotoSize.DoesNotExist:
bgneal@1 18 size = PhotoSize(name=name)
bgneal@1 19 exists = False
bgneal@1 20 if exists:
bgneal@1 21 msg = 'A "%s" photo size already exists. Do you want to replace it? (yes, no):' % name
bgneal@1 22 if not get_response(msg, lambda inp: inp == 'yes', False):
bgneal@1 23 return
bgneal@1 24 print '\nWe will now define the "%s" photo size:\n' % size
bgneal@1 25 w = get_response('Width (in pixels):', lambda inp: int(inp), width)
bgneal@1 26 h = get_response('Height (in pixels):', lambda inp: int(inp), height)
bgneal@1 27 c = get_response('Crop to fit? (yes, no):', lambda inp: inp == 'yes', crop)
bgneal@1 28 p = get_response('Pre-cache? (yes, no):', lambda inp: inp == 'yes', pre_cache)
bgneal@1 29 i = get_response('Increment count? (yes, no):', lambda inp: inp == 'yes', increment_count)
bgneal@1 30 size.width = w
bgneal@1 31 size.height = h
bgneal@1 32 size.crop = c
bgneal@1 33 size.pre_cache = p
bgneal@1 34 size.increment_count = i
bgneal@1 35 size.save()
bgneal@1 36 print '\nA "%s" photo size has been created.\n' % name
bgneal@1 37 return size