Ejemplo n.º 1
0
class AbstractFAQItem(ContentItem):
    """
    A one off FAQ.
    """
    question = PluginHtmlField()
    answer = PluginHtmlField()
    load_open = models.BooleanField(default=False)

    class Meta:
        abstract = True
        verbose_name = _('FAQ')
        verbose_name_plural = _('FAQs')

    def __str__(self):
        return self.question
Ejemplo n.º 2
0
class TextItem(ContentItem):
    """
    A snippet of HTML text to display on a page.
    """
    text = PluginHtmlField(_('text'), blank=True)
    # annoyingly, Django will create useless migrations every time choices
    # changes. These shouldn't be committed to ICEKit
    style = models.CharField(max_length=255,
                             choices=appsettings.TEXT_STYLE_CHOICES,
                             blank=True)

    class Meta:
        verbose_name = _('Text')
        verbose_name_plural = _('Text')

    def __str__(self):
        return Truncator(strip_tags(self.text)).words(20)

    def save(self, *args, **kwargs):
        # Make well-formed if requested
        if appsettings.FLUENT_TEXT_CLEAN_HTML:
            self.text = clean_html(self.text)

        # Remove unwanted tags if requested
        if appsettings.FLUENT_TEXT_SANITIZE_HTML:
            self.text = sanitize_html(self.text)

        super(TextItem, self).save(*args, **kwargs)
Ejemplo n.º 3
0
class ImageTextItem(ContentItem):
    """
    A block with image + text
    """
    ALIGN_LEFT = 'left'
    ALIGN_RIGHT = 'right'
    ALIGN_CHOICES = (
        (ALIGN_LEFT, _("Left")),
        (ALIGN_RIGHT, _("Right")),
    )

    title = models.CharField(_("Title"), max_length=200)
    image = PluginImageField(_("Image"))
    align = models.CharField(_("Align"), max_length=10, choices=ALIGN_CHOICES, default=ALIGN_LEFT)
    body = PluginHtmlField(_("Body"))

    url = PluginUrlField(_("URL"), blank=True)
    url_text = models.CharField(_("Text"), max_length=200, blank=True)

    class Meta:
        verbose_name = _("Image+text")
        verbose_name_plural = _("Image+text items")

    def __str__(self):
        return self.title

    @property
    def image_css_class(self):
        if self.align == self.ALIGN_RIGHT:
            return 'image_fr'
        else:
            return 'image_fl'
Ejemplo n.º 4
0
class TextItem(ContentItem):
    """
    A snippet of HTML text to display on a page.
    """

    text = PluginHtmlField(_("text"), blank=True)
    text_final = models.TextField(editable=False, blank=True, null=True)

    objects = ContentItemManager()  # Avoid Django 1.10 migrations

    class Meta:
        verbose_name = _("Text")
        verbose_name_plural = _("Text")

    def __str__(self):
        return Truncator(strip_tags(self.text)).words(20)

    def full_clean(self, *args, **kwargs):
        # This is called by the form when all values are assigned.
        # The pre filters are applied here, so any errors also appear as ValidationError.
        super().full_clean(*args, **kwargs)

        self.text, self.text_final = apply_filters(self,
                                                   self.text,
                                                   field_name="text")
        if self.text_final == self.text:
            # No need to store duplicate content:
            self.text_final = None
Ejemplo n.º 5
0
class FilerTeaserItem(ContentItem):

    title = models.CharField(_("title"), max_length=256)
    image = FilerImageField(verbose_name=_("image"), blank=True, null=True)
    url = PluginUrlField(_("URL"),
                         null=True,
                         blank=True,
                         help_text=_("If present image will be clickable."))

    description = PluginHtmlField(_("description"), blank=True, null=True)

    target = models.CharField(_("target"),
                              blank=True,
                              max_length=100,
                              choices=((
                                  ("", _("same window")),
                                  ("_blank", _("new window")),
                                  ("_parent", _("parent window")),
                                  ("_top", _("topmost frame")),
                              )))

    class Meta:
        verbose_name = _("Teaser")
        verbose_name_plural = _("Teasers")

    def __str__(self):
        return self.title
