示例#1
0
def inserted_file(request, filepath=""):
    """ Get image from local dropbox and serve.

    """
    challenge_short_name = request.challenge.short_name

    data_folder_root = get_data_folder_path(challenge_short_name)
    filepath = posixpath.normpath(filepath).lstrip("/")
    filename = safe_join(data_folder_root, filepath)
    # can this location be served regularly (e.g. it is in public folder)?
    serve_allowed = can_access(
        request.user, filepath, challenge=request.challenge
    )
    if not serve_allowed:
        raise PermissionDenied(
            "You do not have the correct permissions to access this page."
        )

    if serve_allowed:
        try:
            file = open(filename, "rb")
        except Exception:
            raise Http404

        django_file = File(file)
        return serve_file(django_file)

    else:
        return HttpResponseForbidden(
            "This file is not available without credentials."
        )
示例#2
0
def inserted_file(request, filepath=""):
    """ Get image from local dropbox and serve.

    """
    challenge_short_name = request.challenge.short_name

    data_folder_root = get_data_folder_path(challenge_short_name)
    filepath = posixpath.normpath(filepath).lstrip("/")
    filename = safe_join(data_folder_root, filepath)
    # can this location be served regularly (e.g. it is in public folder)?
    serve_allowed = can_access(
        request.user, filepath, challenge=request.challenge
    )
    if not serve_allowed:
        raise PermissionDenied(
            "You do not have the correct permissions to access this page."
        )

    if serve_allowed:
        try:
            file = open(filename, "rb")
        except Exception:
            raise Http404

        django_file = File(file)
        return serve_file(django_file)

    else:
        return HttpResponseForbidden(
            "This file is not available without credentials."
        )
示例#3
0
def serve_fullpath(*, fullpath):
    storage = DefaultStorage()

    if not (os.path.abspath(fullpath)
            == fullpath) or not storage.exists(fullpath):
        raise Http404("File not found.")

    try:
        f = storage.open(fullpath, "rb")
        file = File(f)
        return serve_file(file, save_as=True)
    except IOError:
        raise Http404("File not found.")
示例#4
0
def serve_fullpath(*, fullpath):
    storage = DefaultStorage()

    if not (os.path.abspath(fullpath) == fullpath) or not storage.exists(
        fullpath
    ):
        raise Http404("File not found.")

    try:
        f = storage.open(fullpath, "rb")
        file = File(f)
        return serve_file(file, save_as=True)
    except IOError:
        raise Http404("File not found.")