summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-02-21 01:15:46 -0500
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-02-21 01:15:46 -0500
commiteda77cb657b96a765ce61f4f557ead618c9d8eb3 (patch)
treea35a752636405ee5fd74b259963a8d21bb986693
parentb3ba261331b553836b07ff58547833fc85767a34 (diff)
downloadaskbot-eda77cb657b96a765ce61f4f557ead618c9d8eb3.tar.gz
askbot-eda77cb657b96a765ce61f4f557ead618c9d8eb3.tar.bz2
askbot-eda77cb657b96a765ce61f4f557ead618c9d8eb3.zip
added support for the email subject line prefix
-rw-r--r--askbot/conf/email.py43
-rw-r--r--askbot/management/commands/send_email_alerts.py23
-rw-r--r--askbot/models/__init__.py5
-rw-r--r--askbot/tests/email_alert_tests.py21
-rw-r--r--askbot/utils/email.py13
-rw-r--r--askbot/utils/mail.py10
6 files changed, 82 insertions, 33 deletions
diff --git a/askbot/conf/email.py b/askbot/conf/email.py
index 77407d70..e48a74f0 100644
--- a/askbot/conf/email.py
+++ b/askbot/conf/email.py
@@ -2,18 +2,34 @@
Email related settings
"""
from askbot.conf.settings_wrapper import settings
-from askbot.deps.livesettings import ConfigurationGroup, IntegerValue, BooleanValue
-from askbot.deps.livesettings import StringValue
-from django.utils.translation import ugettext as _
+from askbot.deps import livesettings
from askbot import const
+from django.utils.translation import ugettext as _
+from django.conf import settings as django_settings
-EMAIL = ConfigurationGroup(
+EMAIL_SUBJECT_PREFIX = getattr(django_settings, 'EMAIL_SUBJECT_PREFIX', '')
+
+EMAIL = livesettings.ConfigurationGroup(
'EMAIL',
_('Email and email alert settings'),
)
settings.register(
- IntegerValue(
+ livesettings.StringValue(
+ EMAIL,
+ 'EMAIL_SUBJECT_PREFIX',
+ default = EMAIL_SUBJECT_PREFIX,
+ description = _('Prefix for the email subject line'),
+ help_text = _(
+ 'This setting takes default from the django setting'
+ 'EMAIL_SUBJECT_PREFIX. A value entered here will override'
+ 'the default.'
+ )
+ )
+)
+
+settings.register(
+ livesettings.IntegerValue(
EMAIL,
'MAX_ALERTS_PER_EMAIL',
default=7,
@@ -22,7 +38,7 @@ settings.register(
)
settings.register(
- StringValue(
+ livesettings.StringValue(
EMAIL,
'DEFAULT_NOTIFICATION_DELIVERY_SCHEDULE',
default='w',
@@ -39,7 +55,7 @@ settings.register(
)
settings.register(
- BooleanValue(
+ livesettings.BooleanValue(
EMAIL,
'EMAIL_VALIDATION',
default=False,
@@ -50,7 +66,7 @@ settings.register(
)
settings.register(
- BooleanValue(
+ livesettings.BooleanValue(
EMAIL,
'EMAIL_UNIQUE',
default=True,
@@ -59,7 +75,7 @@ settings.register(
)
settings.register(
- StringValue(
+ livesettings.StringValue(
EMAIL,
'ANONYMOUS_USER_EMAIL',
default='anonymous@askbot.org',
@@ -67,12 +83,3 @@ settings.register(
help_text=_('Use this setting to control gravatar for email-less user')
)
)
-
-settings.register(
- StringValue(
- EMAIL,
- 'EMAIL_SUBJECT_PREFIX',
- default='',
- description=_('Prefix for the email subject line'),
- )
-)
diff --git a/askbot/management/commands/send_email_alerts.py b/askbot/management/commands/send_email_alerts.py
index 48c01dab..cf4ff16a 100644
--- a/askbot/management/commands/send_email_alerts.py
+++ b/askbot/management/commands/send_email_alerts.py
@@ -7,12 +7,12 @@ from askbot.models import AnswerRevision, Activity, EmailFeedSetting
from askbot.models import Comment
from django.utils.translation import ugettext as _
from django.utils.translation import ungettext
-from django.conf import settings
+from django.conf import settings as django_settings
from askbot.conf import settings as askbot_settings
from django.utils.datastructures import SortedDict
from django.contrib.contenttypes.models import ContentType
from askbot import const
-from askbot.utils.mail import send_mail
+from askbot.utils import mail
DEBUG_THIS_COMMAND = False
@@ -98,7 +98,7 @@ def get_update_subject_line(question_dict):
question_count = len(updated_questions)
#note that double quote placement is important here
if len(tag_list) == 1:
- last_topic = ''
+ last_topic = '"'
elif len(tag_list) <= 5:
last_topic = _('" and "%s"') % tag_list.pop()
else:
@@ -115,7 +115,8 @@ def get_update_subject_line(question_dict):
'question_count': question_count,
'topics': topics
}
- return subject_line
+
+ return mail.prefix_the_subject_line(subject_line)
class Command(NoArgsCommand):
def handle_noargs(self, **options):
@@ -525,14 +526,20 @@ class Command(NoArgsCommand):
)
link = url_prefix + user.get_profile_url() + '?sort=email_subscriptions'
- text += _('go to %(email_settings_link)s to change frequency of email updates or %(admin_email)s administrator') \
- % {'email_settings_link':link, 'admin_email':settings.ADMINS[0][1]}
+ text += _(
+ 'go to %(email_settings_link)s to change '
+ 'frequency of email updates or '
+ '%(admin_email)s administrator'
+ ) % {
+ 'email_settings_link': link,
+ 'admin_email': django_settings.ADMINS[0][1]
+ }
if DEBUG_THIS_COMMAND == True:
- recipient_email = settings.ADMINS[0][1]
+ recipient_email = django_settings.ADMINS[0][1]
else:
recipient_email = user.email
- send_mail(
+ mail.send_mail(
subject_line = subject_line,
body_text = text,
recipient_list = [recipient_email]
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py
index 9dc5083f..d0b3b9fd 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -34,7 +34,7 @@ from askbot import auth
from askbot.utils.decorators import auto_now_timestamp
from askbot.utils.slug import slugify
from askbot.utils.diff import textDiff as htmldiff
-from askbot.utils.mail import send_mail
+from askbot.utils import mail
from askbot import startup_procedures
startup_procedures.run()
@@ -1839,6 +1839,7 @@ def format_instant_notification_email(
'origin_post_title': origin_post.title,
'user_subscriptions_url': user_subscriptions_url,
}
+ subject_line = mail.prefix_the_subject_line(subject_line)
return subject_line, template.render(Context(update_data))
#todo: action
@@ -1879,7 +1880,7 @@ def send_instant_notifications_about_activity_in_post(
)
#todo: this could be packaged as an "action" - a bundle
#of executive function with the activity log recording
- send_mail(
+ mail.send_mail(
subject_line = subject_line,
body_text = body_text,
recipient_list = [user.email],
diff --git a/askbot/tests/email_alert_tests.py b/askbot/tests/email_alert_tests.py
index 56142805..e8ef3ba5 100644
--- a/askbot/tests/email_alert_tests.py
+++ b/askbot/tests/email_alert_tests.py
@@ -9,7 +9,8 @@ from django.test import TestCase
from django.test.client import Client
from askbot.tests import utils
from askbot import models
-from askbot.utils.mail import mail_moderators
+from askbot.utils import mail
+from askbot.conf import settings as askbot_settings
def email_alert_test(test_func):
"""decorator for test methods in EmailAlertTests
@@ -79,6 +80,22 @@ def setup_email_alert_tests(setup_func):
test_object.setUpUsers()
return wrapped_setup
+class SubjectLineTests(TestCase):
+ """Tests for the email subject line"""
+ def test_set_prefix(self):
+ """set prefix and see if it is there
+ """
+ askbot_settings.update('EMAIL_SUBJECT_PREFIX', 'test prefix')
+ subj = mail.prefix_the_subject_line('hahah')
+ self.assertEquals(subj, 'test prefix hahah')
+
+ def test_can_disable_prefix(self):
+ """set prefix to empty string and make sure
+ that the subject line is not altered"""
+ askbot_settings.update('EMAIL_SUBJECT_PREFIX', '')
+ subj = mail.prefix_the_subject_line('hahah')
+ self.assertEquals(subj, 'hahah')
+
class EmailAlertTests(TestCase):
"""Base class for testing delayed Email notifications
that are triggered by the send_email_alerts
@@ -711,6 +728,6 @@ class FeedbackTests(utils.AskbotTestCase):
def test_mail_moderators(self):
"""tests askbot.mail_moderators()
"""
- mail_moderators('subject', 'text')
+ mail.mail_moderators('subject', 'text')
self.assert_feedback_works()
diff --git a/askbot/utils/email.py b/askbot/utils/email.py
index 8f719e82..34b11c45 100644
--- a/askbot/utils/email.py
+++ b/askbot/utils/email.py
@@ -1,11 +1,18 @@
from django.core.mail import EmailMultiAlternatives
-from django.conf import settings
+from django.conf import settings as django_settings
from django.template import loader, Context
from django.utils.html import strip_tags
from threading import Thread
-def send_email(subject, recipients, template, context={}, sender=settings.DEFAULT_FROM_EMAIL, txt_template=None):
- context['settings'] = settings
+def send_email(
+ subject,
+ recipients,
+ template,
+ context = {},
+ sender = django_settings.DEFAULT_FROM_EMAIL,
+ txt_template = None
+ ):
+ context['settings'] = django_settings
html_body = loader.get_template(template).render(Context(context))
if txt_template is None:
diff --git a/askbot/utils/mail.py b/askbot/utils/mail.py
index dee7f74b..9f88bb3c 100644
--- a/askbot/utils/mail.py
+++ b/askbot/utils/mail.py
@@ -9,6 +9,16 @@ from askbot.conf import settings as askbot_settings
from askbot import exceptions
#todo: maybe send_mail functions belong to models
#or the future API
+def prefix_the_subject_line(subject):
+ """prefixes the subject line with the
+ EMAIL_SUBJECT_LINE_PREFIX either from
+ from live settings, which take default from django
+ """
+ prefix = askbot_settings.EMAIL_SUBJECT_PREFIX.strip()
+ if prefix != '':
+ subject = prefix + ' ' + subject
+ return subject
+
def send_mail(
subject_line = None,
body_text = None,