Ejemplo n.º 6
0
class ExcerptTextEntryMixin(models.Model):
    """
    Optional Mixin for adding excerpt text to a blog entry.
    """
    # While this field is designated as HTML field, it's not officially part of a plugin.
    # Hence it will not be converted into a WYSIWYG field by default.
    # Instead, the 'html_fields' in the base 'admin/fluent_blogs/entry/change_form.html' take care of that.
    excerpt_text = PluginHtmlField(_("Excerpt text"), help_text=_("This is the summary in the list of articles."))

    class Meta:
        abstract = True
Ejemplo n.º 7
0
class Marker(CachedModelMixin, models.Model):
    """
    A single point on the map
    """
    title = models.CharField(_("Title"), max_length=200)
    image = PluginImageField(_("Image"), blank=True)
    description = PluginHtmlField(_("Description"), blank=True)
    group = models.ForeignKey(MarkerGroup,
                              related_name='markers',
                              verbose_name=_("Group"),
                              blank=True,
                              null=True)
    location = GeopositionField(_("Location"))  # TODO: use different package?

    class Meta:
        verbose_name = _("Marker")
        verbose_name_plural = _("Markers")
        ordering = ('title', )

    def __str__(self):
        return self.title

    def clear_cache(self):
        # Called on save/delete by CachedModelMixin
        _clear_mapitem_cache()

    def to_dict(self, detailed=False):
        """
        Export the marker data for the frontend.

        :param expanded: Tell whether more detailed information should be added, for the detail page.
        :type expanded: bool
        """
        geoposition = self.location
        return {
            'id':
            self.pk,
            'title':
            self.title,
            'image':
            _image_to_dict(self, self.image),
            'description':
            self.description,
            'group_id':
            self.group_id,
            'location':
            [float(geoposition.latitude),
             float(geoposition.longitude)],
            #'click_zoom': 7,
            #cluster_weight
        }
Ejemplo n.º 8
0
class Col12Item(ContentItem):
    """
    A column that takes 1/2 of the width
    """
    title = models.CharField(_("Title"), max_length=200)
    icon = PluginImageField(_("Icon"), blank=True)
    body = PluginHtmlField(_("Body"))

    class Meta:
        verbose_name = _("Column (1/2)")
        verbose_name_plural = _("Columns (1/2)")

    def __str__(self):
        return self.title
Ejemplo n.º 9
0
class CookieLawItem(ContentItem):
    """
    Cookie law item
    """
    text = PluginHtmlField(
        _("Text"),
        help_text=
        _("For example: 'We use cookies to ensure you get the best experience on our website'"
          ))
    button_text = models.CharField(_("Button text"),
                                   max_length=100)  # e.g. "Close" or "Accept"

    class Meta:
        verbose_name = _("Cookie notification")
        verbose_name_plural = _("Cookie notifications")

    def __str__(self):
        return strip_tags(self.text).strip()
Ejemplo n.º 10
0
class TeaserItem(ContentItem):

    title = models.CharField(_("title"), max_length=256)
    image = PluginImageField(
        _("image"), upload_to=appsettings.FLUENTCMS_TEASER_UPLOAD_TO, blank=True, null=True
    )
    url = PluginUrlField(
        _("URL"), null=True, blank=True, help_text=_("If present image will be clickable.")
    )
    url_title = models.CharField(_("URL title"), max_length=200, blank=True, null=True)

    description = PluginHtmlField(_("description"), blank=True, null=True)

    target = models.CharField(
        _("target"),
        blank=True,
        max_length=100,
        choices=(
            (
                ("", _("same window")),
                ("_blank", _("new window")),
                ("_parent", _("parent window")),
                ("_top", _("topmost frame")),
            )
        ),
    )

    class Meta:
        verbose_name = _("Teaser")
        verbose_name_plural = _("Teasers")

    def __str__(self):
        return self.title

    def save(self, *args, **kwargs):
        if appsettings.FLUENTCMS_TEASER_CLEAN_HTML:
            self.description = clean_html(self.description)

        # Remove unwanted tags if requested
        if appsettings.FLUENTCMS_TEASER_SANITIZE_HTML:
            self.description = sanitize_html(self.description)

        super().save(*args, **kwargs)
