comparison photologue/management/commands/__init__.py @ 71:e2868ad47a1e

For Django 1.4, using the new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 14 Apr 2012 16:40:29 -0500
parents madeira/photologue/management/commands/__init__.py@63e4211628e1
children
comparison
equal deleted inserted replaced
70:f26cdda0ad8b 71:e2868ad47a1e
1 from photologue.models import PhotoSize
2
3 def get_response(msg, func=int, default=None):
4 while True:
5 resp = raw_input(msg)
6 if not resp and default is not None:
7 return default
8 try:
9 return func(resp)
10 except:
11 print 'Invalid input.'
12
13 def create_photosize(name, width=0, height=0, crop=False, pre_cache=False, increment_count=False):
14 try:
15 size = PhotoSize.objects.get(name=name)
16 exists = True
17 except PhotoSize.DoesNotExist:
18 size = PhotoSize(name=name)
19 exists = False
20 if exists:
21 msg = 'A "%s" photo size already exists. Do you want to replace it? (yes, no):' % name
22 if not get_response(msg, lambda inp: inp == 'yes', False):
23 return
24 print '\nWe will now define the "%s" photo size:\n' % size
25 w = get_response('Width (in pixels):', lambda inp: int(inp), width)
26 h = get_response('Height (in pixels):', lambda inp: int(inp), height)
27 c = get_response('Crop to fit? (yes, no):', lambda inp: inp == 'yes', crop)
28 p = get_response('Pre-cache? (yes, no):', lambda inp: inp == 'yes', pre_cache)
29 i = get_response('Increment count? (yes, no):', lambda inp: inp == 'yes', increment_count)
30 size.width = w
31 size.height = h
32 size.crop = c
33 size.pre_cache = p
34 size.increment_count = i
35 size.save()
36 print '\nA "%s" photo size has been created.\n' % name
37 return size