class FilerFolder(CMSPlugin): """ Plugin for storing any type of Folder. Default template displays files store inside this folder. """ STYLE_CHOICES = settings.CMSPLUGIN_FILER_FOLDER_STYLE_CHOICES DEFAULT_STYLE = settings.CMSPLUGIN_FILER_FOLDER_DEFAULT_STYLE title = models.CharField(_("title"), max_length=255, null=True, blank=True) folder = FilerFolderField(null=True, on_delete=models.SET_NULL) style = models.CharField( _('Style'), choices=STYLE_CHOICES, default=DEFAULT_STYLE, max_length=50) objects = FilerPluginManager(select_related=('folder',)) @property def view_option(self): warnings.warn("view_option on cmsplugin_filer_folder.FilderFolder is deprecated. Use .style instead.", DeprecationWarning) return self.style def __str__(self): return self.get_display_name() def get_display_name(self): if self.title: return self.title elif self.folder_id and self.folder.name: return self.folder.name return "<empty>" search_fields = ('title',)
class FilerFolder(CMSPlugin): """ Plugin for storing any type of Folder. Default template displays files store inside this folder. """ STYLE_CHOICES = settings.CMSPLUGIN_FILER_FOLDER_STYLE_CHOICES DEFAULT_STYLE = settings.CMSPLUGIN_FILER_FOLDER_DEFAULT_STYLE title = models.CharField(_("title"), max_length=255, null=True, blank=True) folder = FilerFolderField() style = models.CharField(_('Style'), choices=STYLE_CHOICES, default=DEFAULT_STYLE, max_length=50) objects = FilerPluginManager(select_related=('folder', )) @property def view_option(self): warnings.warn( "view_option on cmsplugin_filer_folder.FilderFolder is deprecated. Use .style instead.", DeprecationWarning) return self.style def __unicode__(self): if self.title: return self.title elif self.folder.name: # added if, because it raised attribute error when file wasnt defined return self.folder.name return "<empty>" search_fields = ('title', )
class FilerTeaser(CMSPlugin): """ A Teaser """ STYLE_CHOICES = settings.CMSPLUGIN_FILER_TEASER_STYLE_CHOICES DEFAULT_STYLE = settings.CMSPLUGIN_FILER_TEASER_DEFAULT_STYLE title = models.CharField(_("title"), max_length=255, blank=True) image = FilerImageField( blank=True, null=True, verbose_name=_("image"), on_delete=models.SET_NULL, ) image_url = models.URLField(_("alternative image url"), null=True, blank=True, default=None) style = models.CharField( _('Style'), choices=STYLE_CHOICES, default=DEFAULT_STYLE, max_length=255, blank=True) use_autoscale = models.BooleanField(_("use automatic scaling"), default=True, help_text=_('tries to auto scale the image based on the placeholder context')) width = models.PositiveIntegerField(_("width"), null=True, blank=True) height = models.PositiveIntegerField(_("height"), null=True, blank=True) free_link = models.CharField(_("link"), max_length=255, blank=True, null=True, help_text=_("if present image will be clickable")) page_link = PageField( null=True, blank=True, help_text=_("if present image will be clickable"), verbose_name=_("page link"), on_delete=models.SET_NULL, ) description = models.TextField(_("description"), blank=True, null=True) target_blank = models.BooleanField(_("open link in new window"), default=False) objects = FilerPluginManager(select_related=('image', 'page_link')) def clean(self): from django.core.exceptions import ValidationError # Make sure that either image or image_url is set if self.image and self.image_url: raise ValidationError(_('Either an image or an image url must be selected.')) def __str__(self): return self.title @property def link(self): try: if self.free_link: return self.free_link elif self.page_link and self.page_link: return self.page_link.get_absolute_url() else: return '' except Exception as e: print(e)
class FilerFile(CMSPlugin): """ Plugin for storing any type of file. Default template displays download link with icon (if available) and file size. This could be updated to use the mimetypes library to determine the type of file rather than storing a separate icon for each different extension. The icon search is currently performed within get_icon_url; this is probably a performance concern. """ STYLE_CHOICES = settings.CMSPLUGIN_FILER_FILE_STYLE_CHOICES DEFAULT_STYLE = settings.CMSPLUGIN_FILER_FILE_DEFAULT_STYLE title = models.CharField(_("title"), max_length=255, null=True, blank=True) file = FilerFileField(verbose_name=_('file')) target_blank = models.BooleanField(_('Open link in new window'), default=False) style = models.CharField(_('Style'), choices=STYLE_CHOICES, default=DEFAULT_STYLE, max_length=255, blank=True) objects = FilerPluginManager(select_related=('file', )) def get_icon_url(self): return self.file.icons['32'] def file_exists(self): return self.file.file.storage.exists(self.file.file.name) def get_file_name(self): if self.file.name in ('', None): name = "%s" % (self.file.original_filename, ) else: name = "%s" % (self.file.name, ) return name def get_ext(self): return self.file.extension def __str__(self): if self.title: return self.title elif self.file: # added if, because it raised attribute error when file wasnt defined return self.get_file_name() return "<empty>" search_fields = ('title', )
class FilerFile(CMSPlugin): """ Plugin for storing any type of file. Default template displays download link with icon (if available) and file size. This could be updated to use the mimetypes library to determine the type of file rather than storing a separate icon for each different extension. The icon search is currently performed within get_icon_url; this is probably a performance concern. """ title = models.CharField(_("title"), max_length=255, null=True, blank=True) file = FilerFileField(verbose_name=_('file')) objects = FilerPluginManager(select_related=('file', )) def get_icon_url(self): return self.file.icons['32'] def file_exists(self): return exists(self.file.path) def get_file_name(self): return self.file.name def get_ext(self): return self.file.extension def __unicode__(self): if self.title: return self.title elif self.file: # added if, because it raised attribute error when file wasnt defined return self.get_file_name() return "<empty>" search_fields = ('title', )
class FilerImage(CMSPlugin): LEFT = "left" RIGHT = "right" FLOAT_CHOICES = ( (LEFT, _("left")), (RIGHT, _("right")), ) STYLE_CHOICES = settings.CMSPLUGIN_FILER_IMAGE_STYLE_CHOICES DEFAULT_STYLE = settings.CMSPLUGIN_FILER_IMAGE_DEFAULT_STYLE style = models.CharField(_('Style'), choices=STYLE_CHOICES, default=DEFAULT_STYLE, max_length=50, blank=True) caption_text = models.CharField(_("caption text"), null=True, blank=True, max_length=255) image = FilerImageField(null=True, blank=True, default=None, verbose_name=_("image")) image_url = models.URLField(_("alternative image url"), null=True, blank=True, default=None) alt_text = models.CharField(_("alt text"), null=True, blank=True, max_length=255) use_original_image = models.BooleanField( _("use the original image"), default=False, help_text=_( 'do not resize the image. use the original image instead.')) thumbnail_option = models.ForeignKey( 'ThumbnailOption', null=True, blank=True, verbose_name=_("thumbnail option"), help_text= _('overrides width, height, crop and upscale with values from the selected thumbnail option' )) use_autoscale = models.BooleanField( _("use automatic scaling"), default=False, help_text=_( 'tries to auto scale the image based on the placeholder context')) width = models.PositiveIntegerField(_("width"), null=True, blank=True) height = models.PositiveIntegerField(_("height"), null=True, blank=True) crop = models.BooleanField(_("crop"), default=True) upscale = models.BooleanField(_("upscale"), default=True) alignment = models.CharField(_("image alignment"), max_length=10, blank=True, null=True, choices=FLOAT_CHOICES) free_link = models.CharField( _("link"), max_length=255, blank=True, null=True, help_text=_("if present image will be clickable")) page_link = PageField(null=True, blank=True, help_text=_("if present image will be clickable"), verbose_name=_("page link")) file_link = FilerFileField( null=True, blank=True, default=None, verbose_name=_("file link"), help_text=_("if present image will be clickable"), related_name='+') original_link = models.BooleanField( _("link original image"), default=False, help_text=_("if present image will be clickable")) description = models.TextField(_("description"), blank=True, null=True) target_blank = models.BooleanField(_('Open link in new window'), default=False) # we only add the image to select_related. page_link and file_link are FKs # as well, but they are not used often enough to warrant the impact of two # additional LEFT OUTER JOINs. objects = FilerPluginManager(select_related=('image', )) class Meta: verbose_name = _("filer image") verbose_name_plural = _("filer images") def clean(self): from django.core.exceptions import ValidationError # Make sure that either image or image_url is set if (not self.image and not self.image_url) or (self.image and self.image_url): raise ValidationError( _('Either an image or an image url must be selected.')) def __unicode__(self): if self.image: return self.image.label else: return unicode( _("Image Publication %(caption)s") % {'caption': self.caption or self.alt}) return '' @property def caption(self): if self.image: return self.caption_text or self.image.default_caption else: return self.caption_text @property def alt(self): if self.image: return self.alt_text or self.image.default_alt_text or self.image.label else: return self.alt_text @property def link(self): if self.free_link: return self.free_link elif self.page_link: return self.page_link.get_absolute_url() elif self.file_link: return self.file_link.url elif self.original_link: if self.image: return self.image.url else: return self.image_url else: return ''
class FilerImage(CMSPlugin): LEFT = "left" RIGHT = "right" CENTER = "center" FLOAT_CHOICES = ( (LEFT, _("left")), (RIGHT, _("right")), (CENTER, _("center")), ) STYLE_CHOICES = settings.CMSPLUGIN_FILER_IMAGE_STYLE_CHOICES DEFAULT_STYLE = settings.CMSPLUGIN_FILER_IMAGE_DEFAULT_STYLE EXCLUDED_KEYS = [ 'class', 'href', 'target', ] style = models.CharField(_('Style'), choices=STYLE_CHOICES, default=DEFAULT_STYLE, max_length=50, blank=True) caption_text = models.CharField(_("caption text"), null=True, blank=True, max_length=255) image = FilerImageField( null=True, blank=True, default=None, verbose_name=_("image"), on_delete=models.SET_NULL, ) image_url = models.URLField(_("alternative image url"), null=True, blank=True, default=None) alt_text = models.CharField(_("alt text"), null=True, blank=True, max_length=255) use_original_image = models.BooleanField( _("use the original image"), default=False, help_text=_( 'do not resize the image. use the original image instead.')) thumbnail_option = models.ForeignKey( 'filer.ThumbnailOption', null=True, blank=True, verbose_name=_("thumbnail option"), help_text= _('overrides width, height, crop and upscale with values from the selected thumbnail option' ), on_delete=models.CASCADE) use_autoscale = models.BooleanField( _("use automatic scaling"), default=False, help_text=_( 'tries to auto scale the image based on the placeholder context')) UNIT_CHOICES = ( ('px', _("pixels (px)")), ('%', _("percent (%)")), ('em', _("relative to font size (em)")), ) width = models.PositiveIntegerField(_("width"), null=True, blank=True) width_units = models.CharField(_("width units"), max_length=2, choices=UNIT_CHOICES, default='px') height = models.PositiveIntegerField(_("height"), null=True, blank=True) height_units = models.CharField(_("height units"), max_length=2, choices=UNIT_CHOICES, default='px') crop = models.BooleanField(_("crop"), default=True) upscale = models.BooleanField(_("upscale"), default=True) alignment = models.CharField(_("image alignment"), max_length=10, blank=True, null=True, choices=FLOAT_CHOICES) free_link = models.CharField( _("link"), max_length=2000, blank=True, null=True, help_text=_("if present image will be clickable")) page_link = PageField(null=True, blank=True, help_text=_("if present image will be clickable"), verbose_name=_("page link")) file_link = FilerFileField( null=True, blank=True, default=None, verbose_name=_("file link"), help_text=_("if present image will be clickable"), related_name='+', on_delete=models.SET_NULL, ) original_link = models.BooleanField( _("link original image"), default=False, help_text=_("if present image will be clickable")) description = models.TextField(_("description"), blank=True, null=True) target_blank = models.BooleanField(_('Open link in new window'), default=False) link_attributes = AttributesField( excluded_keys=EXCLUDED_KEYS, blank=True, help_text=_('Optional. Adds HTML attributes to the rendered link.')) cmsplugin_ptr = models.OneToOneField( to=CMSPlugin, related_name='%(app_label)s_%(class)s', parent_link=True, on_delete=models.CASCADE, ) # we only add the image to select_related. page_link and file_link are FKs # as well, but they are not used often enough to warrant the impact of two # additional LEFT OUTER JOINs. objects = FilerPluginManager(select_related=('image', )) class Meta: verbose_name = _("filer image") verbose_name_plural = _("filer images") def clean(self): from django.core.exceptions import ValidationError # Make sure that either image or image_url is set if (not self.image and not self.image_url) or (self.image and self.image_url): raise ValidationError( _('Either an image or an image url must be selected.')) def __str__(self): if self.image: return self.image.label else: return _("Image Publication %(caption)s") % { 'caption': self.caption or self.alt } return '' @property def caption(self): if self.image: return self.caption_text or self.image.default_caption else: return self.caption_text @property def alt(self): if self.image: return self.alt_text or self.image.default_alt_text or self.image.label else: return self.alt_text @property def link(self): if self.free_link: return self.free_link elif self.page_link: return self.page_link.get_absolute_url() elif self.file_link: return self.file_link.url elif self.original_link: if self.image: return self.image.url else: return self.image_url else: return ''
class FilerFile(CMSPlugin): """ Plugin for storing any type of file. Default template displays download link with icon (if available) and file size. This could be updated to use the mimetypes library to determine the type of file rather than storing a separate icon for each different extension. The icon search is currently performed within get_icon_url; this is probably a performance concern. """ STYLE_CHOICES = settings.CMSPLUGIN_FILER_FILE_STYLE_CHOICES DEFAULT_STYLE = settings.CMSPLUGIN_FILER_FILE_DEFAULT_STYLE EXCLUDED_KEYS = ['href', 'target', ] title = models.CharField(_("title"), max_length=255, null=True, blank=True) file = FilerFileField( verbose_name=_('file'), null=True, on_delete=models.SET_NULL, ) target_blank = models.BooleanField(_('Open link in new window'), default=False) style = models.CharField( _('Style'), choices=STYLE_CHOICES, default=DEFAULT_STYLE, max_length=255, blank=True) link_attributes = AttributesField(excluded_keys=EXCLUDED_KEYS, blank=True, help_text=_('Optional. Adds HTML attributes to the rendered link.')) cmsplugin_ptr = models.OneToOneField( to=CMSPlugin, related_name='%(app_label)s_%(class)s', parent_link=True, on_delete=models.CASCADE, ) objects = FilerPluginManager(select_related=('file',)) def get_icon_url(self): if self.file_id: return self.file.icons['32'] return '' def file_exists(self): if self.file.file.name != None: return self.file.file.storage.exists(self.file.file.name) return False def get_file_name(self): if not self.file_id: return '' if self.file.name in ('', None): name = "%s" % (self.file.original_filename,) else: name = "%s" % (self.file.name,) return name def get_ext(self): return self.file.extension def __str__(self): if self.title: return self.title elif self.file_id: # added if, because it raised attribute error when file wasnt defined return self.get_file_name() return "<empty>" class Meta: app_label = 'cmsplugin_filer_file' search_fields = ('title',)