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 Node |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 4 | |
| 5 | def _get_nodes(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): |
| 9 | nodes = Node.objects.filter(id=filter) |
| 10 | elif isinstance(filter, StringTypes): |
| 11 | nodes = Node.objects.filter(name=filter) |
Tony Mack | 5df6c55 | 2013-04-11 21:24:17 -0400 | [diff] [blame] | 12 | elif isinstance(filter, dict): |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 13 | nodes = Node.objects.filter(**filter) |
| 14 | else: |
| 15 | nodes = [] |
| 16 | return nodes |
| 17 | |
| 18 | def add_node(auth, fields={}): |
| 19 | """not implemented""" |
| 20 | return |
| 21 | |
| 22 | def delete_node(auth, filter={}): |
| 23 | """not implemented""" |
| 24 | return 1 |
| 25 | |
| 26 | def update_node(auth, id, fields={}): |
| 27 | return |
| 28 | |
| 29 | def get_nodes(auth, filter={}): |
Tony Mack | 09080c6 | 2013-05-06 16:57:54 -0400 | [diff] [blame] | 30 | user = authenticate(username=auth.get('username'), |
| 31 | password=auth.get('password')) |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 32 | nodes = _get_nodes(filter) |
| 33 | return nodes |
| 34 | |
| 35 | |
| 36 | |