Mercurial > public > madeira
comparison mysite/photologue/management/commands/__init__.py @ 1:0dcfcdf50c62
Initial import of Madeira project from the private repository.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 06 Apr 2009 03:10:59 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:df0370bfe3f0 | 1:0dcfcdf50c62 |
---|---|
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 |