Handle limit/nested_limit zero

This returns zero comments now
This commit is contained in:
Srijan Choudhary 2014-05-03 01:14:23 +05:30
parent 54b156844b
commit abc0eaaf1d

View File

@ -331,6 +331,7 @@ class API(object):
fetch_args['limit'] = int(request.args.get('limit')) fetch_args['limit'] = int(request.args.get('limit'))
except ValueError: except ValueError:
return BadRequest("limit should be integer") return BadRequest("limit should be integer")
if request.args.get('parent'): if request.args.get('parent'):
parent_arg = request.args.get('parent') parent_arg = request.args.get('parent')
if parent_arg == 'NULL': if parent_arg == 'NULL':
@ -353,6 +354,9 @@ class API(object):
reply_counts = self.comments.reply_count(uri, after) reply_counts = self.comments.reply_count(uri, after)
if 'limit' in fetch_args and fetch_args['limit'] == 0:
root_list = []
else:
root_list = list(self.comments.fetch(**fetch_args)) root_list = list(self.comments.fetch(**fetch_args))
if not root_list: if not root_list:
raise NotFound raise NotFound
@ -365,7 +369,7 @@ class API(object):
except ValueError: except ValueError:
return BadRequest("nested_limit should be integer") return BadRequest("nested_limit should be integer")
else: else:
nested_limit = 0 nested_limit = None
rv = { rv = {
'id' : root_id, 'id' : root_id,
@ -378,12 +382,16 @@ class API(object):
for comment in rv['replies']: for comment in rv['replies']:
if comment['id'] in reply_counts: if comment['id'] in reply_counts:
comment['total_replies'] = reply_counts[comment['id']] comment['total_replies'] = reply_counts[comment['id']]
if nested_limit is not None:
if nested_limit > 0: if nested_limit > 0:
fetch_args['parent'] = comment['id'] fetch_args['parent'] = comment['id']
fetch_args['limit'] = nested_limit fetch_args['limit'] = nested_limit
replies = list(self.comments.fetch(**fetch_args)) replies = list(self.comments.fetch(**fetch_args))
else: else:
replies = [] replies = []
else:
fetch_args['parent'] = comment['id']
replies = list(self.comments.fetch(**fetch_args))
else: else:
comment['total_replies'] = 0 comment['total_replies'] = 0
replies = [] replies = []