Skip to content

Commit

Permalink
feat: added pictures align features
Browse files Browse the repository at this point in the history
Signed-off-by: eknath.baravkar <[email protected]>
  • Loading branch information
baravkareknath committed Dec 7, 2023
1 parent 6a649db commit 7d2d24d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
9 changes: 3 additions & 6 deletions djangocms_picture/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,15 @@ class PicturePlugin(CMSPluginBase):
]

def get_render_template(self, context, instance, placeholder):
return 'djangocms_picture/{}/picture.html'.format(instance.template)
return 'djangocms_picture/{}/picture.html'.format(instance.template)

def render(self, context, instance, placeholder):
if instance.alignment:
# See https://getbootstrap.com/docs/5.2/content/images/#aligning-images
if instance.alignment != "center":
instance.add_classes(f"float-{instance.alignment}")
else:
instance.add_classes("mx-auto d-block")

instance.add_classes("mx-auto d-block")
classes = 'align-{} '.format(instance.alignment)
classes += instance.attributes.get('class', '')
# Set the class attribute to include the alignment html class
Expand All @@ -76,8 +75,6 @@ def render(self, context, instance, placeholder):
height=context.get('height') or 0,
)
context['img_srcset_data'] = instance.img_srcset_data

return super().render(context, instance, placeholder)



plugin_pool.register_plugin(PicturePlugin)
4 changes: 0 additions & 4 deletions djangocms_picture/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from filer.fields.image import FilerImageField
from filer.models import ThumbnailOption


# add setting for picture alignment, renders a class or inline styles
# depending on your template setup
def get_alignment():
Expand Down Expand Up @@ -50,7 +49,6 @@ def get_templates():
)
return choices


# use golden ration as default (https://en.wikipedia.org/wiki/Golden_ratio)
PICTURE_RATIO = getattr(settings, 'DJANGOCMS_PICTURE_RATIO', 1.6180)

Expand Down Expand Up @@ -188,7 +186,6 @@ class AbstractPicture(CMSPlugin):
default=False,
help_text=_('Crops the image according to the thumbnail settings provided in the template.'),
)

use_upscale = models.BooleanField(
verbose_name=_('Upscale image'),
blank=True,
Expand All @@ -215,7 +212,6 @@ class AbstractPicture(CMSPlugin):
help_text=_('Overrides width, height, and crop; scales up to the provided preset dimensions.'),
on_delete=models.CASCADE,
)

# Add an app namespace to related_name to avoid field name clashes
# with any other plugins that have a field with the same name as the
# lowercase of the class name of this model.
Expand Down

0 comments on commit 7d2d24d

Please sign in to comment.