You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2021/02/04 23:42:23 UTC
[airavata-django-portal] branch develop updated: Preserve query
params in pagination next/previous links
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git
The following commit(s) were added to refs/heads/develop by this push:
new 611864f Preserve query params in pagination next/previous links
611864f is described below
commit 611864fba0031dff3cc906230e8760e6c620d4c9
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Thu Feb 4 18:39:44 2021 -0500
Preserve query params in pagination next/previous links
---
django_airavata/apps/api/view_utils.py | 10 +++++++++-
django_airavata/apps/api/views.py | 5 +++--
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/django_airavata/apps/api/view_utils.py b/django_airavata/apps/api/view_utils.py
index 45616f9..ddef7e3 100644
--- a/django_airavata/apps/api/view_utils.py
+++ b/django_airavata/apps/api/view_utils.py
@@ -5,6 +5,7 @@ from datetime import datetime
import pytz
from django.conf import settings
from django.http import Http404
+from django.http.request import QueryDict
from rest_framework import mixins, pagination, permissions
from rest_framework.response import Response
from rest_framework.reverse import reverse
@@ -105,6 +106,9 @@ class APIResultIterator(object):
limit = -1
offset = 0
+ def __init__(self, query_params=None):
+ self.query_params = query_params if query_params is not None else QueryDict()
+
def get_results(self, limit=-1, offset=0):
raise NotImplementedError("Subclasses must implement get_results")
@@ -133,6 +137,7 @@ class APIResultPagination(pagination.LimitOffsetPagination):
def paginate_queryset(self, queryset, request, view=None):
assert isinstance(
queryset, APIResultIterator), "queryset is not an APIResultIterator: {}".format(queryset)
+ self.query_params = queryset.query_params.copy()
self.limit = self.get_limit(request)
if self.limit is None:
return None
@@ -187,7 +192,10 @@ class APIResultPagination(pagination.LimitOffsetPagination):
def get_base_url(self):
if hasattr(self, 'viewname'):
- return self.request.build_absolute_uri(reverse(self.viewname))
+ base_url = self.request.build_absolute_uri(reverse(self.viewname))
+ if len(self.query_params) > 0:
+ base_url += f"?{self.query_params.urlencode()}"
+ return base_url
else:
return self.request.build_absolute_uri()
diff --git a/django_airavata/apps/api/views.py b/django_airavata/apps/api/views.py
index 76b4148..04d98bb 100644
--- a/django_airavata/apps/api/views.py
+++ b/django_airavata/apps/api/views.py
@@ -469,7 +469,8 @@ class ExperimentSearchViewSet(mixins.ListModelMixin, GenericAPIBackedViewSet):
view.authz_token, view.gateway_id, view.username, filters,
limit, offset)
- return ExperimentSearchResultIterator()
+ # Preserve query parameters when moving to next and previous links
+ return ExperimentSearchResultIterator(query_params=self.request.query_params.copy())
def get_instance(self, lookup_value):
raise NotImplementedError()
@@ -1676,7 +1677,7 @@ class IAMUserViewSet(mixins.RetrieveModelMixin,
def get_results(self, limit=-1, offset=0):
return map(convert_user_profile,
iam_admin_client.get_users(offset, limit, search))
- return IAMUsersResultIterator()
+ return IAMUsersResultIterator(query_params=self.request.query_params.copy())
def get_instance(self, lookup_value):
return self._convert_user_profile(