Skip to content

Commit

Permalink
Overwrite default thumbnail generation of picture plugin
Browse files Browse the repository at this point in the history
Responsive-sized thumbnails are generated via template tag
  • Loading branch information
stefanw authored and pajowu committed Sep 25, 2023
1 parent 5e058fa commit 703b3fe
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions fragdenstaat_de/fds_cms/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from djangocms_picture.cms_plugins import PicturePlugin as BasePicturePlugin

from froide.foirequest.models import FoiRequest
from froide.helper.utils import get_redirect_url
Expand Down Expand Up @@ -681,3 +682,29 @@ def padding(self, instance):
elif instance.spacing == "md":
return "p-3 p-md-4"
return "p-3"


class PicturePlugin(BasePicturePlugin):
def render(self, context, instance, placeholder):
# Overwrite render method to remove original's
# thumbnail generation in img_srcset_data property

if instance.alignment:
classes = "align-{} ".format(instance.alignment)
classes += instance.attributes.get("class", "")
# Set the class attribute to include the alignment html class
# This is done to leverage the attributes_str property
instance.attributes["class"] = classes
# assign link to a context variable to be performant
context["picture_link"] = instance.get_link()
context["picture_size"] = instance.get_size(
width=context.get("width") or 0,
height=context.get("height") or 0,
)

# Note: Skipping base plugin render method
return super(BasePicturePlugin, self).render(context, instance, placeholder)


plugin_pool.unregister_plugin(BasePicturePlugin)
plugin_pool.register_plugin(PicturePlugin)

0 comments on commit 703b3fe

Please sign in to comment.