예제 #1
0
def redirect_old_apps_view(request, *args, **kwargs):
    path = request.get_full_path()
    if path.find('/core') != -1:
        raise Http404()
    if path in ['/docs/', '/docs', '/core/docs/', '/core/docs']:
        return redirect('/api/docs/')
    new_path = '/core{}'.format(path)
    return HttpResponseTemporaryRedirect(new_path)
예제 #2
0
def redirect_format_api(request, *args, **kwargs):
    _path, query = request.path, request.GET.urlencode()
    matched = api_url_pattern.match(_path)
    if matched:
        kwargs = matched.groupdict()
        kwargs["query"] = query
        _path = '/api/{version}/{app}/{extra}?{query}'.format(**kwargs).rstrip("?")
        return HttpResponseTemporaryRedirect(_path)
    else:
        return JsonResponse({"msg": "Redirect url failed: {}".format(_path)}, status=404)
예제 #3
0
def redirect_format_api(request, *args, **kwargs):
    _path, query = request.path, request.GET.urlencode()
    matched = api_url_pattern.match(_path)
    if matched:
        version, app, extra = matched.groups()
        _path = '/api/{app}/{version}/{extra}?{query}'.format(**{
            "app": app,
            "version": version,
            "extra": extra,
            "query": query
        })
        return HttpResponseTemporaryRedirect(_path)
    else:
        return Response({"msg": "Redirect url failed: {}".format(_path)},
                        status=404)