class Article(models.Model): title = models.CharField(max_length=200) regions = [ Region(key="main", title="main region"), Region(key="sidebar", title="sidebar region"), ] def __str__(self): return self.title def get_absolute_url(self): return reverse("article_detail", kwargs={"pk": self.pk}) ArticlePlugin = create_plugin_base(Article) class RichText(AbstractRichText, ArticlePlugin): pass class Download(ArticlePlugin): file = models.TextField() # FileField, but charfield is easier to test. class Meta: verbose_name = "download" verbose_name_plural = "downloads" class Thing(models.Model):
from django.db import models from django.utils.translation import ugettext_lazy as _ from content_editor.models import Region, create_plugin_base from feincms3 import plugins from feincms3_downloads.plugins import DownloadBase class Article(models.Model): regions = [Region(key="main", title=_("main"))] ArticlePlugin = create_plugin_base(Article) class HTML(plugins.html.HTML, ArticlePlugin): pass class Download(DownloadBase, ArticlePlugin): pass
# MenuMixin MENUS = [("main", _("main")), ("footer", _("footer"))] # AppsMixin. We have two apps, one is for company PR, the other # for a more informal blog. # # NOTE! The app names (first element in the tuple) have to match the # article categories exactly for URL reversing and filtering articles by # app to work! (See app.articles.models.Article.CATEGORIES) APPLICATIONS = [ ("publications", _("publications"), {"urlconf": "testapp.articles_urls"}), ("blog", _("blog"), {"urlconf": "testapp.articles_urls"}), ] PagePlugin = create_plugin_base(Page) class Snippet(plugins.snippet.Snippet, PagePlugin): TEMPLATES = [("snippet.html", _("snippet"))] class Article(models.Model): title = models.CharField(_("title"), max_length=100) category = models.CharField( _("category"), max_length=20, choices=(("publications", "publications"), ("blog", "blog")), ) class Meta:
if not self.section or site == self.section.site: return reverse_app([f"{site.pk}-events"], "location-detail", kwargs={"slug": self.slug}) with set_current_site(self.section.site): return ("//" + self.section.site.host + reverse_app( [f"{self.section.site.id}-events"], "location-detail", urlconf=apps_urlconf(), kwargs={"slug": self.slug}, )) except NoReverseMatch: return "#" LocationPluginBase = create_plugin_base(Location) class LocationImage(plugins.image.Image, LocationPluginBase): caption = models.CharField(_("caption"), max_length=200, blank=True) def ical_calendar(queryset): begin = ("BEGIN:VCALENDAR\r\n" "VERSION:2.0\r\n" "METHOD:PUBLISH\r\n" "PRODID:JUSO\r\n") events = "".join(e.ical_event() for e in queryset) return begin + events + "END:VCALENDAR\r\n"
def entry_dict(self): form_entries = [] fields = self.get_fields() for entry in self.formentry_set.all(): form_entries.append(entry.get_values(fields)) fields.append("ip") fields.append("created") fields.append('sid') return form_entries, fields PluginBase = create_plugin_base(Form) class FormField(PluginBase): name = models.CharField(_("name"), max_length=140) input_type = models.CharField(_("type"), choices=INPUT_TYPES, max_length=140) slug = models.SlugField() required = models.BooleanField(_("required")) help_text = models.CharField(_("help text"), max_length=240, blank=True) choices = models.TextField(_("choices"), blank=True) initial = models.TextField(_("initial"), max_length=240, blank=True) size = models.TextField(_("size"), default="one", choices=SIZES) disallow_text = models.CharField(max_length=40, blank=True)
# for a more informal blog. # # NOTE! The app names (first element in the tuple) have to match the # article categories exactly for URL reversing and filtering articles by # app to work! (See app.articles.models.Article.CATEGORIES) APPLICATIONS = [ ('publications', _('publications'), { 'urlconf': 'app.articles.urls', }), ('blog', _('blog'), { 'urlconf': 'app.articles.urls', }), ] objects = PageManager() PagePlugin = create_plugin_base(Page) class RichText(plugins.RichText, PagePlugin): pass class Image(plugins.Image, PagePlugin): caption = models.CharField( _('caption'), max_length=200, blank=True, )
] constraints = [ models.UniqueConstraint(fields=["path", "site_id"], name="unique_page_for_path") ] class PagesPlugin(models.Model): pages = models.ManyToManyField(Page, related_name="+") class Meta: abstract = True PluginBase = create_plugin_base(Page) class External(feincms3_plugins.external.External, PluginBase): class Meta: verbose_name = _("external") class RichText(feincms3_plugins.richtext.RichText, PluginBase): class Meta: verbose_name = _("rich text") class GlossaryRichText(GlossaryContent, PluginBase): class Meta: verbose_name = _("glossary text")
It may feel weird since we're not using self.is_active, but that's on purpose. """ subscriber.is_active = False subscriber.save() return subscriber def is_idle(self): """ Check if subscriber has any email activity (opens/clicks) over the past 90 days """ return Open.objects.filter( date__gte=timezone.now() - timezone.timedelta(days=SQUEEZE_SUBSCRIBER_IDLE_DAYS)).exists() EmailMessagePlugin = create_plugin_base(EmailMessage) try: from squeezemail_extensions.models import * except ImportError as error: logger.error( "You need to create a squeezemail_extensions app with models.py inside." ) raise error.with_traceback(sys.exc_info()[2]) # class DripOperator(StepPlugin): # drip = models.ForeignKey('squeezemail.Drip', related_name='operators+') # # class Meta: # verbose_name = 'Send A Drip' #
'You can\'t highlight an event and hide it at the same time.') if self.highlighted_event and not self.display_image: raise ValidationError( 'You must provide a display image if highlighting the event.') def save(self, *args, **kwargs): """Override save to update slug.""" self.slug = slugify(self.name) if self.display_image and str(self.display_image.path) != str( self.display_image.file): self.display_image = compressors.compress_image(self.display_image) super(Event, self).save(*args, **kwargs) EventPlugin = create_plugin_base(Event) class RichText(EventPlugin): """Represents rich text fields.""" text = RichTextField(blank=True) class Meta: # noqa: D106 verbose_name = 'rich text' verbose_name_plural = 'rich texts' class Download(EventPlugin): """Represents a download field."""
def __str__(self): return self.title def get_absolute_url(self): return reverse_app((f'blog-{self.namespace.slug}', ), 'article-detail', kwargs={'slug': self.slug}, languages=[self.language_code]) class Meta: ordering = ['-publication_date'] get_latest_by = 'publication_date' PluginBase = create_plugin_base(Article) class External(feincms3_plugins.external.External, PluginBase): class Meta: verbose_name = _("external") class RichText(feincms3_plugins.richtext.RichText, PluginBase): class Meta: verbose_name = _("rich text") class Image(feincms3_plugins.image.Image, PluginBase): caption = models.CharField(_("caption"), max_length=200, blank=True) title = models.CharField(_("title"), max_length=200, blank=True)