def get_skip_and_limit(self, params=None): """ Perform validation and return sanitized values for _skip and _limit params of the request that's currently being processed. """ max_limit = self.get_max_limit() if params is None: params = self.params if self.paginate: # _limit and _skip validation if not isint(params.get('_limit', 1)): raise ValidationError({ 'error': '_limit must be an integer (got "%s" instead).' % params['_limit'] }) if not isint(params.get('_skip', 1)): raise ValidationError({ 'error': '_skip must be an integer (got "%s" instead).' % params['_skip'] }) if params.get('_limit') and int(params['_limit']) > max_limit: raise ValidationError({ 'error': "The limit you set is larger than the maximum limit for this resource (max_limit = %d)." % max_limit }) if params.get('_skip') and int(params['_skip']) < 0: raise ValidationError({ 'error': '_skip must be a non-negative integer (got "%s" instead).' % params['_skip'] }) limit = min(int(params.get('_limit', self.default_limit)), max_limit) # Fetch one more so we know if there are more results. return int(params.get('_skip', 0)), limit else: return 0, max_limit
def get_skip_and_limit(self, params=None): """ Perform validation and return sanitized values for _skip and _limit params of the request that's currently being processed. """ max_limit = self.get_max_limit() if params is None: params = self.params if self.paginate: # _limit and _skip validation if not isint(params.get('_limit', 1)): raise ValidationError({'error': '_limit must be an integer (got "%s" instead).' % params['_limit']}) if not isint(params.get('_skip', 1)): raise ValidationError({'error': '_skip must be an integer (got "%s" instead).' % params['_skip']}) if params.get('_limit') and int(params['_limit']) > max_limit: raise ValidationError({'error': "The limit you set is larger than the maximum limit for this resource (max_limit = %d)." % max_limit}) if params.get('_skip') and int(params['_skip']) < 0: raise ValidationError({'error': '_skip must be a non-negative integer (got "%s" instead).' % params['_skip']}) limit = min(int(params.get('_limit', self.default_limit)), max_limit) # Fetch one more so we know if there are more results. return int(params.get('_skip', 0)), limit else: return 0, max_limit