Python rest_framework.settings.api_settings.PAGE_SIZE Examples
The following are 8
code examples of rest_framework.settings.api_settings.PAGE_SIZE().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rest_framework.settings.api_settings
, or try the search function
.
Example #1
Source File: util.py From cadasta-platform with GNU Affero General Public License v3.0 | 6 votes |
def get_previous_link(request): """ Generate URL of previous page in pagination. """ limit = int(request.query_params.get('limit', api_settings.PAGE_SIZE)) offset = int(request.query_params.get('offset', 0)) if offset <= 0: return None url = request.build_absolute_uri() url = replace_query_param(url, 'limit', limit) if offset - limit <= 0: return remove_query_param(url, 'offset') offset = offset - limit return replace_query_param(url, 'offset', offset)
Example #2
Source File: checks.py From Dailyfresh-B2C with Apache License 2.0 | 6 votes |
def pagination_system_check(app_configs, **kwargs): errors = [] # Use of default page size setting requires a default Paginator class from rest_framework.settings import api_settings if api_settings.PAGE_SIZE and not api_settings.DEFAULT_PAGINATION_CLASS: errors.append( Warning( "You have specified a default PAGE_SIZE pagination rest_framework setting," "without specifying also a DEFAULT_PAGINATION_CLASS.", hint="The default for DEFAULT_PAGINATION_CLASS is None. " "In previous versions this was PageNumberPagination. " "If you wish to define PAGE_SIZE globally whilst defining " "pagination_class on a per-view basis you may silence this check.", id="rest_framework.W001" ) ) return errors
Example #3
Source File: util.py From cadasta-platform with GNU Affero General Public License v3.0 | 5 votes |
def paginate_results(request, *qs_serializers): """ Custom pagination to handle multiple querysets and renderers. Supports serializing 1 to many different querysets. Based of DRF's LimitOffsetPagination. Useful when adding pagination to a regular APIView. qs_serializers - tuple of a queryset/array and respective serializer """ limit = int(request.query_params.get('limit', api_settings.PAGE_SIZE)) offset = int(request.query_params.get('offset', 0)) count = 0 cur_offset = offset out = [] for qs, serializer in qs_serializers: len_func = ('__len__' if isinstance(qs, list) else 'count') qs_len = getattr(qs, len_func)() count += qs_len if (len(out) < limit): end_index = min([limit - len(out) + cur_offset, qs_len]) qs = qs[cur_offset:end_index] if qs: out += serializer(qs, many=True).data cur_offset = max([cur_offset - end_index, 0]) return OrderedDict([ ('count', count), ('next', get_next_link(request, count)), ('previous', get_previous_link(request)), ('results', out), ])
Example #4
Source File: util.py From cadasta-platform with GNU Affero General Public License v3.0 | 5 votes |
def get_next_link(request, count): """ Generate URL of next page in pagination. """ limit = int(request.query_params.get('limit', api_settings.PAGE_SIZE)) offset = int(request.query_params.get('offset', 0)) if offset + limit >= count: return None url = request.build_absolute_uri() url = replace_query_param(url, 'limit', limit) offset = offset + limit return replace_query_param(url, 'offset', offset)
Example #5
Source File: test_pagination.py From cadasta-platform with GNU Affero General Public License v3.0 | 5 votes |
def test_next_link(self): req = self._get_request('/foo') assert ( get_next_link(req, 200) == 'http://testserver/foo?limit={}&offset=100'.format( api_settings.PAGE_SIZE))
Example #6
Source File: test_pagination.py From cadasta-platform with GNU Affero General Public License v3.0 | 5 votes |
def test_previous_link(self): req = self._get_request('/foo', {'offset': 200}) resp = get_previous_link(req) assert ( resp == 'http://testserver/foo?limit={}&offset=100'.format( api_settings.PAGE_SIZE)) req = self._get_request('/foo', {'offset': api_settings.PAGE_SIZE}) resp = get_previous_link(req) assert ( resp == 'http://testserver/foo?limit={}'.format( api_settings.PAGE_SIZE))
Example #7
Source File: pagination.py From ws-backend-community with GNU General Public License v3.0 | 5 votes |
def __init__( self, results=None, count=None, current_page=None, page_size=api_settings.PAGE_SIZE, ): self.results = results self.count = count self.current_page = current_page self.page_size = page_size
Example #8
Source File: mixin.py From ws-backend-community with GNU General Public License v3.0 | 5 votes |
def test_response_count_matches_results(self): """ Tests to ensure that the value in the count field matches the number of results returned in the response. :return: None """ response = self.send(user=self.auth_user) content = response.json() if content["count"] <= api_settings.PAGE_SIZE: self.assertEqual(content["count"], len(content["results"]))