From d9ccfa59d381256adf2b0ac7e32500dc06356015 Mon Sep 17 00:00:00 2001 From: Aroy-Art Date: Mon, 21 Oct 2024 17:59:30 +0200 Subject: [PATCH] Add pdf media filter template tag --- .../apps/sites/templatetags/media_filters.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/archivist/apps/sites/templatetags/media_filters.py b/archivist/apps/sites/templatetags/media_filters.py index 2dc6963..d858604 100644 --- a/archivist/apps/sites/templatetags/media_filters.py +++ b/archivist/apps/sites/templatetags/media_filters.py @@ -35,3 +35,21 @@ def is_flash (mime_type): if valid_type in mime_type: return True return False + + +@register.filter +def is_pdf(mime_type): + """ + A function that takes the mime type as input and returns true if it is an pdf + """ + valid_pdf_mime_types = [ + "application/pdf", + "application/vnd.cups-pdf", + "application/x-pdf", + ] + + for valid_type in valid_pdf_mime_types: + if valid_type in mime_type: + return True + + return False