Esempio n. 1
0
def view_leaflet(request: HttpRequest, leaflet_name: str) -> HttpResponseBase:
    leaflet = get_object_or_404(Leaflet, name=leaflet_name)  # type: Leaflet
    if not leaflet.pdf:
        raise Http404("Missing leaflet")
    return serve_file(leaflet.pdf.path,
                      content_type=CONTENTTYPE_PDF,
                      as_inline=True)
Esempio n. 2
0
def download_privatestorage(request: HttpRequest,
                            filename: str) -> HttpResponseBase:
    """Superuser access function, used for admin interface only."""
    fullpath = privatestorage.path(filename)
    content_type = mimetypes.guess_type(filename, strict=False)[0]
    # ... guess_type returns a (content_type, encoding) tuple
    return serve_file(fullpath, content_type=content_type, as_inline=True)
Esempio n. 3
0
def study_form(request: HttpRequest, study_id: str) -> HttpResponseBase:
    study = get_object_or_404(Study, pk=study_id)  # type: Study
    if not study.subject_form_template_pdf:
        raise Http404("No study form for clinicians to complete")
    return serve_file(study.subject_form_template_pdf.path,
                      content_type=CONTENTTYPE_PDF,
                      as_inline=True)
Esempio n. 4
0
def study_details(request: HttpRequest, study_id: str) -> HttpResponseBase:
    study = get_object_or_404(Study, pk=study_id)  # type: Study
    if not study.study_details_pdf:
        raise Http404("No details")
    return serve_file(study.study_details_pdf.path,
                      content_type=CONTENTTYPE_PDF,
                      as_inline=True)
Esempio n. 5
0
def view_letter(request: HttpRequest, letter_id: str) -> HttpResponseBase:
    letter = get_object_or_404(Letter, pk=letter_id)  # type: Letter
    validate_letter_request(request.user, letter)
    if not letter.pdf:
        raise Http404("Missing letter")
    return serve_file(letter.pdf.path,
                      content_type=CONTENTTYPE_PDF,
                      as_inline=True)
Esempio n. 6
0
def view_email_attachment(request: HttpRequest,
                          attachment_id: str) -> HttpResponseBase:
    attachment = get_object_or_404(
        EmailAttachment, pk=attachment_id)  # type: EmailAttachment  # noqa
    validate_email_request(request.user, attachment.email)
    if not attachment.file:
        raise Http404("Attachment missing")
    return serve_file(attachment.file.path,
                      content_type=attachment.content_type,
                      as_inline=True)