From bdff34cf2b59b8b5d21f08600f1e9c298214faa1 Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 28 Jul 2022 20:19:00 +0530 Subject: [PATCH 1/2] Introduce Original image format --- publichealth/home/models/__init__.py | 1 + publichealth/home/models/image_formats.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 publichealth/home/models/image_formats.py diff --git a/publichealth/home/models/__init__.py b/publichealth/home/models/__init__.py index 52e04bb..bc6c174 100644 --- a/publichealth/home/models/__init__.py +++ b/publichealth/home/models/__init__.py @@ -2,3 +2,4 @@ from .forms import * from .models import * from .snippets import * from .admin import * +from .image_formats import * diff --git a/publichealth/home/models/image_formats.py b/publichealth/home/models/image_formats.py new file mode 100644 index 0000000..a625261 --- /dev/null +++ b/publichealth/home/models/image_formats.py @@ -0,0 +1,17 @@ +# image_formats.py +from django.utils.html import format_html +from wagtail.images.formats import Format, register_image_format + + +class OriginalImageFormat(Format): + + def image_to_html(self, image, alt_text, extra_attributes=None): + + default_html = super().image_to_html(image, alt_text, extra_attributes) + + return format_html("{}
{}
", default_html, alt_text) + + +register_image_format( + OriginalImageFormat('original_fullwidth', 'Original image', 'bodytext-image', 'original') +) From 6818359e1a6e2349fb9d5fe8f174897fc605c82b Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 28 Jul 2022 20:36:01 +0530 Subject: [PATCH 2/2] Remove unwanted code --- publichealth/home/models/image_formats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publichealth/home/models/image_formats.py b/publichealth/home/models/image_formats.py index a625261..ebf4968 100644 --- a/publichealth/home/models/image_formats.py +++ b/publichealth/home/models/image_formats.py @@ -9,7 +9,7 @@ class OriginalImageFormat(Format): default_html = super().image_to_html(image, alt_text, extra_attributes) - return format_html("{}
{}
", default_html, alt_text) + return format_html("{}", default_html, alt_text) register_image_format(