Ejemplo n.º 11
0
class TextItem(ContentItem):
    """
    A snippet of HTML text to display on a page.
    """
    text = PluginHtmlField(_('text'), blank=True)

    class Meta:
        verbose_name = _('Text')
        verbose_name_plural = _('Text')

    def __unicode__(self):
        return Truncator(strip_tags(self.text)).words(20)

    def save(self, *args, **kwargs):
        # Make well-formed if requested
        if appsettings.FLUENT_TEXT_CLEAN_HTML:
            self.text = clean_html(self.text)

        # Remove unwanted tags if requested
        if appsettings.FLUENT_TEXT_SANITIZE_HTML:
            self.text = sanitize_html(self.text)

        super(TextItem, self).save(*args, **kwargs)
Ejemplo n.º 12
0
class BlockItem(ContentItem):
    """
    RUS: Класс экземпляра блока (BlockItem).
    Определяет поля и их значения.
    """
    SHORT_SUBTITLE_MAX_WORDS_COUNT = 12
    SHORT_SUBTITLE_MAX_CHARS_COUNT = 120
    SHORT_SUBTITLE_TRUNCATE = '...'

    text = PluginHtmlField(_('text'), blank=True)
    text_final = models.TextField(editable=False, blank=True, null=True)
    subjects = models.ManyToManyField('Publication',
                                      related_name='block_subjects',
                                      db_table='{}_block_subjects'.format(
                                          settings.EDW_APP_LABEL))

    class Meta:
        """
        RUS: Метаданные класса BlockItem.
        """
        app_label = settings.EDW_APP_LABEL
        verbose_name = _('Block')
        verbose_name_plural = _('Blocks')

    def __str__(self):
        """
        RUS: При превышении длины подзаголовок обрезается до нужного количества символов.
        Строковое представление данных.
        """
        return Truncator(
            Truncator(strip_tags(self.text)).words(
                self.SHORT_SUBTITLE_MAX_WORDS_COUNT,
                truncate=self.SHORT_SUBTITLE_TRUNCATE)).chars(
                    self.SHORT_SUBTITLE_MAX_CHARS_COUNT,
                    truncate=self.SHORT_SUBTITLE_TRUNCATE)

    def full_clean(self, *args, **kwargs):
        """
        RUS: Проверка данных текста формы.
        Текст должен быть проверен типографом и удалить непечатные символы.
        """
        # This is called by the form when all values are assigned.
        # The pre filters are applied here, so any errors also appear as ValidationError.
        super(BlockItem, self).full_clean(*args, **kwargs)

        # todo: переделать через фильтры и сделать фильтр типографа последним, remove_unprintable сделать тоже фильтром
        self.text = Typograph.typograph_html(remove_unprintable(self.text),
                                             'ru')

        self.text, self.text_final = apply_filters(self,
                                                   self.text,
                                                   field_name='text')

        if self.text_final == self.text:
            # No need to store duplicate content:
            self.text_final = None

    def get_stripped_text(self, with_dots_in_headings=False):
        text = self.text

        if with_dots_in_headings:
            expr = r'(\w)(</h[1-6]>)'
            if six.PY2:
                expr = expr.decode('raw_unicode_escape')
            pattern = re.compile(expr, re.UNICODE)
            text = re.sub(
                pattern,
                lambda match: '. '.join(list(match.groups())),
                text,
            )

        return strip_tags(text)