Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding subscriber lists, to manage multiple lists of different subscr…

…ibers.
  • Loading branch information...
commit ece8bca93e5f6a0cc948d3ad96dc81f926184605 1 parent 76093f1
@arneb arneb authored
View
10 README
@@ -1 +1,9 @@
-A basic newsletter app for the Django webframework.
+A basic newsletter app for the Django webframework
+--------------------------------------------------
+
+See docs/overview.txt for a brief overview.
+
+You can reach the author of django-campaign at arne _at_ rcs4u.de.
+
+Bug-reports can be filed at the google code project page:
+http://code.google.com/p/django-campaign/
View
5 campaign/admin.py
@@ -11,7 +11,7 @@
from django.utils.safestring import mark_safe
from django.utils.simplejson import simplejson as json
-from campaign.models import MailTemplate, Subscriber, Campaign, BlacklistEntry, BounceEntry
+from campaign.models import MailTemplate, Subscriber, Campaign, BlacklistEntry, BounceEntry, SubscriberList
from campaign.forms import UploadForm
@@ -188,4 +188,5 @@ def wrapper(*args, **kwargs):
admin.site.register(MailTemplate)
admin.site.register(Subscriber, SubscriberAdmin)
admin.site.register(BlacklistEntry)
-admin.site.register(BounceEntry)
+admin.site.register(BounceEntry)
+admin.site.register(SubscriberList, filter_horizontal=('subscribers',))
View
32 campaign/models.py
@@ -58,7 +58,19 @@ class Subscriber(Recipient):
"""
+
+class SubscriberList(models.Model):
+ """
+ A list of Subscriber objects.
+
+ """
+ name = models.CharField(_(u"Name"), max_length=255)
+ subscribers = models.ManyToManyField(Subscriber, null=True, verbose_name=_(u"Subscribers"))
+ def __unicode__(self):
+ return self.name
+
+
class Campaign(models.Model):
"""
A Campaign is the central part of this app. Once a Campaign is created,
@@ -71,7 +83,7 @@ class Campaign(models.Model):
"""
name = models.CharField(_(u"Name"), max_length=255)
template = models.ForeignKey(MailTemplate, verbose_name=_(u"Template"))
- recipients = models.ManyToManyField(Subscriber, verbose_name=_(u"Subscribers"))
+ recipients = models.ManyToManyField(SubscriberList, verbose_name=_(u"Subscriber lists"))
sent = models.BooleanField(_(u"sent out"), default=False, editable=False)
def __unicode__(self):
@@ -98,14 +110,16 @@ def _send(self, connection):
html_template = template.Template(self.template.html)
sent = 0
- for recipient in self.recipients.all():
- # never send mail to blacklisted email addresses
- if not BlacklistEntry.objects.filter(email=recipient.email).count():
- msg = EmailMultiAlternatives(subject, connection=connection, to=[recipient.email,])
- msg.body = text_template.render(template.Context({'salutation': recipient.salutation,}))
- html_content = html_template.render(template.Context({'salutation': recipient.salutation,}))
- msg.attach_alternative(html_content, 'text/html')
- sent += msg.send()
+ for recipient_list in self.recipients.all():
+ for recipient in recipient_list.subscribers.all():
+ # never send mail to blacklisted email addresses
+ if not BlacklistEntry.objects.filter(email=recipient.email).count():
+ msg = EmailMultiAlternatives(subject, connection=connection, to=[recipient.email,])
+ msg.body = text_template.render(template.Context({'salutation': recipient.salutation,}))
+ if self.template.html is not None and self.template.html != u"":
+ html_content = html_template.render(template.Context({'salutation': recipient.salutation,}))
+ msg.attach_alternative(html_content, 'text/html')
+ sent += msg.send()
return sent
View
18 docs/overview.txt
@@ -0,0 +1,18 @@
+============================================
+How to send Newsletters with django-campaign
+============================================
+
+Here is a very brief overview how to use django-campaign:
+
+* Import (or enter by hand) a number of subscribers into the Subscriber model.
+ Importing json formatted data is possible.
+
+* Build one or more SubscriberList objects, which hold a bunch of Subscriber
+ objects.
+
+* Create a Campaign object and the corresponding MailTemplate object.
+
+* Assign one or more SubscriberList objects as recipients to the Campaign.
+
+* Finally send the Campaign.
+
Please sign in to comment.
Something went wrong with that request. Please try again.