diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-05-31 22:31:20 -0700 |
---|---|---|
committer | fadeev <fadeev@bacchus.bio.uci.edu> | 2010-05-31 22:32:25 -0700 |
commit | 5dfebd5164518572b9f1c9822990ee476854304d (patch) | |
tree | 59367e36177a8bfe58e0ff59453cb4ec1c6b334e /forum/models/__init__.py | |
parent | f5cd9612ec2d58d3f2da218a254ad011052b46ce (diff) | |
download | askbot-5dfebd5164518572b9f1c9822990ee476854304d.tar.gz askbot-5dfebd5164518572b9f1c9822990ee476854304d.tar.bz2 askbot-5dfebd5164518572b9f1c9822990ee476854304d.zip |
fixed some bugs in comment posting and made progress in instant notifications
Diffstat (limited to 'forum/models/__init__.py')
-rw-r--r-- | forum/models/__init__.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/forum/models/__init__.py b/forum/models/__init__.py index 0c0914ec..3b4fd8c0 100644 --- a/forum/models/__init__.py +++ b/forum/models/__init__.py @@ -16,6 +16,7 @@ from django.contrib.auth.models import User from django.template.defaultfilters import slugify from django.utils.safestring import mark_safe from django.db import models +from django.conf import settings as django_settings from forum import const import logging import re @@ -251,6 +252,23 @@ User.add_to_class( user_should_receive_instant_notification_about_post ) +def format_instant_notification_body(template, data): + """data has the following keys: + receiving_user: User instance + update_author: Uses instance + updated_post: post = Question|Answer|Comment instance + update_url: absolute url (including http...) of the post + revision_number: latest revision number of the post + update_type: type of update from the map in function below + related_origin_post: another post related to the updated one, if any + admin_email: email address of forum administrator + email_settings_url: full url to the page where user can change email settings + """ + #todo: write this function so that + #it can be easily used for testing of the email messages + #separately using a script + return template.render(Context(data)) + def send_instant_notifications_about_activity_in_post( activity = None, post = None, @@ -288,15 +306,15 @@ def send_instant_notifications_about_activity_in_post( 'update_type': update_type_map[activity.activity_type], 'revision_number': post.get_latest_revision_number(), 'related_origin_post': post.get_origin_post(), - 'admin_email': settings.ADMINS[0][1], + 'admin_email': django_settings.ADMINS[0][1], #todo: clean up url calculation below 'email_settings_url': base_url + u.get_profile_url() \ + '?sort=email_subscriptions' } #send update subject = _('email update message subject') - text = template.render(Context(data)) - msg = EmailMessage(subject, text, settings.DEFAULT_FROM_EMAIL, [u.email]) + text = format_instant_notification_body(template, data) + msg = EmailMessage(subject, text, django_settings.DEFAULT_FROM_EMAIL, [u.email]) print 'sending email to %s' % u.email print 'subject: %s' % subject print 'body: %s' % text |