[PATCH] xmlrpc: Don't use 'reverse'

Daniel Axtens dja at axtens.net
Fri Sep 2 09:36:40 AEST 2016


Stephen Finucane <stephenfinucane at hotmail.com> writes:

> queryset.reverse() is either broken or being used incorrectly in
> Django 1.6 and Django 1.7. Replace it with an alternative approach.
>
> Signed-off-by: Stephen Finucane <stephenfinucane at hotmail.com>
> Closes-bug: #35

Thanks!

Tested-by: Daniel Axtens <dja at axtens.net>

Regards,
Daniel

> ---
>  patchwork/views/xmlrpc.py | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/patchwork/views/xmlrpc.py b/patchwork/views/xmlrpc.py
> index 8f759aa..81df266 100644
> --- a/patchwork/views/xmlrpc.py
> +++ b/patchwork/views/xmlrpc.py
> @@ -406,8 +406,8 @@ def project_list(search_str=None, max_count=0):
>          if max_count > 0:
>              return list(map(project_to_dict, projects[:max_count]))
>          elif max_count < 0:
> -            query = projects.reverse()[:-max_count]
> -            return list(map(project_to_dict, reversed(query)))
> +            min_count = projects.count() + max_count
> +            return list(map(project_to_dict, projects[min_count:]))
>          else:
>              return list(map(project_to_dict, projects))
>      except Project.DoesNotExist:
> @@ -461,8 +461,8 @@ def person_list(search_str=None, max_count=0):
>          if max_count > 0:
>              return list(map(person_to_dict, people[:max_count]))
>          elif max_count < 0:
> -            query = people.reverse()[:-max_count]
> -            return list(map(person_to_dict, reversed(query)))
> +            min_count = people.count() + max_count
> +            return list(map(person_to_dict, people[min_count:]))
>          else:
>              return list(map(person_to_dict, people))
>      except Person.DoesNotExist:
> @@ -607,8 +607,8 @@ def patch_list(filt=None):
>          if max_count > 0:
>              return list(map(patch_to_dict, patches[:max_count]))
>          elif max_count < 0:
> -            query = patches.reverse()[:-max_count]
> -            return list(map(patch_to_dict, reversed(query)))
> +            min_count = patches.count() + max_count
> +            return list(map(patch_to_dict, patches[min_count:]))
>          else:
>              return list(map(patch_to_dict, patches))
>      except Patch.DoesNotExist:
> @@ -803,8 +803,8 @@ def state_list(search_str=None, max_count=0):
>          if max_count > 0:
>              return list(map(state_to_dict, states[:max_count]))
>          elif max_count < 0:
> -            query = states.reverse()[:-max_count]
> -            return list(map(state_to_dict, reversed(query)))
> +            min_count = states.count() + max_count
> +            return list(map(state_to_dict, states[min_count:]))
>          else:
>              return list(map(state_to_dict, states))
>      except State.DoesNotExist:
> -- 
> 2.7.4
>
> _______________________________________________
> Patchwork mailing list
> Patchwork at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 859 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/patchwork/attachments/20160902/d44d3ae4/attachment.sig>


More information about the Patchwork mailing list