From 4f8d459001bd399fcc46c685065cd2fa84633dc7 Mon Sep 17 00:00:00 2001 From: Aroy-Art Date: Wed, 27 Sep 2023 15:11:06 +0200 Subject: [PATCH] Add: custom template filters --- .../templatetags/custom_filters.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 archivist/sites/furaffinity/templatetags/custom_filters.py diff --git a/archivist/sites/furaffinity/templatetags/custom_filters.py b/archivist/sites/furaffinity/templatetags/custom_filters.py new file mode 100644 index 0000000..cb9d70c --- /dev/null +++ b/archivist/sites/furaffinity/templatetags/custom_filters.py @@ -0,0 +1,47 @@ +# custom_filters.py +from django import template + +import nh3 + +from bs4 import BeautifulSoup + +register = template.Library() + +@register.filter +def is_image(file_url): + image_extensions = ['.png', '.jpg', '.jpeg', '.gif', '.webp'] + return file_url.lower().endswith(tuple(image_extensions)) + + +@register.filter +def is_flash(file_url): + flash_extensions = ['.swf'] + return file_url.lower().endswith(tuple(flash_extensions)) + + +@register.filter +def is_pdf(file_url): + pdf_extensions = ['.pdf'] + return file_url.lower().endswith(tuple(pdf_extensions)) + +@register.filter +def descriptionHtml2Text(description): + if description.startswith("