def _extract_pagination_rules_from_token(self, sorting): """Get pagination params.""" queryparams = self.request.GET paginate_by = self.request.registry.settings['cliquet.paginate_by'] limit = queryparams.get('_limit', paginate_by) if limit: try: limit = int(limit) except ValueError: error_details = { 'location': 'querystring', 'description': "_limit should be an integer" } raise_invalid(self.request, **error_details) # If limit is higher than paginate_by setting, ignore it. if limit and paginate_by: limit = min(limit, paginate_by) token = queryparams.get('_token', None) filters = [] if token: try: last_record = json.loads(decode64(token)) assert isinstance(last_record, dict) except (ValueError, TypeError, AssertionError): error_msg = '_token has invalid content' error_details = { 'location': 'querystring', 'description': error_msg } raise_invalid(self.request, **error_details) filters = self._build_pagination_rules(sorting, last_record) return filters, limit
def _extract_pagination_rules_from_token(self, limit, sorting): """Get pagination params.""" queryparams = self.request.GET token = queryparams.get('_token', None) filters = [] if token: try: last_record = json.loads(decode64(token)) assert isinstance(last_record, dict) except (ValueError, TypeError, AssertionError): error_msg = '_token has invalid content' error_details = { 'location': 'querystring', 'description': error_msg } raise_invalid(self.request, **error_details) filters = self._build_pagination_rules(sorting, last_record) return filters
def _extract_pagination_rules_from_token(self, limit, sorting): """Get pagination params.""" queryparams = self.request.GET token = queryparams.get('_token', None) filters = [] offset = 0 if token: try: tokeninfo = json.loads(decode64(token)) if not isinstance(tokeninfo, dict): raise ValueError() last_record = tokeninfo['last_record'] offset = tokeninfo['offset'] except (ValueError, KeyError, TypeError): error_msg = '_token has invalid content' error_details = { 'location': 'querystring', 'description': error_msg } raise_invalid(self.request, **error_details) filters = self._build_pagination_rules(sorting, last_record) return filters, offset