Handle limit/nested_limit zero
This returns zero comments now
This commit is contained in:
parent
54b156844b
commit
abc0eaaf1d
@ -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,9 +354,12 @@ class API(object):
|
|||||||
|
|
||||||
reply_counts = self.comments.reply_count(uri, after)
|
reply_counts = self.comments.reply_count(uri, after)
|
||||||
|
|
||||||
root_list = list(self.comments.fetch(**fetch_args))
|
if 'limit' in fetch_args and fetch_args['limit'] == 0:
|
||||||
if not root_list:
|
root_list = []
|
||||||
raise NotFound
|
else:
|
||||||
|
root_list = list(self.comments.fetch(**fetch_args))
|
||||||
|
if not root_list:
|
||||||
|
raise NotFound
|
||||||
if root_id not in reply_counts:
|
if root_id not in reply_counts:
|
||||||
reply_counts[root_id] = 0
|
reply_counts[root_id] = 0
|
||||||
|
|
||||||
@ -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 > 0:
|
if nested_limit is not None:
|
||||||
fetch_args['parent'] = comment['id']
|
if nested_limit > 0:
|
||||||
fetch_args['limit'] = nested_limit
|
fetch_args['parent'] = comment['id']
|
||||||
replies = list(self.comments.fetch(**fetch_args))
|
fetch_args['limit'] = nested_limit
|
||||||
|
replies = list(self.comments.fetch(**fetch_args))
|
||||||
|
else:
|
||||||
|
replies = []
|
||||||
else:
|
else:
|
||||||
replies = []
|
fetch_args['parent'] = comment['id']
|
||||||
|
replies = list(self.comments.fetch(**fetch_args))
|
||||||
else:
|
else:
|
||||||
comment['total_replies'] = 0
|
comment['total_replies'] = 0
|
||||||
replies = []
|
replies = []
|
||||||
|
Loading…
Reference in New Issue
Block a user