Introduce Original image format

This commit is contained in:
PCoder 2022-07-28 20:19:00 +05:30
parent df9448e745
commit bdff34cf2b
2 changed files with 18 additions and 0 deletions

View file

@ -2,3 +2,4 @@ from .forms import *
from .models import * from .models import *
from .snippets import * from .snippets import *
from .admin import * from .admin import *
from .image_formats import *

View file

@ -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("{}<figcaption>{}</figcaption>", default_html, alt_text)
register_image_format(
OriginalImageFormat('original_fullwidth', 'Original image', 'bodytext-image', 'original')
)