fix addList/removeList/unknown list

This commit is contained in:
rolux 2011-01-13 15:32:14 +00:00
parent 18ce6852c4
commit a3b65cb046
2 changed files with 26 additions and 27 deletions

View file

@ -82,7 +82,9 @@ def parseCondition(condition):
q = Q(**{k: v})
return q
elif key_type == 'list':
q = Q(itemId=False)
l = v.split(".")
if len(l) == 2:
lqs = List.objects.filter(name=l[1], user__username=l[0])
if lqs.count() == 1:
if lqs[0].query.get('static', False) == False:
@ -91,8 +93,6 @@ def parseCondition(condition):
data.get('operator', '&'))
else:
q = Q(id__in=lqs[0].items.all())
else:
q = Q(itemId=False)
return q
else: #number or date

View file

@ -178,17 +178,19 @@ def addList(request):
}
'''
data = json.loads(request.POST['data'])
if models.List.objects.filter(name=data['name'], user=request.user).count() == 0:
list = models.List(name = data['name'], user=request.user)
name = data['name']
num = 1
while models.List.objects.filter(name=name, user=request.user).count()>0:
num += 1
name = data['name'] + ' (%d)' % num
list = models.List(name = name, user=request.user)
list.save()
pos, created = models.Position.objects.get_or_create(list=list, user=request.user, section='my')
pos, created = models.Position.objects.get_or_create(list=list,
user=request.user, section='my')
pos.position = data['position']
pos.save()
response = json_response(status=200, text='created')
response['data']['list'] = list.json()
else:
response = json_response(status=200, text='list already exists')
response['data']['errors'] = {'name': 'List already exists'}
response['data'] = list.json()
return render_to_json_response(response)
actions.register(addList, cache=False)
@ -263,8 +265,7 @@ actions.register(editList, cache=False)
def removeList(request):
'''
param data {
name: value,
user: username(only admins)
id: listId,
}
return {
status: {'code': int, 'text': string},
@ -273,10 +274,8 @@ def removeList(request):
}
'''
data = json.loads(request.POST['data'])
user = request.user.username
if user.is_staff and 'user' in data:
user = data.get('user')
list = get_object_or_404_json(models.List, name=data['name'], user__username=user)
list = get_list_or_404_json(data['id'])
response = json_response()
if list.editable(request.user):
list.delete()
else: