filter keys
This commit is contained in:
parent
bebbeade8d
commit
f7e0893d20
2 changed files with 20 additions and 12 deletions
|
@ -63,15 +63,16 @@ class List(models.Model):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def json(self, user=None):
|
def json(self, keys, user=None):
|
||||||
return {
|
response = {}
|
||||||
'user': self.user.username,
|
for key in keys:
|
||||||
'name': self.name,
|
if key == 'items':
|
||||||
'public': self.public,
|
response[key] = self.get_number_of_items(user)
|
||||||
'featured': self.featured,
|
elif key == 'user':
|
||||||
'query': self.query,
|
response[key] = self.user.username
|
||||||
'items': self.get_number_of_items(user)
|
else:
|
||||||
}
|
response[key] = getattr(self, key)
|
||||||
|
return response
|
||||||
|
|
||||||
class ListItem(models.Model):
|
class ListItem(models.Model):
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
|
@ -49,11 +49,15 @@ def findList(request):
|
||||||
},
|
},
|
||||||
sort: [{key: 'name', operator: '+'}],
|
sort: [{key: 'name', operator: '+'}],
|
||||||
range: [0, 100]
|
range: [0, 100]
|
||||||
|
keys: []
|
||||||
}
|
}
|
||||||
|
|
||||||
possible query keys:
|
possible query keys:
|
||||||
name, user, featured, subscribed
|
name, user, featured, subscribed
|
||||||
|
|
||||||
|
possible keys:
|
||||||
|
name, user, featured, subscribed, query
|
||||||
|
|
||||||
}
|
}
|
||||||
return {status: {code: int, text: string},
|
return {status: {code: int, text: string},
|
||||||
data: {
|
data: {
|
||||||
|
@ -69,10 +73,13 @@ def findList(request):
|
||||||
#order
|
#order
|
||||||
qs = _order_query(query['qs'], query['sort'])
|
qs = _order_query(query['qs'], query['sort'])
|
||||||
#range
|
#range
|
||||||
qs = qs[query['range'][0]:query['range'][1]]
|
|
||||||
|
|
||||||
response = json_response()
|
response = json_response()
|
||||||
response['data']['lists'] = [l.json(request.user) for l in qs]
|
if 'keys' in data:
|
||||||
|
qs = qs[query['range'][0]:query['range'][1]]
|
||||||
|
|
||||||
|
response['data']['items'] = [l.json(data['keys'], request.user) for l in qs]
|
||||||
|
else:
|
||||||
|
response['data']['items'] = qs.count()
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(findList)
|
actions.register(findList)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue