def get_range(offset=None, limit=None, limit_default=None, limit_max=None): warnings.warn( 'rmr.views.Json.get_range() is deprecated and will be removed ' 'in rmr-django 2.0, use rmr.utils.range.get_range() instead and/or ' 'rmr.forms.OffsetLimit form to validate offset/limit request ' 'params', category=DeprecationWarning, ) start = 0 stop = None with contextlib.suppress(ValueError): start = offset and int(offset) or start if start < 0: raise rmr.ClientError( 'Offset must be a positive number', code='incorrect_offset', ) limit = limit and int(limit) or limit_default if limit is not None: if limit <= 0: raise rmr.ClientError( 'Limit must be a positive number', code='incorrect_limit', ) if limit_max and limit > limit_max: raise rmr.ClientError( 'Maximum value of limit must be ' 'less then or equal {}'.format(limit_max), code='max_limit_exceeded', ) stop = start + limit elif limit_max: raise rmr.ClientError( 'Limit must be provided', code='limit_not_provided', ) return start, stop raise rmr.ClientError( 'Limit and offset must be a numbers if provided', code='incorrect_limit_or_offset', )
def _view(request: http.HttpRequest, *args, **kwargs): form_get = get(request.GET) form_post = post(request.POST, request.FILES) if False in (form_get.is_valid(), form_post.is_valid()): raise rmr.ClientError( code='validation_error', message=dict(form_post.errors, **form_get.errors), ) request.GET = form_get.cleaned_data request.POST = form_post.cleaned_data return view(request, *args, **kwargs)