Browse Source

SimpleImagePlugin and SimpleDownloadPlugin.

master
Erik Stein 6 years ago
parent
commit
26611844b7
  1. 2
      CHANGES
  2. 63
      content_plugins/base.py

2
CHANGES

@ -1,3 +1,5 @@
- Added SimpleImagePlugin and SimpleDownloadPlugin.
0.3.19 2019-04-02 0.3.19 2019-04-02
- Again better template_name handling. - Again better template_name handling.
- Added ObjectPluginBase class. - Added ObjectPluginBase class.

63
content_plugins/base.py

@ -243,35 +243,38 @@ class ObjectPluginBase(FilesystemTemplateRendererPlugin):
return inline return inline
# ImageBase can't live here because image managment is different from project to project class SimpleImageBase(StringRendererPlugin):
# class ImageBase(StyleMixin, BasePlugin): image = models.ImageField(_("image"), upload_to='images/%Y/%m/')
# image = models.ForeignKey(Image, on_delete=models.PROTECT) caption = TranslatableCharField(_("caption"), max_length=500,
# alt_caption = TranslatableCharField(_("caption"), max_length=500, null=True, blank=True, help_text=_("Optional, used instead of the caption of the image object."))# null=True, blank=True,
help_text=_("Optional, used instead of the caption of the image object."))
# class Meta:
# abstract = True class Meta:
# verbose_name = _("image") abstract = True
# verbose_name_plural = _("images")# verbose_name = _("image")
verbose_name_plural = _("images")
# def render(self):
# template = """ def __str__(self):
# <figure class="image"> return getattr(self.image, 'name', "")
# <img src="{src}">#
def render(self):
# <figcaption> template = """
# {caption_text} <figure class="image">
# </figcaption> <img src="{src}">
# </figure>
# """ <figcaption>
# # TOOD Assemble caption from image's captions if empty {caption_text}
# return mark_safe(template.format( </figcaption>
# src=self.image.figure_image.url, </figure>
# caption_text=mark_safe(self.alt_caption or "") """
# ))
return mark_safe(template.format(
src=self.image.url,
# TODO See comments on ImageBase; remove DownloadBase caption_text=mark_safe(self.caption or "")
class DownloadBase(StyleMixin, StringRendererPlugin): ))
class SimpleDownloadBase(StringRendererPlugin):
file = models.FileField(upload_to='downloads/%Y/%m/') file = models.FileField(upload_to='downloads/%Y/%m/')
class Meta: class Meta:
@ -284,7 +287,7 @@ class DownloadBase(StyleMixin, StringRendererPlugin):
def render(self): def render(self):
template = """ template = """
<a href="{url}">{name}</a> <a href="{url}" download="{name}">{name}</a>
""" """
return mark_safe(template.format( return mark_safe(template.format(
url=self.file.url, url=self.file.url,

Loading…
Cancel
Save