Exemplo n.º 1
0
def export_file(request):
    file_type = request.GET['type']
    url = request.GET['path']
    file_name = 'dashboards.' + file_type
    css_file = 'file://' + STATICFILES_DIRS[0] + '/css/pdf.css'

    cookie = {}
    cookie['name'] = 'sessionid'
    cookie['value'] = request.COOKIES[cookie['name']]

    javascript_delay = '10000'

    if 'pdf' in file_type:
        options = {'orientation': 'Landscape', 'javascript-delay': javascript_delay, 'quiet': ' '}
        content_type = 'application/pdf'
    else:
        options = {'javascript-delay': javascript_delay, 'width': '1425', 'quality': '100', 'quiet': ' '}
        content_type = 'image/JPEG'

    pdf_content = print_pdf(type=file_type, url=url, output_path=None, options=options, cookie=cookie, css_file=css_file)

    if isinstance(pdf_content, IOError):
        response = HttpResponse(status=500)
    else:
        response = HttpResponse(content=pdf_content, content_type=content_type)
        response['Content-Disposition'] = 'attachment; filename=' + file_name

    response.set_cookie('fileDownloadToken', 'true')
    return response
Exemplo n.º 2
0
def export_file(request):
    file_type = request.GET["type"]
    url = request.GET["path"]
    file_name = "dashboards." + file_type
    css_file = "file://" + STATICFILES_DIRS[0] + "/css/pdf.css"

    cookie = {}
    cookie["name"] = "sessionid"
    cookie["value"] = request.COOKIES[cookie["name"]]

    javascript_delay = "10000"

    if "pdf" in file_type:
        options = {"orientation": "Landscape", "javascript-delay": javascript_delay, "quiet": " "}
        content_type = "application/pdf"
    else:
        options = {"javascript-delay": javascript_delay, "width": "1425", "quality": "100", "quiet": " "}
        content_type = "image/JPEG"

    pdf_content = print_pdf(
        type=file_type, url=url, output_path=None, options=options, cookie=cookie, css_file=css_file
    )

    if isinstance(pdf_content, IOError):
        response = HttpResponse(status=500)
    else:
        response = HttpResponse(content=pdf_content, content_type=content_type)
        response["Content-Disposition"] = "attachment; filename=" + file_name

    response.set_cookie("fileDownloadToken", "true")
    return response