diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2009-08-05 22:55:30 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2009-08-05 22:55:30 -0400 |
commit | ba4363f23c06e522cdfc2349c8b0112867247f42 (patch) | |
tree | 8ef471c33a9e2561b0dca0c5c591fe292bd55027 /forum/management | |
parent | b47e6e9c1f0ae86745376f8297e63ab775ba95fb (diff) | |
download | askbot-ba4363f23c06e522cdfc2349c8b0112867247f42.tar.gz askbot-ba4363f23c06e522cdfc2349c8b0112867247f42.tar.bz2 askbot-ba4363f23c06e522cdfc2349c8b0112867247f42.zip |
added some more files
Diffstat (limited to 'forum/management')
-rw-r--r-- | forum/management/commands/send_email_alerts.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/forum/management/commands/send_email_alerts.py b/forum/management/commands/send_email_alerts.py new file mode 100644 index 00000000..3c37aaa3 --- /dev/null +++ b/forum/management/commands/send_email_alerts.py @@ -0,0 +1,41 @@ +from django.core.management.base import NoArgsCommand +from django.db import connection +from forum.models import * +import collections +from django.core.mail import EmailMessage +from django.utils.translation import ugettext as _ +import settings + +class Command(NoArgsCommand): + def handle_noargs(self,**options): + try: + self.send_email_alerts() + except Exception, e: + print e + finally: + connection.close() + + def send_email_alerts(self): + report_time = datetime.datetime.now() + feeds = EmailFeed.objects.all() + user_ctype = ContentType.objects.get_for_model(User) + + #lists of update messages keyed by email address + update_collection = collections.defaultdict(list) + for feed in feeds: + update_summary = feed.get_update_summary() + if update_summary != None: + email = feed.get_email() + update_collection[email].append(update_summary) + feed.reported_at = report_time + feed.save() + + for email, updates in update_collection.items(): + text = '\n'.join(updates) + subject = _('updates from website') + print 'sent %s to %s' % (updates,email) + msg = EmailMessage(subject, text, settings.DEFAULT_FROM_EMAIL, [email]) + msg.content_subtype = 'html' + msg.send() + + |