コード例 #1
0
ファイル: views.py プロジェクト: comic/comic-django
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
ファイル: views.py プロジェクト: picspin/grand-challenge.org
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
ファイル: views.py プロジェクト: comic/comic-django
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.")