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

View file

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