Ejemplo n.º 1
0
def file(request, path, name):
    try:
        page = Page(path)
    except InvalidPageError:
        raise Http404()

    if page.lpath != path:
        logger = logging.getLogger(u'poleno.pages')
        logger.warning(
            u'Redirected request: /{}/{} -> /{}{}; Referer: {}'.format(
                page.lang, path, page.lang, page.path,
                request.META.get(u'HTTP_REFERER', u'--')))

    try:
        file = File(page, name)
    except InvalidFileError:
        raise Http404()

    if page.lpath != path:
        return HttpResponseRedirect(
            reverse(u'pages:file', args=[page.lpath, name]))

    return send_file_response(request,
                              file.filepath,
                              file.name,
                              file.content_type,
                              attachment=False)
Ejemplo n.º 2
0
def file(request, path, name):
    try:
        page = Page(path)
    except InvalidPageError:
        return HttpResponseNotFound()

    if page.lpath != path:
        logging.getLogger(u'poleno.pages').warning(u'Redirected request: /%s/%s -> /%s%s; Referer: %s',
                page.lang, path, page.lang, page.path, request.META.get(u'HTTP_REFERER', u'--'))

    try:
        file = File(page, name)
    except InvalidFileError:
        return HttpResponseNotFound()

    if page.lpath != path:
        return HttpResponseRedirect(reverse(u'pages:file', args=[page.lpath, name]))

    return send_file_response(request, file.filepath, file.name, file.content_type, attachment=False)
Ejemplo n.º 3
0
def download(request, attachment):
    # FIXME: If ``attachment.content_type`` is among whitelisted content types, we should use it.
    path = os.path.join(settings.MEDIA_ROOT, attachment.file.name)
    return send_file_response(request, path, attachment.name, u'application/octet-stream')
Ejemplo n.º 4
0
 def file_view(request):
     path = request.GET[u'path']
     name = request.GET[u'name']
     content_type = request.GET[u'content-type']
     return send_file_response(request, path, name, content_type)
Ejemplo n.º 5
0
 def file_view(request):
     path = request.GET[u'path']
     name = request.GET[u'name']
     content_type = request.GET[u'content-type']
     return send_file_response(request, path, name, content_type)
Ejemplo n.º 6
0
def download(request, attachment):
    path = os.path.join(settings.MEDIA_ROOT, attachment.file.name)
    return send_file_response(request, path, attachment.name, attachment.content_type)
Ejemplo n.º 7
0
def download(request, attachment):
    # FIXME: If ``attachment.content_type`` is among whitelisted content types, we should use it.
    path = os.path.join(settings.MEDIA_ROOT, attachment.file.name)
    return send_file_response(request, path, attachment.name,
                              u'application/octet-stream')