Skip to content

Commit

Permalink
Merge pull request #3426 from akvo/release/candidate
Browse files Browse the repository at this point in the history
RSR release 3.40.3 Managua hot-fix
  • Loading branch information
punchagan authored Nov 20, 2018
2 parents b291a35 + c8a1f5b commit 5762018
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 8 deletions.
8 changes: 7 additions & 1 deletion akvo/rest/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
from rest_framework.response import Response


class LimitSizePageNumberPagination(pagination.PageNumberPagination):
class StandardSizePageNumberPagination(pagination.PageNumberPagination):
page_size = 30
page_size_query_param = 'limit'
max_page_size = 100


class LargeSizePageNumberPagination(pagination.PageNumberPagination):
page_size = 100
page_size_query_param = 'limit'
max_page_size = 1000


class TastypieOffsetPagination(pagination.LimitOffsetPagination):

def get_paginated_response(self, data):
Expand Down
2 changes: 2 additions & 0 deletions akvo/rest/views/indicator_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


from akvo.rsr.models import IndicatorDimension
from akvo.rest.pagination import LargeSizePageNumberPagination

from ..serializers import IndicatorDimensionSerializer
from ..viewsets import PublicProjectViewSet
Expand All @@ -17,3 +18,4 @@ class IndicatorDimensionViewSet(PublicProjectViewSet):
queryset = IndicatorDimension.objects.all()
serializer_class = IndicatorDimensionSerializer
project_relation = 'indicator__result__project__'
pagination_class = LargeSizePageNumberPagination
10 changes: 6 additions & 4 deletions akvo/rsr/static/dist/vendors.bundle.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ function fetchFromAPI(baseUrl) {
// if data.next then we have more data than fits in one go
if (data.next) {
// calculate how many pages we need to get and consturct URLs
const pageNumbers = range(2, Math.ceil(data.count / c.API_LIMIT));
const limitParam = baseUrl.match(/limit=\d+/);
const pageSize = limitParam
? parseInt(limitParam[0].split("=")[1]) || c.API_LIMIT
: c.API_LIMIT;
const pageNumbers = range(2, Math.ceil(data.count / pageSize));
const urls = pageNumbers.map(n => `${baseUrl}&page=${n}`);
// NOTE: we need to bind url to wrappedFetch or the array index will leak as a
// second param into the call. Nasty!
Expand Down
1 change: 1 addition & 0 deletions akvo/rsr/static/scripts-src/my-results/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

// TODO: several of these constants should be derived from the RSR settings
export const API_LIMIT = 100,
API_LARGE_LIMIT = 1000,
// From rsr.models.indicator.IndicatorPeriodData
ROLE_ME_MANAGER = "ROLE_ME_MANAGER",
ROLE_PROJECT_EDITOR = "ROLE_PROJECT_EDITOR",
Expand Down
4 changes: 3 additions & 1 deletion akvo/rsr/static/scripts-src/my-results/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ export const endpoints = {
results: id => `/rest/v2/result/?format=json&limit=${c.API_LIMIT}&project=${id}`,
indicators: id => `/rest/v1/indicator/?format=json&limit=${c.API_LIMIT}&result__project=${id}`,
dimensions: id =>
`/rest/v1/indicator_dimension/?format=json&limit=${c.API_LIMIT}&result__project=${id}`,
`/rest/v1/indicator_dimension/?format=json&limit=${
c.API_LARGE_LIMIT
}&indicator__result__project=${id}`,
periods: id =>
`/rest/v1/indicator_period/?format=json&limit=${
c.API_LIMIT
Expand Down
2 changes: 1 addition & 1 deletion akvo/settings/30-rsr.conf
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ REST_FRAMEWORK = {
'rest_framework.parsers.JSONParser',
'rest_framework_xml.parsers.XMLParser',
),
'DEFAULT_PAGINATION_CLASS': 'akvo.rest.pagination.LimitSizePageNumberPagination',
'DEFAULT_PAGINATION_CLASS': 'akvo.rest.pagination.StandardSizePageNumberPagination',
'PAGE_SIZE': 30,
# Harmonize datetime format across serializer formats
'DATETIME_FORMAT': 'iso-8601',
Expand Down

0 comments on commit 5762018

Please # to comment.