blob: 933216f71c24142244e7445de33ad74fef0e1fa9 [file] [log] [blame]
Tony Mack5df6c552013-04-11 21:24:17 -04001from types import StringTypes
Tony Mack09080c62013-05-06 16:57:54 -04002from django.contrib.auth import authenticate
Siobhan Tully30fd4292013-05-10 08:59:56 -04003from core.models import Image
Tony Mack53310082013-04-09 09:26:12 -04004
Tony Mack29c287f2013-04-11 21:07:16 -04005def _get_images(filter):
Tony Mack5df6c552013-04-11 21:24:17 -04006 if isinstance(filter, StringTypes) and filter.isdigit():
7 filter = int(filter)
Tony Mack29c287f2013-04-11 21:07:16 -04008 if isinstance(filter, int):
Tony Mack771f4b92013-04-12 01:49:57 -04009 images = Image.objects.filter(id=filter)
Tony Mack29c287f2013-04-11 21:07:16 -040010 elif isinstance(filter, StringTypes):
Tony Mack771f4b92013-04-12 01:49:57 -040011 images = Image.objects.filter(name=filter)
Tony Mack5df6c552013-04-11 21:24:17 -040012 elif isinstance(filter, dict):
Tony Mack771f4b92013-04-12 01:49:57 -040013 images = Image.objects.filter(**filter)
Tony Mack29c287f2013-04-11 21:07:16 -040014 else:
15 images = []
16 return images
Tony Mack53310082013-04-09 09:26:12 -040017
18def add_image(auth, fields={}):
19 """not implemented"""
20 return
21
22def delete_image(auth, filter={}):
23 """not implemented"""
24 return 1
25
26def get_images(auth, filter={}):
Tony Mack09080c62013-05-06 16:57:54 -040027 user = authenticate(username=auth.get('username'),
28 password=auth.get('password'))
Tony Mack29c287f2013-04-11 21:07:16 -040029 images = _get_images(filter)
Tony Mack53310082013-04-09 09:26:12 -040030 return images
31
32
33