blob: 4f7ceeb741a3aedd495cf9cb2854a4f645773366 [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 Node
Tony Mack29c287f2013-04-11 21:07:16 -04004
5def _get_nodes(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):
9 nodes = Node.objects.filter(id=filter)
10 elif isinstance(filter, StringTypes):
11 nodes = Node.objects.filter(name=filter)
Tony Mack5df6c552013-04-11 21:24:17 -040012 elif isinstance(filter, dict):
Tony Mack29c287f2013-04-11 21:07:16 -040013 nodes = Node.objects.filter(**filter)
14 else:
15 nodes = []
16 return nodes
17
18def add_node(auth, fields={}):
19 """not implemented"""
20 return
21
22def delete_node(auth, filter={}):
23 """not implemented"""
24 return 1
25
26def update_node(auth, id, fields={}):
27 return
28
29def get_nodes(auth, filter={}):
Tony Mack09080c62013-05-06 16:57:54 -040030 user = authenticate(username=auth.get('username'),
31 password=auth.get('password'))
Tony Mack29c287f2013-04-11 21:07:16 -040032 nodes = _get_nodes(filter)
33 return nodes
34
35
36