"""Provides an image plugin with support for setting the primary point ofinterest. This is very useful especially when cropping images. Depends on`django-imagefield <https://django-imagefield.readthedocs.io>`__."""importosfromcontent_editor.adminimportContentEditorInlinefromdjango.dbimportmodelsfromdjango.utils.htmlimportformat_htmlfromdjango.utils.translationimportgettext_lazyas_fromimagefield.fieldsimportImageField,PPOIFieldfromfeincms3.utilsimportupload_to__all__=("Image","ImageInline","render_image")
[docs]classImage(models.Model):""" Image plugin """image=ImageField(_("image"),upload_to=upload_to,width_field="width",height_field="height",ppoi_field="ppoi",# NOTE! You probably want to use auto_add_fields=True in your own# models and not worry about setting the *_field vars above.)width=models.PositiveIntegerField(_("image width"),blank=True,null=True,editable=False)height=models.PositiveIntegerField(_("image height"),blank=True,null=True,editable=False)ppoi=PPOIField(_("primary point of interest"))alternative_text=models.CharField(_("alternative text"),help_text=_("Describe the contents, e.g. for screenreaders."),max_length=1000,blank=True,)caption=models.CharField(_("caption"),blank=True,max_length=1000)classMeta:abstract=Trueverbose_name=_("image")verbose_name_plural=_("images")def__str__(self):returnself.captionoros.path.basename(self.image.name)
[docs]defrender_image(plugin,context=None,**kwargs):""" Return a simple, unscaled version of the image """returnformat_html('<img src="{}" alt="">',plugin.image.url)