Skip to content

Commit

Permalink
xmlrpc: Treat negative max_count as meaning "return last N results"
Browse files Browse the repository at this point in the history
This is most useful when listing patches, as it lets you get the most
recent results instead of the oldest.

v2: Don't negative indexing on querysets, Django doesn't support that
    and was throwing an exception "Negative indexing is not supported."
    (Damien)

Signed-off-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
  • Loading branch information
nwnk authored and Damien Lespiau committed Dec 5, 2015
1 parent 516ee49 commit 3dd8ddc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion patchwork/bin/pwclient
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,12 @@ def main():
filter_parser.add_argument(
'-n', metavar='MAX#',
type=int,
help='''Restrict number of results'''
help='''Return first N results'''
)
filter_parser.add_argument(
'-N', metavar='MAX#',
type=int,
help='''Return last N results'''
)
filter_parser.add_argument(
'-m', metavar='MESSAGEID',
Expand Down Expand Up @@ -525,6 +530,12 @@ def main():
except:
action_parser.error("Invalid maximum count '%s'" % args.get('n'))

if args.get('N') != None:
try:
filt.add("max_count", 0 - args.get('N'))
except:
action_parser.error("Invalid maximum count '%s'" % args.get('N'))

do_signoff = args.get('signoff')

# grab settings from config files
Expand Down
10 changes: 10 additions & 0 deletions patchwork/views/xmlrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ def project_list(search_str=None, max_count=0):

if max_count > 0:
return map(project_to_dict, projects)[:max_count]
elif max_count < 0:
return map(project_to_dict, projects)[max_count:]
else:
return map(project_to_dict, projects)
except Project.DoesNotExist:
Expand Down Expand Up @@ -423,6 +425,8 @@ def person_list(search_str=None, max_count=0):

if max_count > 0:
return map(person_to_dict, people)[:max_count]
elif max_count < 0:
return map(person_to_dict, people)[max_count:]
else:
return map(person_to_dict, people)
except Person.DoesNotExist:
Expand Down Expand Up @@ -566,6 +570,10 @@ def patch_list(filt=None):

if max_count > 0:
return map(patch_to_dict, patches[:max_count])
elif max_count < 0:
results = map(patch_to_dict, patches.reverse()[:-max_count])
results.reverse()
return results
else:
return map(patch_to_dict, patches)
except Patch.DoesNotExist:
Expand Down Expand Up @@ -759,6 +767,8 @@ def state_list(search_str=None, max_count=0):

if max_count > 0:
return map(state_to_dict, states)[:max_count]
elif max_count < 0:
return map(state_to_dict, states)[max_count:]
else:
return map(state_to_dict, states)
except State.DoesNotExist:
Expand Down

0 comments on commit 3dd8ddc

Please sign in to comment.