Source code for jmb.newsletter.models

# -*- coding: utf-8 -*-
"""

"""

from datetime import datetime, date
from django.db import models
from django.db.models import Q
from django.utils.translation import ugettext as _
from django.contrib.contenttypes.models import ContentType
from django.core.validators import validate_email
from django.conf import settings
from django.core.urlresolvers import reverse

from jmb.core.db.models import DateModel, UserModel, StatusModel, OrderedModel, SEOModel
from jmb.mailer.models import EmailObject, MailingStatus
from jmb.core.db.fields import HTMLFieldTinyMCE
from jmb.mailer.utils.email_object_sender import EmailObjectSender
from jmb.newsletter.utils.tokens import tokenize


[docs]class MailingList(StatusModel, UserModel, DateModel, OrderedModel): """ Mailing list: is a list of subscribers to some newsletters. """ name = models.CharField( _("Name"), max_length=255 ) slug = models.SlugField( _("Slug"), unique=True, max_length=100, default=datetime.now ) description = models.TextField( _("Description"), blank=True, null=True )
[docs] def get_subscribers(self): """ return Active Subscribers queryset """ return self.subscribers.filter( date_unsubscription__isnull=True, status=1 )
subscribers = property(get_subscribers)
[docs] def get_test_subscribers(self): """ return Test Subscribers queryset """ return self.subscribers.filter( is_test_contact=True )
test_subscribers = property(get_test_subscribers)
[docs] def get_unsubscribers(self): """ return Unsubscribers queryset """ return self.subscribers.filter( date_unsubscription__isnull=False, )
unsubscribers = property(get_unsubscribers)
[docs] def get_subscribers_count(self): """ return number of subscribtions """ return self.subscribers.count()
total_subscribers = property(get_subscribers_count)
[docs] def get_subscribers_url(self): """ return a link to the list of mailing list subscribers """ subscribers_list_url = "%s?mailinglist=%s" % (reverse("admin:newsletter_activesubscriber_changelist"), self.id) return '<a href="%s">%s</a>' % (subscribers_list_url, self.get_subscribers_count())
get_subscribers_url.short_description = _('Subscribers') get_subscribers_url.allow_tags = True
[docs] def get_test_subscribers_count(self): """ return number of test subscribtions """ return self.test_subscribers.count()
total_test_subscribers = property(get_test_subscribers_count)
[docs] def get_test_subscribers_url(self): """ return a link to the list of mailing list subscribers of subscribtions """ test_subscribers_list_url = "%s?mailinglist=%s" % (reverse("admin:newsletter_testsubscriber_changelist"), self.id) return '<a href="%s">%s</a>' % (test_subscribers_list_url, self.get_test_subscribers_count())
get_test_subscribers_url.short_description = _('Test subscribers') get_test_subscribers_url.allow_tags = True
[docs] def get_unsubscribers_count(self): """ return number of unsubscribtions """ return self.unsubscribers.count()
total_unsubscribers = property(get_unsubscribers_count)
[docs] def get_unsubscribers_url(self): """ return a link to the list of mailing list subscribers of subscribtions """ unsubscribers_list_url = "%s?mailinglist=%s" % (reverse("admin:newsletter_unsubscriber_changelist"), self.id) return '<a href="%s">%s</a>' % (unsubscribers_list_url, self.get_unsubscribers_count())
get_unsubscribers_url.short_description = _('Unsubscribers') get_unsubscribers_url.allow_tags = True
[docs] def has_test_contact(self): """ return True or False if Test Contacts are present """ if self.test_subscribers.count() > 0: return True else: return False
has_test_contact = property(has_test_contact) def send_newsletter(self, newsletter): creation_messages = [] for subscriber in self.subscribers.all(): created, message = subscriber.send_newsletter(newsletter) creation_messages.append((created, message)) return creation_messages def send_in_test_newsletter(self, newsletter): creation_messages = [] for subscriber in self.subscribers.all(): created, message = subscriber.send_in_test_newsletter(newsletter) creation_messages.append((created, message)) return creation_messages def resend_newsletter(self, newsletter): creation_messages = [] for subscriber in self.subscribers.all(): created, message = subscriber.resend_newsletter(newsletter) creation_messages.append((created, message)) return creation_messages def resend_all_newsletter(self, newsletter): creation_messages = [] for subscriber in self.subscribers.all(): created, message = subscriber.resend_all_newsletter(newsletter) creation_messages.append((created, message)) return creation_messages
[docs] def clone(self): """ clone mailinglist without contacts """ today = datetime.today() new_obj = MailingList() new_obj.name = '%s_%s' % (self.name, today.strftime('%d-%m-%Y')) new_obj.description = self.description new_obj.save() return new_obj
def __unicode__(self): return self.name class Meta: ordering = ('-date_create',) verbose_name = _('Mailing list') verbose_name_plural = _('Mailing lists')
class ActiveSubscriberProxyManager(models.Manager): def get_query_set(self): today = date.today() return super(ActiveSubscriberProxyManager, self).get_query_set().filter( status=1, contact__status=1, date_subscription__lte=today, ).filter(Q(date_unsubscription__isnull=True) | Q(date_unsubscription__gt=today)) class TestSubscriberProxyManager(models.Manager): def get_query_set(self): today = date.today() return super(TestSubscriberProxyManager, self).get_query_set().filter( status=1, contact__status=1, is_test_contact=True, date_subscription__lte=today, ).filter(Q(date_unsubscription__isnull=True) | Q(date_unsubscription__gt=today)) class UnsubscriberProxyManager(models.Manager): def get_query_set(self): today = date.today() return super(UnsubscriberProxyManager, self).get_query_set().filter( status=1, contact__status=1, date_unsubscription__lte=today, )
[docs]class Subscriber(StatusModel, UserModel, DateModel, OrderedModel): """ Subscription to a mailing list """ objects = models.Manager() actives = ActiveSubscriberProxyManager() tests = TestSubscriberProxyManager() unsubscribed = UnsubscriberProxyManager() mailinglist = models.ForeignKey( MailingList, verbose_name=_("Mailing list"), related_name='subscribers' ) contact = models.ForeignKey( settings.NEWSLETTER_SUBSCRIBER_CONTACT_MODEL, related_name=_("Subscribers"), verbose_name=_('Contact'), ) date_subscription = models.DateTimeField( _("Date subscription"), default=datetime.today ) date_unsubscription = models.DateTimeField( _("Date unsubscription"), blank=True, null=True ) is_test_contact = models.BooleanField( _("Test"), ) @property def can_create_message(self): return True, "OK" def get_email(self): return getattr(self.contact, settings.NEWSLETTER_SUBSCRIBER_CONTACT_MODEL_EMAIL) get_email.short_description = "email" def get_default_email(self): return self.get_email() class Meta: verbose_name = _('Subscriber') verbose_name_plural = _('Subscribers') unique_together = ('mailinglist', 'contact') # @classmethod # def sottoscrittori_unici(cls): # return cls.objects.filter( # date_unsubscription__isnull=True # ).values('contact__email').distinct().count() # # @classmethod # def disiscritti_unici(cls): # return cls.objects.filter( # date_unsubscription__isnull=False # ).values('contact__email').distinct().count() def __unicode__(self): return "%s %s (%s) in mailing list %s" % ( self.contact.first_name, self.contact.last_name, self.contact.email, self.mailinglist.name, )
[docs] def get_tokens(self): """Return the uid in base 36 of a contact, and a token""" return tokenize(self)
[docs] def get_uidb36(self): """Return the uid in base 36 of a contact""" return self.get_tokens()[0]
[docs] def get_token(self): """Return a token of a contact""" return self.get_tokens()[1]
def set_subscriber_to_test(self): try: self.is_test_contact = True self.save() except Exception: return False, _('%s unsuccesfully set as test.') % self return True, _('%s succesfully set as test.') % self def link_to_mailinglist(self, mailing_list): return mailing_list.add_subscriber(self.contact)
[docs] def unsubscribe_from_mailinglist(self, mailing_list): """ Unsubscribe the subscriber from a given mailing_list :param newsletter: A newsletter instance to be sent via email :return: boolean flag of creation succesfully done, custom message """ now = datetime.now() if self.mailinglist == mailing_list: try: self.date_unsubscription = now self.save() return True, _('Subscriber %s successfully unsubscribed from %s') % self, mailing_list except Exception: return False, _('Subscriber %s successfully unsubscribed from %s') % self, mailing_list else: return False, _('Subscriber %s succesfully unsubscribed from mailing list %s') % self, mailing_list
[docs] def send_newsletter(self, newsletter): """ Prepare an email object the subscriber will receive containing newsletter only if not already sent. Email sending is made by background cron task (jmb.mailer.send_mails) :param newsletter: A newsletter instance to be sent via email :return: boolean flag of creation succesfully done, custom message """ from jmb.newsletter.utils.email_object_constructor import NewsletterEmailObjectConstructor if not self.is_active(): return False, _("Subscriber %s is not active") % self elif not self.is_contact_active(): return False, _("Subscriber %s is not active") % self elif not self.is_subscribed(): return False, _("Subscriber %s is unsubscribed") % self elif not self.is_subscriber_in_newsletter_mailing_lists(newsletter): return False, _("Subscriber %s is not in newsletter %s mailing lists") % (self, newsletter) elif not self.is_mailinglist_active(): return False, _("Mailing list %s is not active") % self.mailinglist elif not self.is_newsletter_active(newsletter): return False, _("Newsletter %s is not active") % newsletter elif self.is_newsletter_already_sent(newsletter): return False, _("Newsletter %s is already sent") % newsletter else: email_constructor = NewsletterEmailObjectConstructor(newsletter, self) mail_created, email_object, msg = email_constructor.create() return mail_created, msg
[docs] def send_in_test_newsletter(self, newsletter): """ Prepare and send an email to the subscriber containing newsletter. :param newsletter: A newsletter instance to be sent via email :return: boolean flag of creation succesfully done, custom message """ from jmb.newsletter.utils.email_object_constructor import NewsletterEmailObjectConstructor if not self.is_active(): return False, _("Subscriber is not active") elif not self.is_contact_active(): return False, _("Contact is not active") elif not self.is_subscribed(): return False, _("Contact is unsubscribed") elif not self.is_subscriber_in_newsletter_mailing_lists(newsletter): return False, _("Subscriber %s is not in newsletter %s mailing lists") % (self, newsletter) elif not self.is_mailinglist_active(): return False, _("Mailing list is not active") elif not self.is_newsletter_in_test_active(newsletter): return False, _("Newsletter is not active") elif not self.is_test_subscriber(): return False, _("Subscriber is not of test type") else: email_constructor = NewsletterEmailObjectConstructor( newsletter, self, email_object_status=settings.MAILER_EMAIL_STATUS_TO_SEND_IN_TEST ) mail_created, email_object, msg = email_constructor.create() if mail_created: email_object_sender = EmailObjectSender(email_object, is_test=True) email_object_sender.send() return mail_created, msg
[docs] def resend_newsletter(self, newsletter): """ Prepare a new email object for every subscriber has already received the email of the newsletter. Email sending is made by background cron task (jmb.mailer.send_mails) :param newsletter: A newsletter instance to be sent via email :return: boolean flag of creation succesfully done, custom message """ from jmb.newsletter.utils.email_object_constructor import NewsletterEmailObjectConstructor if not self.is_active(): return False, _("Subscriber is not active") elif not self.is_contact_active(): return False, _("Contact is not active") elif not self.is_subscribed(): return False, _("Contact is unsubscribed") elif not self.is_subscriber_in_newsletter_mailing_lists(newsletter): return False, _("Subscriber %s is not in newsletter %s mailing lists") % (self, newsletter) elif not self.is_newsletter_already_sent(newsletter): return False, _("Newsletter has never been sent") elif not self.is_mailinglist_active(): return False, _("Mailing list is not active") elif not self.is_newsletter_active(newsletter): return False, _("Newsletter is not active") else: email_constructor = NewsletterEmailObjectConstructor(newsletter, self) mail_created, email_object, msg = email_constructor.create() return mail_created, msg
[docs] def resend_all_newsletter(self, newsletter): """ Prepare a new email object for every subscriber without checking if the subscriber has already received the email. Email sending is made by background cron task (jmb.mailer.send_mails) :param newsletter: A newsletter instance to be sent via email :return: boolean flag of creation succesfully done, custom message """ from jmb.newsletter.utils.email_object_constructor import NewsletterEmailObjectConstructor if not self.is_active(): return False, _("Subscriber is not active") elif not self.is_contact_active(): return False, _("Contact is not active") elif not self.is_subscribed(): return False, _("Contact is unsubscribed") elif not self.is_subscriber_in_newsletter_mailing_lists(newsletter): return False, _("Subscriber %s is not in newsletter %s mailing lists") % (self, newsletter) elif not self.is_mailinglist_active(): return False, _("Mailing list is not active") elif not self.is_newsletter_active(newsletter): return False, _("Newsletter is not active") else: email_constructor = NewsletterEmailObjectConstructor(newsletter, self) mail_created, email_object, msg = email_constructor.create() return mail_created, msg
[docs] def is_active(self): """ Checks if subscriber is active due to its status field :return: Boolean flag """ if self.status == 1: return True return False
[docs] def is_contact_active(self): """ Checks if subscriber related contact is active due to its status field :return: Boolean flag """ if self.contact.status == 1: return True return False
[docs] def is_test_subscriber(self): """ Checks if subscriber is a test one due to its is_test_contact field :return: Boolean flag """ if self.is_test_contact: return True return False
[docs] def is_subscribed(self): """ Checks if a subscriber is subscribed from its mailing list :return: Boolean flag """ now = datetime.now() if self.date_subscription <= now: if self.date_unsubscription is None or self.date_unsubscription >= now: return True return False
[docs] def is_unsubscribed(self): """ Checks if a subscriber is unsubscribed from its mailing list :return: Boolean flag """ if self.is_subscribed(): return False return True
def is_mailinglist_active(self): if self.mailinglist.status == 1: return True return False def is_newsletter_active(self, newsletter): if newsletter.status in ( settings.NEWSLETTER_STATUS_SENDING, settings.NEWSLETTER_STATUS_WAITING ): return True return False def is_newsletter_in_test_active(self, newsletter): if newsletter.status in ( settings.NEWSLETTER_STATUS_SENDING, settings.NEWSLETTER_STATUS_WAITING, settings.NEWSLETTER_STATUS_DRAFT ): return True return False def is_newsletter_already_sent(self, newsletter): status_list = ( settings.MAILER_EMAIL_STATUS_TO_SEND, settings.MAILER_EMAIL_STATUS_SENT, ) return bool(self.newsletter_email_objects.filter(newsletter=newsletter, status__in=status_list).count()) def is_subscriber_in_newsletter_mailing_lists(self, newsletter): return self.mailinglist in newsletter.mailing_lists.filter(status=1)
[docs]class ActiveSubscriber(Subscriber): objects = ActiveSubscriberProxyManager() class Meta: proxy = True verbose_name = _('Active Subscriber') verbose_name_plural = _('Active Subscribers')
[docs]class TestSubscriber(Subscriber): objects = TestSubscriberProxyManager() class Meta: proxy = True verbose_name = _('Test Subscriber') verbose_name_plural = _('Test Subscribers')
[docs]class Unsubscriber(Subscriber): objects = UnsubscriberProxyManager() class Meta: proxy = True verbose_name = _('Unsubscriber') verbose_name_plural = _('Unsubscriber')
[docs]class Newsletter(UserModel, DateModel, OrderedModel, SEOModel): """Newsletter to be sended to subscribers""" @classmethod def get_years(cls, desc=True): output = [] newsletter_qs = Newsletter.objects.filter(status=settings.NEWSLETTER_STATUS_SENT) for d in newsletter_qs.dates('sending_date','year', order='DESC' if desc else 'ASC'): output.append((str(d.year),str(d.year))) return output @classmethod def get_months(cls): return [ ("1", _("January")), ("2", _("February")), ("3", _("March")), ("4", _("April")), ("5", _("May")), ("6", _("June")), ("7", _("July")), ("8", _("August")), ("9", _("September")), ("10", _("October")), ("11", _("November")), ("12", _("December")) ] status = models.IntegerField( _('Newsletter status'), choices= settings.NEWSLETTER_STATUS_CHOICES, default=settings.NEWSLETTER_STATUS_DRAFT ) title = models.CharField( _("Title"), max_length=255, help_text=_( "You can use the '{{ UNIQUE_KEY }}' variable for unique identifier within the newsletter's title." ) ) slug = models.SlugField( _("Slug"), help_text=_('Used for displaying the newsletter on the site.'), unique=True ) content = HTMLFieldTinyMCE( _('Content'), help_text=_('Write HTML code or paste an URL.'), ) content_web = HTMLFieldTinyMCE( _('Content WEB'), help_text=_('Write web HTML code.'), ) template = models.ForeignKey( "NewsletterTemplate", verbose_name=_("template"), ) mailing_lists = models.ManyToManyField( MailingList, related_name = 'newsletters', verbose_name=_('Mailing list') ) sending_date = models.DateTimeField( _('Sending date'), default=datetime.now )
[docs] def clone(self): """ clone Newsletter """ today = datetime.today() new_obj = Newsletter() new_obj.title = '%s_%s' % (self.title, today.strftime('%d-%m-%Y')) new_obj.slug = new_obj.title new_obj.content = self.content new_obj.mailing_list = self.mailing_list new_obj.server = self.server new_obj.header_sender = self.header_sender new_obj.header_reply= self.header_reply new_obj.save() return new_obj
[docs] def get_subscribers(self): """ return all Subscribers queryset of newsletter """ return Subscriber.objects.filter(mailinglist__newsletters=self)
subscribers = property(get_subscribers)
[docs] def get_active_subscribers(self): """ return Active Subscribers queryset of newsltter """ return ActiveSubscriber.objects.filter(mailinglist__newsletters=self)
active_subscribers = property(get_subscribers)
[docs] def get_test_subscribers(self): """ return Test Subscribers queryset of newsletter """ return TestSubscriber.objects.filter(mailinglist__newsletters=self)
test_subscribers = property(get_test_subscribers)
[docs] def get_unsubscribers(self): """ return Unsubscribers queryset of newsletter """ return Unsubscriber.objects.filter(mailinglist__newsletters=self)
unsubscribers = property(get_unsubscribers)
[docs] def get_subscribers_count(self): """ return number subscribers of newsletter """ return self.subscribers.count()
subscribers_count = property(get_subscribers_count)
[docs] def get_active_subscribers_count(self): """ return number active subscribers of newsletter """ return self.active_subscribers.count()
active_subscribers_count = property(get_active_subscribers_count)
[docs] def get_test_subscribers_count(self): """ return number test subscribers of newsletter """ return self.test_subscribers.count()
test_subscribers_count = property(get_test_subscribers_count)
[docs] def get_unsubscribers_count(self): """ return number unsubscribers of newsletter """ return self.unsubscribers.count()
unsubscribers_count = property(get_unsubscribers_count)
[docs] def get_subscribers_url(self): """ return a subscribers changelist link of newsletter """ subscribers_list_url = "%s?mailinglist__newsletters__id=%s" % ( reverse("admin:newsletter_subscriber_changelist"), self.id ) return '<a href="%s">%s</a>' % (subscribers_list_url, self.get_subscribers_count())
get_subscribers_url.short_description = _('Subscribers') get_subscribers_url.allow_tags = True
[docs] def get_active_subscribers_url(self): """ return an active subscribers changelist link of newsletter """ subscribers_list_url = "%s?mailinglist__newsletters__id=%s" % ( reverse("admin:newsletter_activesubscriber_changelist"), self.id ) return '<a href="%s">%s</a>' % (subscribers_list_url, self.get_subscribers_count())
get_active_subscribers_url.short_description = _('Active Subscribers') get_active_subscribers_url.allow_tags = True
[docs] def get_test_subscribers_url(self): """ return a test subscribers changelist link of newsletter """ test_subscribers_list_url = "%s?mailinglist__newsletters__id=%s" % ( reverse("admin:newsletter_testsubscriber_changelist"), self.id ) return '<a href="%s">%s</a>' % (test_subscribers_list_url, self.get_test_subscribers_count())
get_test_subscribers_url.short_description = _('Test subscribers') get_test_subscribers_url.allow_tags = True
[docs] def get_unsubscribers_url(self): """ return a unsubscribers changelist link of newsletter """ unsubscribers_list_url = "%s?mailinglist__newsletters__id=%s" % ( reverse("admin:newsletter_unsubscriber_changelist"), self.id ) return '<a href="%s">%s</a>' % (unsubscribers_list_url, self.get_unsubscribers_count())
get_unsubscribers_url.short_description = _('Unsubscribers') get_unsubscribers_url.allow_tags = True
[docs] def unsubscriptions_perc(self): """ return percentage of unsubscribtions """ if self.subscribers_count != 0: return float(self.unsubscribers_count) / float(self.subscribers_count) * 100 return float(0)
unsubscriptions_perc = property(unsubscriptions_perc)
[docs] def get_default_template_path(self): """ return default template path """ return self.template.file.path
[docs] def get_default_title(self): """ return default newsletter title """ return self.title
[docs] def get_list_mailinglists(self): """ return list of mailing list names """ mailinglist_list = [] for mailinglist in self.mailing_lists.all(): mailinglist_list.append(mailinglist.name) return mailinglist_list
get_list_mailinglists.short_description = _("Mailing Lists")
[docs] def get_string_mailinglists(self, separator=","): """ return a string of mailing list names separated by separator """ mailinglist_list = self.get_list_mailinglists() return separator.join(mailinglist_list)
get_string_mailinglists.short_description = _("Mailing Lists")
[docs] def get_html_mailinglists(self): """ return a html string of mailing list names separated by '<br/> """ return self.get_string_mailinglists("<br/>")
get_html_mailinglists.allow_tags = True get_html_mailinglists.short_description = _("Mailing Lists") @models.permalink
[docs] def get_absolute_url(self): """ return preview url """ return ('newsletter_newsletter_preview', (self.slug,))
@models.permalink
[docs] def get_historic_url(self): """ return historic url """ return reverse('newsletter_newsletter_historic', (self.slug,))
@models.permalink
[docs] def get_statistics_url(self): """ return statistics url """ return reverse('newsletter_newsletter_statistics', (self.slug,))
def __unicode__(self): """ return newsletter unicode """ return self.title def make_ready_to_send(self): try: self.status = settings.NEWSLETTER_STATUS_WAITING self.save() except Exception: return False, _('%s unsuccesfully set as ready to send') % self return True, _('%s succesfully set as ready to send') % self def make_cancel_sending(self): try: self.status = settings.NEWSLETTER_STATUS_CANCELED self.save() except Exception: return False, _('%s unsuccesfully set as canceled') % self return True, _('%s succesfully set as canceled') % self
[docs] def send(self, mailing_list=None): """ method to send newsletter """ creation_messages = [] if mailing_list: mailing_list_messages = mailing_list.send_newsletter(self) creation_messages.extend(mailing_list_messages) else: for mailing_list in self.mailing_lists.filter(status=1): mailing_list_messages = mailing_list.send_newsletter(self) creation_messages.extend(mailing_list_messages) return creation_messages
[docs] def send_in_test(self, mailing_list=None): """ method to send newsletter in test """ creation_messages = [] if mailing_list: mailing_list_messages = mailing_list.send_in_test_newsletter(self) creation_messages.extend(mailing_list_messages) else: for mailing_list in self.mailing_lists.filter(status=1): mailing_list_messages = mailing_list.send_in_test_newsletter(self) creation_messages.extend(mailing_list_messages) return creation_messages
def resend(self, mailing_list=None): creation_messages = [] if mailing_list: mailing_list_messages = mailing_list.resend_newsletter(self) creation_messages.extend(mailing_list_messages) else: for mailing_list in self.mailing_lists.filter(status=1): mailing_list_messages = mailing_list.resend_newsletter(self) creation_messages.extend(mailing_list_messages) return creation_messages def resend_all(self, mailing_list=None): creation_messages = [] if mailing_list: mailing_list_messages = mailing_list.resend_all_newsletter(self) creation_messages.extend(mailing_list_messages) else: for mailing_list in self.mailing_lists.filter(status=1): mailing_list_messages = mailing_list.resend_all_newsletter(self) creation_messages.extend(mailing_list_messages) return creation_messages class Meta: ordering = ('-date_create',) verbose_name = _('Newsletter') verbose_name_plural = _('Newsletters') permissions = ( ('can_change_status', 'Can change status'), ('view_newsletter', 'Can view newsletter'), )
[docs]class NewsletterEmailObject(EmailObject): newsletter = models.ForeignKey( Newsletter, verbose_name=_("Newsletter"), related_name='newsletter_email_objects', ) subscriber = models.ForeignKey( Subscriber, verbose_name=_("Subscriber"), related_name='newsletter_email_objects', )
[docs]class NewsletterTemplate(UserModel, DateModel, OrderedModel): name = models.CharField( _("Name"), unique=True, max_length=255, ) file = models.FileField( upload_to=settings.NEWSLETTER_TEMPLATE_PATH, verbose_name=_("Template"), ) class Meta: ordering = ('name',) verbose_name = _('Template') verbose_name_plural = _('Templates') def __unicode__(self): return "%s" % self.name
[docs]class Settings (DateModel, UserModel): name = models.CharField( _("Name"), max_length = 100, ) value = models.CharField( _("Value"), blank = True, null = True, max_length = 500, ) description = models.TextField( _("Description"), blank = True, null = True, ) type = models.CharField( _("Type"), max_length = 20, choices = settings.NEWSLETTER_SETTINGS_TYPE, ) class Meta: verbose_name = _("Settings") verbose_name_plural = _("Settings") def __unicode__(self): return u"%s --> %s" % (self.name, self.value)
if settings.CMS_ENABLED: import jmb.newsletter.cms.models # import jmb.newsletter.cms.app