Permalink
Browse files

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

…ibers.
  • Loading branch information...
1 parent 76093f1 commit ece8bca93e5f6a0cc948d3ad96dc81f926184605 @arneb arneb committed Feb 27, 2009
Showing with 53 additions and 12 deletions.
  1. +9 −1 README
  2. +3 −2 campaign/admin.py
  3. +23 −9 campaign/models.py
  4. +18 −0 docs/overview.txt
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
@@ -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
@@ -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
@@ -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.
+

0 comments on commit ece8bca

Please sign in to comment.