"""A hero component with an image (commonly for background) and a content."""fromdjango.confimportsettingsfromdjango.dbimportmodelsfromdjango.utils.encodingimportforce_strfromdjango.utils.htmlimportstrip_tagsfromdjango.utils.textimportTruncatorfromdjango.utils.translationimportgettext_lazyas_fromcms.models.pluginmodelimportCMSPluginfromsmart_media.mixinsimportSmartFormatMixinfromsmart_media.modelfieldsimportSmartMediaFieldfrom..choices_helpersimportget_hero_template_choices,get_hero_template_defaultfrom.mixinsimportFeatureMixinModel
[docs]classHero(SmartFormatMixin,FeatureMixinModel,CMSPlugin):""" Hero component. """template=models.CharField(_("Template"),blank=False,max_length=150,choices=get_hero_template_choices(),default=get_hero_template_default(),help_text=_("Used template for content look."),)""" Template choice from available plugin templates in setting ``BLOCKS_HERO_TEMPLATES``. Default to the first choice item. """image=SmartMediaField(_("Image"),max_length=255,blank=True,null=True,default=None,upload_to="blocks/hero/%y/%m",)""" Optional image file. """image_alt=models.CharField(_("Alternative image text"),blank=True,max_length=125,default="",)""" An optional text string for alternative image text. """content=models.TextField(_(u"Content"),blank=False,default="",)""" Required long text, it will be editable through CKeditor on plugin form. """size_features=models.ManyToManyField("cmsplugin_blocks.Feature",verbose_name=_("size features"),related_name="%(app_label)s_%(class)s_size_related",blank=True,limit_choices_to={"scope":"size","plugins__contains":"Hero"},)""" Optional related size features. """color_features=models.ManyToManyField("cmsplugin_blocks.Feature",verbose_name=_("color features"),related_name="%(app_label)s_%(class)s_color_related",blank=True,limit_choices_to={"scope":"color","plugins__contains":"Hero"},)""" Optional related color features. """extra_features=models.ManyToManyField("cmsplugin_blocks.Feature",verbose_name=_("extra features"),related_name="%(app_label)s_%(class)s_extra_related",blank=True,limit_choices_to={"scope":"extra","plugins__contains":"Hero"},)""" Optional related extra features. """def__init__(self,*args,**kwargs):super().__init__(*args,**kwargs)self.content=force_str(self.content)def__str__(self):returnTruncator(strip_tags(self.content)).words(settings.BLOCKS_MODEL_TRUNCATION_LENGTH,truncate=settings.BLOCKS_MODEL_TRUNCATION_CHR)defget_image_format(self):returnself.media_format(self.image)classMeta:verbose_name=_("Hero")verbose_name_plural=_("Heros")