Browse files

implemeted a few email lists for blasts such as raw query, auth_users…

… and json based; database migrations
  • Loading branch information...
1 parent 06ca83c commit a66b95076731ec7470002c4c4fbbbf21aa165643 @sherzberg sherzberg committed Jul 10, 2011
View
4 .settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,4 @@
+#Fri Jul 08 14:33:49 EDT 2011
+eclipse.preferences.version=1
+encoding//emailer/migrations/0006_setis_oneoff.py=utf-8
+encoding//emailer/migrations/0009_emaillist_prepend_name.py=utf-8
View
22 emailer/admin.py
@@ -9,7 +9,7 @@
from emailer.models import *
class EmailAdmin(admin.ModelAdmin):
- list_display = ('email_blast', 'to_address', 'status', 'opened', 'get_tracking_png_url',)
+ list_display = ('email_blast', 'to_address', 'status', 'opened', 'get_tracking_png_url', 'merge_data',)
list_filter = ('status',)
class EmailBlastAdminForm(forms.ModelForm):
@@ -20,7 +20,7 @@ class Meta:
class EmailBlastAdmin(admin.ModelAdmin):
list_display = ('name', 'send_after',)
- list_filter = ('type', 'send_after',)
+ list_filter = ('send_after',)
form = EmailBlastAdminForm
class EmailTemplateAdminForm(forms.ModelForm):
@@ -33,9 +33,25 @@ class EmailTemplateAdmin(admin.ModelAdmin):
form = EmailTemplateAdminForm
class EmailListAdmin(admin.ModelAdmin):
- list_display = ('name', 'type', 'date_created',)
+ list_display = ('name', 'type', 'date_created', 'preview_emails',)
+ list_filter = ('type', 'is_oneoff',)
+
+ def changelist_view(self, request, extra_context=None):
+ '''
+ This override, by default hides, the one off lists that are
+ generated by one off emails which are currently necessary to have
+ '''
+ if not request.GET.has_key('is_oneoff__exact'):
+
+ q = request.GET.copy()
+ q['is_oneoff__exact'] = '0'
+ request.GET = q
+ request.META['QUERY_STRING'] = request.GET.urlencode()
+ return super(EmailListAdmin,self).changelist_view(request, extra_context=extra_context)
+
admin.site.register(EmailTemplate, EmailTemplateAdmin)
admin.site.register(Email, EmailAdmin)
admin.site.register(EmailBlast, EmailBlastAdmin)
+admin.site.register(EmailList, EmailListAdmin)
#admin.site.register(EmailList)
View
0 emailer/utils/html2text.py → emailer/html2text.py
File renamed without changes.
View
2 emailer/management/commands/process_emails.py
@@ -11,7 +11,7 @@ class Command(BaseCommand):
def handle(self, *args, **options):
processor = SimpleProcessor()
-
+
processor.prepare_emails()
num_processed = processor.process_emails()
View
7 emailer/management/commands/testemail.py
@@ -9,12 +9,15 @@ class Command(BaseCommand):
help = 'Process emails with SimpleProcessor'
def handle(self, *args, **options):
-
+ class RawEmail():
+ def __init__(self, email):
+ self.email = email
+
to_address = 'spencer.herzberg@gmail.com'
from_address = 'test@gmail.com'
subject = 'one off test'
html = '<p>Hello</p>lksjdlfkdj'
- send_raw_email(to_address, from_address, subject, html)
+ send_raw_email(RawEmail(to_address), from_address, subject, html)
print 'test sent'
View
22 emailer/management/commands/testemail2.py
@@ -0,0 +1,22 @@
+
+from django.contrib.auth.models import User
+from django.core.management.base import BaseCommand
+
+from emailer.utils import send_raw_email
+
+class Command(BaseCommand):
+ args = "None"
+ help = 'Process emails with SimpleProcessor'
+
+ def handle(self, *args, **options):
+ from_address = 'test@gmail.com'
+ subject = 'one off test'
+
+ html = '<p>Hello</p>lksjdlfkdj'
+
+# u = User.objects.all()[0]:
+# if u.email != '':
+# send_raw_email(u, from_address, subject, html)
+#
+ print 'test sent'
+
View
114 emailer/migrations/0003_auto__add_field_emaillist_query_sql.py
@@ -0,0 +1,114 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding field 'EmailList.query_sql'
+ db.add_column('emailer_emaillist', 'query_sql', self.gf('django.db.models.fields.TextField')(default='', blank=True), keep_default=False)
+
+ # Adding M2M table for field site_users on 'EmailList'
+ db.create_table('emailer_emaillist_site_users', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('emaillist', models.ForeignKey(orm['emailer.emaillist'], null=False)),
+ ('user', models.ForeignKey(orm['auth.user'], null=False))
+ ))
+ db.create_unique('emailer_emaillist_site_users', ['emaillist_id', 'user_id'])
+
+
+ def backwards(self, orm):
+
+ # Deleting field 'EmailList.query_sql'
+ db.delete_column('emailer_emaillist', 'query_sql')
+
+ # Removing M2M table for field site_users on 'EmailList'
+ db.delete_table('emailer_emaillist_site_users')
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'emailer.email': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'Email'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'email_blast': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['emailer.EmailBlast']"}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'58d53282-4c8c-4ba8-82dc-2f5af1afab48'", 'max_length': '36', 'primary_key': 'True'}),
+ 'merge_data': ('django.db.models.fields.TextField', [], {}),
+ 'opened': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'status_message': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'to_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'})
+ },
+ 'emailer.emailblast': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'EmailBlast'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'from_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
+ 'html': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'fff405cf-58e6-4b01-b803-99b958076258'", 'max_length': '36', 'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40'}),
+ 'send_after': ('django.db.models.fields.DateTimeField', [], {}),
+ 'subject': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
+ 'type': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'})
+ },
+ 'emailer.emaillist': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'EmailList'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'4137e684-e415-42ec-8266-1430fd5440ab'", 'max_length': '36', 'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40'}),
+ 'query_sql': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'site_users': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.User']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'type': ('django.db.models.fields.IntegerField', [], {'default': '0'})
+ },
+ 'emailer.emailtemplate': {
+ 'Meta': {'object_name': 'EmailTemplate'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'html': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'8e6437a8-3dfd-4c14-be21-c246d71da579'", 'max_length': '36', 'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+ }
+ }
+
+ complete_apps = ['emailer']
View
104 emailer/migrations/0004_auto__add_field_emaillist_raw_emails.py
@@ -0,0 +1,104 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding field 'EmailList.raw_emails'
+ db.add_column('emailer_emaillist', 'raw_emails', self.gf('django.db.models.fields.TextField')(default='', blank=True), keep_default=False)
+
+
+ def backwards(self, orm):
+
+ # Deleting field 'EmailList.raw_emails'
+ db.delete_column('emailer_emaillist', 'raw_emails')
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'emailer.email': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'Email'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'email_blast': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['emailer.EmailBlast']"}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'f0ce614d-a4a1-46c4-b7ec-8e2108017b53'", 'max_length': '36', 'primary_key': 'True'}),
+ 'merge_data': ('django.db.models.fields.TextField', [], {}),
+ 'opened': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'status_message': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'to_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'})
+ },
+ 'emailer.emailblast': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'EmailBlast'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'from_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
+ 'html': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'7e0555b8-d9c8-49c5-9508-c2c48008f113'", 'max_length': '36', 'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40'}),
+ 'send_after': ('django.db.models.fields.DateTimeField', [], {}),
+ 'subject': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
+ 'type': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'})
+ },
+ 'emailer.emaillist': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'EmailList'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'3a66cad3-62fa-4a01-a972-7685ea658d32'", 'max_length': '36', 'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40'}),
+ 'query_sql': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'raw_emails': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'site_users': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.User']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'type': ('django.db.models.fields.IntegerField', [], {'default': '0'})
+ },
+ 'emailer.emailtemplate': {
+ 'Meta': {'object_name': 'EmailTemplate'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'html': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'854a809c-f629-45b5-8e56-4999d3584dbc'", 'max_length': '36', 'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+ }
+ }
+
+ complete_apps = ['emailer']
View
122 emailer/migrations/0005_auto__add_field_emaillist_is_oneoff__del_field_emailblast_type.py
@@ -0,0 +1,122 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding field 'EmailList.is_oneoff'
+ db.add_column('emailer_emaillist', 'is_oneoff', self.gf('django.db.models.fields.BooleanField')(default=False), keep_default=False)
+
+ # Deleting field 'EmailBlast.type'
+ db.delete_column('emailer_emailblast', 'type')
+
+ # Adding M2M table for field lists on 'EmailBlast'
+ db.create_table('emailer_emailblast_lists', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('emailblast', models.ForeignKey(orm['emailer.emailblast'], null=False)),
+ ('emaillist', models.ForeignKey(orm['emailer.emaillist'], null=False))
+ ))
+ db.create_unique('emailer_emailblast_lists', ['emailblast_id', 'emaillist_id'])
+
+
+ def backwards(self, orm):
+
+ # Deleting field 'EmailList.is_oneoff'
+ db.delete_column('emailer_emaillist', 'is_oneoff')
+
+ # Adding field 'EmailBlast.type'
+ db.add_column('emailer_emailblast', 'type', self.gf('django.db.models.fields.IntegerField')(default=0, blank=True), keep_default=False)
+
+ # Removing M2M table for field lists on 'EmailBlast'
+ db.delete_table('emailer_emailblast_lists')
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'emailer.email': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'Email'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'email_blast': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['emailer.EmailBlast']"}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'7cee9f61-a7f0-4008-ba66-2ad57b171a0f'", 'max_length': '36', 'primary_key': 'True'}),
+ 'merge_data': ('django.db.models.fields.TextField', [], {}),
+ 'opened': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'status_message': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'to_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'})
+ },
+ 'emailer.emailblast': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'EmailBlast'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'from_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
+ 'html': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'8dc62da5-be84-4af4-8dd8-a45b720e715c'", 'max_length': '36', 'primary_key': 'True'}),
+ 'lists': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['emailer.EmailList']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40'}),
+ 'send_after': ('django.db.models.fields.DateTimeField', [], {}),
+ 'subject': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+ },
+ 'emailer.emaillist': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'EmailList'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'849a99a9-d017-4f7e-a3e8-5651987fb86f'", 'max_length': '36', 'primary_key': 'True'}),
+ 'is_oneoff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40'}),
+ 'query_sql': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'raw_emails': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'site_users': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.User']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'type': ('django.db.models.fields.IntegerField', [], {'default': '0'})
+ },
+ 'emailer.emailtemplate': {
+ 'Meta': {'object_name': 'EmailTemplate'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'html': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'89d271ed-b1fb-4136-80f9-dc9b1104f2ee'", 'max_length': '36', 'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+ }
+ }
+
+ complete_apps = ['emailer']
View
104 emailer/migrations/0006_setis_oneoff.py
@@ -0,0 +1,104 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import DataMigration
+from django.db import models
+
+class Migration(DataMigration):
+
+ def forwards(self, orm):
+ for emaillist in orm.EmailList.objects.all():
+ emaillist.is_oneoff = False
+ emaillist.save()
+
+
+ def backwards(self, orm):
+ 'nothing to do here'
+ pass
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'emailer.email': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'Email'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'email_blast': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['emailer.EmailBlast']"}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'21ce6b17-29e0-4e22-aea2-9c656782db65'", 'max_length': '36', 'primary_key': 'True'}),
+ 'merge_data': ('django.db.models.fields.TextField', [], {}),
+ 'opened': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'status_message': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'to_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'})
+ },
+ 'emailer.emailblast': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'EmailBlast'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'from_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
+ 'html': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'e4506163-15fd-4da7-a6ef-30facee10f7c'", 'max_length': '36', 'primary_key': 'True'}),
+ 'lists': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['emailer.EmailList']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40'}),
+ 'send_after': ('django.db.models.fields.DateTimeField', [], {}),
+ 'subject': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+ },
+ 'emailer.emaillist': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'EmailList'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'f2bf2475-9f15-4c59-b456-d5051ed3335b'", 'max_length': '36', 'primary_key': 'True'}),
+ 'is_oneoff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40'}),
+ 'query_sql': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'raw_emails': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'site_users': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.User']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'type': ('django.db.models.fields.IntegerField', [], {'default': '0'})
+ },
+ 'emailer.emailtemplate': {
+ 'Meta': {'object_name': 'EmailTemplate'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'html': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'f024722f-f43d-4bc1-80d8-372d58680b75'", 'max_length': '36', 'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+ }
+ }
+
+ complete_apps = ['emailer']
View
145 emailer/migrations/0007_blast_rename_data_cols.py
@@ -0,0 +1,145 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Deleting field 'EmailList.query_sql'
+ db.delete_column('emailer_emaillist', 'query_sql')
+
+ # Deleting field 'EmailList.raw_emails'
+ db.delete_column('emailer_emaillist', 'raw_emails')
+
+ # Adding field 'EmailList.data_raw_emails'
+ db.add_column('emailer_emaillist', 'data_raw_emails', self.gf('django.db.models.fields.TextField')(default='', blank=True), keep_default=False)
+
+ # Adding field 'EmailList.data_query_sql'
+ db.add_column('emailer_emaillist', 'data_query_sql', self.gf('django.db.models.fields.TextField')(default='', blank=True), keep_default=False)
+
+ # Removing M2M table for field site_users on 'EmailList'
+ db.delete_table('emailer_emaillist_site_users')
+
+ # Adding M2M table for field data_site_users on 'EmailList'
+ db.create_table('emailer_emaillist_data_site_users', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('emaillist', models.ForeignKey(orm['emailer.emaillist'], null=False)),
+ ('user', models.ForeignKey(orm['auth.user'], null=False))
+ ))
+ db.create_unique('emailer_emaillist_data_site_users', ['emaillist_id', 'user_id'])
+
+
+ def backwards(self, orm):
+
+ # Adding field 'EmailList.query_sql'
+ db.add_column('emailer_emaillist', 'query_sql', self.gf('django.db.models.fields.TextField')(default='', blank=True), keep_default=False)
+
+ # Adding field 'EmailList.raw_emails'
+ db.add_column('emailer_emaillist', 'raw_emails', self.gf('django.db.models.fields.TextField')(default='', blank=True), keep_default=False)
+
+ # Deleting field 'EmailList.data_raw_emails'
+ db.delete_column('emailer_emaillist', 'data_raw_emails')
+
+ # Deleting field 'EmailList.data_query_sql'
+ db.delete_column('emailer_emaillist', 'data_query_sql')
+
+ # Adding M2M table for field site_users on 'EmailList'
+ db.create_table('emailer_emaillist_site_users', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('emaillist', models.ForeignKey(orm['emailer.emaillist'], null=False)),
+ ('user', models.ForeignKey(orm['auth.user'], null=False))
+ ))
+ db.create_unique('emailer_emaillist_site_users', ['emaillist_id', 'user_id'])
+
+ # Removing M2M table for field data_site_users on 'EmailList'
+ db.delete_table('emailer_emaillist_data_site_users')
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'emailer.email': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'Email'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'email_blast': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['emailer.EmailBlast']"}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'9a2634c8-ba4f-483d-a9ec-bd3322220533'", 'max_length': '36', 'primary_key': 'True'}),
+ 'merge_data': ('django.db.models.fields.TextField', [], {}),
+ 'opened': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'status_message': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'to_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'})
+ },
+ 'emailer.emailblast': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'EmailBlast'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'from_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
+ 'html': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'8a5d04d2-6828-49ff-b42b-59b1a8c73376'", 'max_length': '36', 'primary_key': 'True'}),
+ 'lists': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['emailer.EmailList']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40'}),
+ 'send_after': ('django.db.models.fields.DateTimeField', [], {}),
+ 'subject': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+ },
+ 'emailer.emaillist': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'EmailList'},
+ 'data_query_sql': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'data_raw_emails': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'data_site_users': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.User']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'ffe55fb4-b11a-4cd2-ac20-07b8f0c18a45'", 'max_length': '36', 'primary_key': 'True'}),
+ 'is_oneoff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40'}),
+ 'type': ('django.db.models.fields.IntegerField', [], {'default': '0'})
+ },
+ 'emailer.emailtemplate': {
+ 'Meta': {'object_name': 'EmailTemplate'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'html': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'082baf20-0196-48ce-8238-10b770d53dc0'", 'max_length': '36', 'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+ }
+ }
+
+ complete_apps = ['emailer']
View
118 ...migrations/0008_auto__add_field_emaillist_data_raw_json__chg_field_emailblast_name__de.py
@@ -0,0 +1,118 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Removing unique constraint on 'EmailBlast', fields ['name']
+ db.delete_unique('emailer_emailblast', ['name'])
+
+ # Adding field 'EmailList.data_raw_json'
+ db.add_column('emailer_emaillist', 'data_raw_json', self.gf('django.db.models.fields.TextField')(default='', blank=True), keep_default=False)
+
+ # Changing field 'EmailBlast.name'
+ db.alter_column('emailer_emailblast', 'name', self.gf('django.db.models.fields.CharField')(max_length=50))
+
+
+ def backwards(self, orm):
+
+ # Deleting field 'EmailList.data_raw_json'
+ db.delete_column('emailer_emaillist', 'data_raw_json')
+
+ # Changing field 'EmailBlast.name'
+ db.alter_column('emailer_emailblast', 'name', self.gf('django.db.models.fields.CharField')(max_length=40, unique=True))
+
+ # Adding unique constraint on 'EmailBlast', fields ['name']
+ db.create_unique('emailer_emailblast', ['name'])
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'emailer.email': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'Email'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'email_blast': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['emailer.EmailBlast']"}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'0d4687af-1aa1-40ce-8a03-6915f021602d'", 'max_length': '36', 'primary_key': 'True'}),
+ 'merge_data': ('django.db.models.fields.TextField', [], {}),
+ 'opened': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'status_message': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'to_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'})
+ },
+ 'emailer.emailblast': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'EmailBlast'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'from_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
+ 'html': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'f157bc6d-2aec-4d2e-88cd-823b7e8fd155'", 'max_length': '36', 'primary_key': 'True'}),
+ 'lists': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['emailer.EmailList']", 'symmetrical': 'False'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+ 'send_after': ('django.db.models.fields.DateTimeField', [], {}),
+ 'subject': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+ },
+ 'emailer.emaillist': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'EmailList'},
+ 'data_query_sql': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'data_raw_emails': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'data_raw_json': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'data_site_users': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.User']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'f74b3336-e630-461b-bd86-a36ad2e7f864'", 'max_length': '36', 'primary_key': 'True'}),
+ 'is_oneoff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40'}),
+ 'type': ('django.db.models.fields.IntegerField', [], {'default': '0'})
+ },
+ 'emailer.emailtemplate': {
+ 'Meta': {'object_name': 'EmailTemplate'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'html': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'63550276-c1da-41e7-bd50-3e5694d2b657'", 'max_length': '36', 'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+ }
+ }
+
+ complete_apps = ['emailer']
View
103 emailer/migrations/0009_emaillist_prepend_name.py
@@ -0,0 +1,103 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import DataMigration
+from django.db import models
+
+class Migration(DataMigration):
+
+ def forwards(self, orm):
+ for l in orm.EmailList.objects.filter(is_oneoff=True):
+ l.name = '_'+l.name
+ l.save()
+
+ def backwards(self, orm):
+ pass
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'emailer.email': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'Email'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'email_blast': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['emailer.EmailBlast']"}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'47c9b2f7-559b-4999-ad83-bd4d96284844'", 'max_length': '36', 'primary_key': 'True'}),
+ 'merge_data': ('django.db.models.fields.TextField', [], {}),
+ 'opened': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'status_message': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'to_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'})
+ },
+ 'emailer.emailblast': {
+ 'Meta': {'ordering': "['date_created']", 'object_name': 'EmailBlast'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'from_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
+ 'html': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'2601f74f-aee0-4de1-9420-78532312969f'", 'max_length': '36', 'primary_key': 'True'}),
+ 'lists': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['emailer.EmailList']", 'symmetrical': 'False'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+ 'send_after': ('django.db.models.fields.DateTimeField', [], {}),
+ 'subject': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+ },
+ 'emailer.emaillist': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'EmailList'},
+ 'data_query_sql': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'data_raw_emails': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'data_raw_json': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'data_site_users': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.User']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'82adaeaa-9319-4427-8f5a-2f9788b0f8b0'", 'max_length': '36', 'primary_key': 'True'}),
+ 'is_oneoff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40'}),
+ 'type': ('django.db.models.fields.IntegerField', [], {'default': '0'})
+ },
+ 'emailer.emailtemplate': {
+ 'Meta': {'object_name': 'EmailTemplate'},
+ 'date_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'html': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.CharField', [], {'default': "'8f47c0b4-1e4e-4a88-a8ba-9df66e3b3f0a'", 'max_length': '36', 'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+ }
+ }
+
+ complete_apps = ['emailer']
View
162 emailer/models.py
@@ -1,6 +1,14 @@
from django.db import models
-
-import uuid, datetime
+from django.contrib.auth.models import User
+from django.db import connection
+from django.core.mail import EmailMultiAlternatives
+from django.template import Context, Template
+from django.conf import settings
+
+from emailer.html2text import html2text
+from urlparse import urljoin
+
+import uuid, json
def make_uuid():
return str(uuid.uuid4())
@@ -25,59 +33,143 @@ def __unicode__(self):
@models.permalink
def get_absolute_url(self):
return ('emailer-template', (), {'template_id': self.id})
+
+#class EmailListManager(models.Manager):
+# def get_query_set(self):
+# return super(EmailListManager, self).get_query_set().filter(is_oneoff=False)
class EmailList(DefaultModel):
LISTTYPE_SITEUSERS_USERDEFINED = 0
+ LISTTYPE_QUERY_CUSTOM_SQL = 1
+ LISTTYPE_RAW_EMAILS = 2
+ LISTTYPE_RAW_JSON = 3
+
EMAIL_LIST_TYPE_CHOICES = (
(LISTTYPE_SITEUSERS_USERDEFINED,'Site Users - User Defined'),
+ (LISTTYPE_QUERY_CUSTOM_SQL, 'Custom SQL Query'),
+ (LISTTYPE_RAW_EMAILS, 'Raw Emails'),
+ (LISTTYPE_RAW_EMAILS, 'Raw JSON'),
)
+ class RawEmail():
+ def __init__(self, email):
+ self.email = email
+
name = models.CharField(blank=False, unique=True, max_length=40)
type = models.IntegerField(
blank=False,
choices=EMAIL_LIST_TYPE_CHOICES,
default=LISTTYPE_SITEUSERS_USERDEFINED
)
+ data_raw_emails = models.TextField(blank=True)
+ data_site_users = models.ManyToManyField(User, blank=True)
+ data_query_sql = models.TextField(blank=True)
+ data_raw_json = models.TextField(blank=True)
+
+ is_oneoff = models.BooleanField(default=False)
+
+# objects = EmailListManager()
+
+ def get_objects(self):
+
+ if self.type in (EmailList.LISTTYPE_SITEUSERS_USERDEFINED,):
+ return self.data_site_users.all()
- def get_users(self):
+ elif self.type in (EmailList.LISTTYPE_QUERY_CUSTOM_SQL,):
+ cursor = connection.cursor()
+ cursor.execute(self.data_query_sql)
+ rows = cursor.fetchall()
+ objs = []
+ for row in rows:#not good
+ objs.append(EmailList.RawEmail(row[0]))
+ return objs
+
+ elif self.type in (EmailList.LISTTYPE_RAW_EMAILS,):
+ return [EmailList.RawEmail(email.strip()) for email in self.data_raw_emails.split(',')]
+
+# elif self.type in (EmailList.LISTTYPE_RAW_JSON,):
+# json.loads(self.data_raw_json)
+# return []
- if self.type in (EmailList.LISTTYPE_SITEUSERS_USERDEFINED):
- return []
else:
raise NotImplementedError()
-
+
+ def preview_emails(self):
+ try:
+ objs = self.get_objects()[:3]
+ except:
+ objs = self.get_objects()
+ preview = u', '.join([obj.email for obj in objs if obj.email])
+ return preview if preview else u'(No emails found)'
+ preview_emails.short_description = 'Preview Emails'
+ preview_emails.allow_tags = True
+
class Meta:
- ordering = ['date_created']
+ ordering = ['name']
+ def save(self, *args, **kwargs):
+ if self.is_oneoff and not self.name.startswith('_'):
+ self.name = '_'+self.name
+ models.Model.save(self,*args, **kwargs)
+
+
def __unicode__(self):
return str(self.name)
-class EmailBlast(DefaultModel):
- BLASTTYPE_ONEOFF = 0
+class EmailBlast(DefaultModel):
+ name = models.CharField(blank=False, unique=False, max_length=50)
+ lists = models.ManyToManyField(EmailList)
- EMAIL_BLAST_LIST_CHOICES = (
- (BLASTTYPE_ONEOFF,'One off email'),
- )
-
- name = models.CharField(blank=False, unique=True, max_length=40)
- type = models.IntegerField(
- blank=True,
- choices=EMAIL_BLAST_LIST_CHOICES,
- default=BLASTTYPE_ONEOFF
- )
send_after = models.DateTimeField(blank=False)
from_address = models.EmailField(blank=False)
subject = models.CharField(blank=False, max_length=40)
html = models.TextField(blank=False)
-
+
+ def _is_prepared(self):
+ return len(Email.objects.filter(email_blast=self)) > 0
+ is_prepared = property(_is_prepared)
+
class Meta:
ordering = ['date_created']
def __unicode__(self):
return str(self.name)
+
+
+ def prepare_for_send(self):
+ if not self.is_prepared:
+ for list in self.lists.all():
+ for obj in list.get_objects():
+ email = Email()
+ email.email_blast = self
+ email.to_address = obj.email
+ email.merge_data = obj.__dict__
+ email.status = Email.STATUS_PREPARED
+ email.save()
+
+ def send_now(self):
+ if not self.is_prepared:
+ self.prepare_for_send()
+
+ for email in Email.objects.filter(email_blast=self):
+ email.send()
+def _append_tracking_image(html,tracking_url):
+ html = html + r'<img src="%s" alt="tracking url" />' %str(urljoin(settings.SITE_URL,tracking_url))
+ return html
+
+def _add_tracking_info(html, tracking_id, tracking_png_url):
+ tracking_html = _append_tracking_image(html, tracking_png_url)
+
+ return tracking_html
+
+def _apply_merge_data(html, merge_data):
+ t = Template(html)
+ c = Context(merge_data)
+ return t.render(c)
+
class EmailManager(models.Manager):
def email_from_tracking(self, id):
@@ -119,4 +211,32 @@ class Meta:
@models.permalink
def get_tracking_png_url(self):
return ('emailer-tracking_png', (), {'tracking_id': self.id})
-
+
+ def _build_message(self):
+ blast = self.email_blast
+
+ subject = blast.subject
+ from_email = blast.from_address
+ to = self.to_address
+
+ merged_html = _apply_merge_data(self.html, self.merge_data)
+
+ text_content = html2text(merged_html)
+ html_content = _add_tracking_info(merged_html, self.id, self.get_tracking_png_url())
+
+ msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
+ msg.attach_alternative(html_content, "text/html")
+
+ return msg
+
+ def send(self):
+ message = self._build_message()
+
+ try:
+ message.send()
+ self.status = Email.STATUS_SENT
+ except Exception, e:
+ self.status = Email.STATUS_ERRORED
+ self.status_message = str(e)
+
+ self.save()
View
98 emailer/utils/__init__.py
@@ -1,78 +1,64 @@
-from django.template import Context, Template
-from django.core.mail import EmailMultiAlternatives
-from django.conf import settings
+from emailer.models import EmailBlast, EmailList
import datetime
-from html2text import html2text
-from emailer.models import Email, EmailBlast
-from urlparse import urljoin
-def _append_tracking_image(html,tracking_url):
- html = html + '<img src="%s" alt="tracking url" />' %str(urljoin(settings.SITE_URL,tracking_url))
- return html
-def _add_tracking_info(html, tracking_id, tracking_png_url):
- tracking_html = _append_tracking_image(html, tracking_png_url)
-
- return tracking_html
-
-def _apply_merge_data(html, merge_data):
- t = Template(html)
- c = Context(merge_data)
- return t.render(c)
-
-def _build_message(email):
- subject = email.subject
- from_email = email.from_address
- to = email.to_address
-
- merged_html = _apply_merge_data(email.html,{})
-
- text_content = html2text(merged_html)
- html_content = _add_tracking_info(merged_html, email.id, email.get_tracking_png_url())
-
- msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
- msg.attach_alternative(html_content, "text/html")
+def send_raw_email(email_obj, from_address, subject, content_html, just_prepare=False):
+ '''
+ Method to generically send a raw email with merge data. Use this method in your own apps to
+ be able to track single emails. Could be for notifications or acknowledgements of events.
+ '''
- return msg
+ email_list = EmailList()
+ email_list.name = '%s - %s' %(str(datetime.datetime.now()),str(email_obj.email))
+ email_list.data_raw_emails = email_obj.email
+ email_list.is_oneoff = True
+ email_list.type = EmailList.LISTTYPE_RAW_EMAILS
+ email_list.save()
-def send_email(email):
- message = _build_message(email)
+ email_blast = EmailBlast()
+ email_blast.name = subject+ ' '+str(datetime.datetime.today().strftime("%Y-%b-%d-%m"))
+ email_blast.lists = [email_list]
+ email_blast.send_after = datetime.datetime.now()
+ email_blast.from_address = from_address
+ email_blast.subject = subject
+ email_blast.html = content_html
+ email_blast.save()
- try:
- message.send()
- email.status = Email.STATUS_SENT
- except Exception, e:
- email.status = Email.STATUS_ERRORED
- email.status_message = str(e)
+ if just_prepare:
+ status = email_blast.prepare_for_send()
+ else:
+ status = email_blast.send_now()
- email.save()
-
- return email.status
-
-def send_raw_email(to_address, from_address, subject, content_html, merge_data={}, just_prepare=False):
+ return status
+
+def send_siteusers_email(user_objs, from_address, subject, content_html, just_prepare=False):
'''
Method to generically send a raw email with merge data. Use this method in your own apps to
- be able to track emails. Could be for notifications or acknowledgements of events.
+ be able to track single emails. Could be for notifications or acknowledgements of events.
'''
+
+ email_list = EmailList()
+ email_list.name = '%s - %s' %(str(datetime.datetime.now()),str(subject))
+ email_list.data_site_users = user_objs
+ email_list.is_oneoff = True
+ email_list.type = EmailList.LISTTYPE_SITEUSERS_USERDEFINED
+ email_list.save()
+
email_blast = EmailBlast()
email_blast.name = subject+ ' '+str(datetime.datetime.today().strftime("%Y-%b-%d-%m"))
- email_blast.type = EmailBlast.BLASTTYPE_ONEOFF
+ email_blast.lists = [email_list]
email_blast.send_after = datetime.datetime.now()
email_blast.from_address = from_address
email_blast.subject = subject
email_blast.html = content_html
email_blast.save()
- email = Email()
- email.email_blast = email_blast
- email.to_address = to_address
- email.merge_data = merge_data
- email.save()
-
- if not just_prepare:
- send_email(email)
+ if just_prepare:
+ status = email_blast.prepare_for_send()
+ else:
+ status = email_blast.send_now()
- return email.status
+ return status
View
11 emailer/utils/emailprocessors.py
@@ -4,8 +4,6 @@
import datetime
from emailer.models import Email
-from emailer.utils import send_email
-
class IEmailProcessor():
@@ -17,14 +15,17 @@ def process_emails(self):
class SimpleProcessor(IEmailProcessor):
- def prepare_emails(self):
- self.emails_to_process = Email.objects.filter(status=Email.STATUS_PREPARED)
+ def prepare_emails(self, blast=None):
+ if blast:
+ self.emails_to_process = Email.objects.filter(status=Email.STATUS_PREPARED, email_blast=blast)
+ else:
+ self.emails_to_process = Email.objects.filter(status=Email.STATUS_PREPARED)
return len(self.emails_to_process)
def process_emails(self):
for email in self.emails_to_process:
- status = send_email(email)
+ status = email.send()
return len(self.emails_to_process)

0 comments on commit a66b950

Please sign in to comment.