Tony Mack | 5df6c55 | 2013-04-11 21:24:17 -0400 | [diff] [blame] | 1 | from types import StringTypes |
Tony Mack | 09080c6 | 2013-05-06 16:57:54 -0400 | [diff] [blame] | 2 | from django.contrib.auth import authenticate |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 3 | from core.models import Image |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 4 | |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 5 | def _get_images(filter): |
Tony Mack | 5df6c55 | 2013-04-11 21:24:17 -0400 | [diff] [blame] | 6 | if isinstance(filter, StringTypes) and filter.isdigit(): |
| 7 | filter = int(filter) |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 8 | if isinstance(filter, int): |
Tony Mack | 771f4b9 | 2013-04-12 01:49:57 -0400 | [diff] [blame] | 9 | images = Image.objects.filter(id=filter) |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 10 | elif isinstance(filter, StringTypes): |
Tony Mack | 771f4b9 | 2013-04-12 01:49:57 -0400 | [diff] [blame] | 11 | images = Image.objects.filter(name=filter) |
Tony Mack | 5df6c55 | 2013-04-11 21:24:17 -0400 | [diff] [blame] | 12 | elif isinstance(filter, dict): |
Tony Mack | 771f4b9 | 2013-04-12 01:49:57 -0400 | [diff] [blame] | 13 | images = Image.objects.filter(**filter) |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 14 | else: |
| 15 | images = [] |
| 16 | return images |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 17 | |
| 18 | def add_image(auth, fields={}): |
| 19 | """not implemented""" |
| 20 | return |
| 21 | |
| 22 | def delete_image(auth, filter={}): |
| 23 | """not implemented""" |
| 24 | return 1 |
| 25 | |
| 26 | def get_images(auth, filter={}): |
Tony Mack | 09080c6 | 2013-05-06 16:57:54 -0400 | [diff] [blame] | 27 | user = authenticate(username=auth.get('username'), |
| 28 | password=auth.get('password')) |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 29 | images = _get_images(filter) |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 30 | return images |
| 31 | |
| 32 | |
| 33 | |