forked from 0x2620/pandora
fix addList/removeList/unknown list
This commit is contained in:
parent
18ce6852c4
commit
a3b65cb046
2 changed files with 26 additions and 27 deletions
|
@ -82,17 +82,17 @@ 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(".")
|
||||||
lqs = List.objects.filter(name=l[1], user__username=l[0])
|
if len(l) == 2:
|
||||||
if lqs.count() == 1:
|
lqs = List.objects.filter(name=l[1], user__username=l[0])
|
||||||
if lqs[0].query.get('static', False) == False:
|
if lqs.count() == 1:
|
||||||
data = lqs[0].query
|
if lqs[0].query.get('static', False) == False:
|
||||||
q = parseConditions(data['conditions'],
|
data = lqs[0].query
|
||||||
data.get('operator', '&'))
|
q = parseConditions(data['conditions'],
|
||||||
else:
|
data.get('operator', '&'))
|
||||||
q = Q(id__in=lqs[0].items.all())
|
else:
|
||||||
else:
|
q = Q(id__in=lqs[0].items.all())
|
||||||
q = Q(itemId=False)
|
|
||||||
return q
|
return q
|
||||||
else: #number or date
|
else: #number or date
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
list.save()
|
while models.List.objects.filter(name=name, user=request.user).count()>0:
|
||||||
pos, created = models.Position.objects.get_or_create(list=list, user=request.user, section='my')
|
num += 1
|
||||||
pos.position = data['position']
|
name = data['name'] + ' (%d)' % num
|
||||||
pos.save()
|
list = models.List(name = name, user=request.user)
|
||||||
response = json_response(status=200, text='created')
|
list.save()
|
||||||
response['data']['list'] = list.json()
|
pos, created = models.Position.objects.get_or_create(list=list,
|
||||||
else:
|
user=request.user, section='my')
|
||||||
response = json_response(status=200, text='list already exists')
|
pos.position = data['position']
|
||||||
response['data']['errors'] = {'name': 'List already exists'}
|
pos.save()
|
||||||
|
response = json_response(status=200, text='created')
|
||||||
|
response['data'] = list.json()
|
||||||
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:
|
||||||
|
|
Loading…
Reference in a new issue