diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2014-08-21 12:36:01 +0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2014-08-21 12:36:01 +0400 |
commit | 5142e94917631315b5fe768adf9d45281991cbeb (patch) | |
tree | 32ae91d104f382f0d16f441cecdbfe3f26ef73a9 | |
parent | 081f52a73bf40a859d703e798725d8729026df30 (diff) | |
download | askbot-5142e94917631315b5fe768adf9d45281991cbeb.tar.gz askbot-5142e94917631315b5fe768adf9d45281991cbeb.tar.bz2 askbot-5142e94917631315b5fe768adf9d45281991cbeb.zip |
live settings for email messages
-rw-r--r-- | askbot/conf/__init__.py | 1 | ||||
-rw-r--r-- | askbot/conf/email_text.py | 50 | ||||
-rw-r--r-- | askbot/models/__init__.py | 1 | ||||
-rw-r--r-- | askbot/templates/email/delayed_email_alert.html | 3 | ||||
-rw-r--r-- | askbot/templates/email/footer.html | 2 | ||||
-rw-r--r-- | askbot/templates/email/welcome_lamson_off.html | 17 | ||||
-rw-r--r-- | askbot/templatetags/extra_filters_jinja.py | 18 |
7 files changed, 79 insertions, 13 deletions
diff --git a/askbot/conf/__init__.py b/askbot/conf/__init__.py index c1ed6ef0..fe19f499 100644 --- a/askbot/conf/__init__.py +++ b/askbot/conf/__init__.py @@ -6,6 +6,7 @@ import askbot.conf.vote_rules import askbot.conf.reputation_changes import askbot.conf.karma_and_badges_visibility import askbot.conf.email +import askbot.conf.email_text import askbot.conf.forum_data_rules import askbot.conf.moderation import askbot.conf.question_lists diff --git a/askbot/conf/email_text.py b/askbot/conf/email_text.py new file mode 100644 index 00000000..143dc35d --- /dev/null +++ b/askbot/conf/email_text.py @@ -0,0 +1,50 @@ +from askbot.conf.settings_wrapper import settings +from askbot.conf.super_groups import LOGIN_USERS_COMMUNICATION +from askbot.deps import livesettings +from django.utils.translation import ugettext_lazy as _ + +EMAIL_TEXT = livesettings.ConfigurationGroup( + 'EMAIL_TEXT', + _('Email template phrases'), + super_group=LOGIN_USERS_COMMUNICATION + ) + +settings.register( + livesettings.StringValue( + EMAIL_TEXT, + 'EMAIL_TEXT_SHORT_WELCOME_TO_SITE', + description = _('Short welcome message'), + default = _('Welcome to {{ SITE_NAME }}!'), + help_text = _( + '<b>NOTE: All email text settings allow placeholders: {{ USER_NAME }}, {{ SITE_NAME }} and {{ SITE_LINK }}.</b>' + ) + ) +) + +settings.register( + livesettings.LongStringValue( + EMAIL_TEXT, + 'EMAIL_TEXT_LONG_WELCOME_TO_SITE_NORESP', + description = _('Longer welcome message, not respondable'), + default = _('<p>Please visit {{ SITE_NAME }} at {{ SITE_LINK }}, we look forward to your posts.</p>'), + ) +) + +settings.register( + livesettings.LongStringValue( + EMAIL_TEXT, + 'EMAIL_TEXT_FOOTER', + description=_('Email footer'), + default=_('<p>Sincerely,<br>{{ SITE_NAME }} Administrator</p>') + ) +) + +settings.register( + livesettings.LongStringValue( + EMAIL_TEXT, + 'EMAIL_TEXT_BATCH_ALERT_HEADER', + description=_('Header for the batch email alerts'), + default=_("""<p>Dear {{ USER_NAME }},</p> +<p>{{ SITE_NAME }} has these updates, please have a look:</p>""") + ) +) diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 70c6628b..f434706d 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -3738,6 +3738,7 @@ def greet_new_user(user, **kwargs): template_name = 'email/welcome_lamson_off.html' data = { + 'recipient_user': user, 'site_name': askbot_settings.APP_SHORT_NAME, 'site_url': site_url(reverse('questions')), 'ask_address': 'ask@' + askbot_settings.REPLY_BY_EMAIL_HOSTNAME, diff --git a/askbot/templates/email/delayed_email_alert.html b/askbot/templates/email/delayed_email_alert.html index 252a2337..65fcbd67 100644 --- a/askbot/templates/email/delayed_email_alert.html +++ b/askbot/templates/email/delayed_email_alert.html @@ -1,6 +1,5 @@ {% block content %} -<p>{% trans %}Dear {{ name }},{% endtrans %}</p> -<p>{% trans %}{{ site_name }} has these updates, please have a look:{% endtrans %}</p> +{{ settings.EMAIL_TEXT_BATCH_ALERT_HEADER|sub_vars(recipient_user) }} <ul> {% for q in questions %} <li> diff --git a/askbot/templates/email/footer.html b/askbot/templates/email/footer.html index eda1269d..eb62ccc7 100644 --- a/askbot/templates/email/footer.html +++ b/askbot/templates/email/footer.html @@ -1 +1 @@ -<p>{% trans %}Sincerely,<br>{{ site_name }} Administrator{% endtrans %}</p> +{{ settings.EMAIL_TEXT_FOOTER|sub_vars(recipient_user) }} diff --git a/askbot/templates/email/welcome_lamson_off.html b/askbot/templates/email/welcome_lamson_off.html index 1be7b9a1..0b1c3e5a 100644 --- a/askbot/templates/email/welcome_lamson_off.html +++ b/askbot/templates/email/welcome_lamson_off.html @@ -3,13 +3,12 @@ {# site_name - is short name of the site, email_code - address portion of the reply email used for this message, we scan to the last appearance of the email code to detect the response signature that will appear under #} -{%block title%} {% trans %}Welcome to {{ site_name }}!{% endtrans %} {%endblock%} -{%block headline%} {% trans %}Welcome to {{ site_name }}!{% endtrans %} {%endblock%} -{%block content%} -<p> - <p>{% trans %}Please visit {{ site_name }} at <a href="{{ site_url }}">{{ site_url }}</a>, we look forward to your posts.{% endtrans %}</p> -</p> -{%endblock%} -{%block footer %} +{% set welcome_msg = settings.EMAIL_TEXT_SHORT_WELCOME_TO_SITE|sub_vars(recipient_user) %} +{% block title %}{{ welcome_msg }}{% endblock %} +{% block headline %}{% trans %}{{ welcome_msg }}{% endblock %} +{% block content %} + {{ settings.EMAIL_TEXT_LONG_WELCOME_TO_SITE_NORESP|sub_vars(recipient_user) }} +{% endblock %} +{% block footer %} {% include "email/footer.html" %} -{%endblock%} +{% endblock %} diff --git a/askbot/templatetags/extra_filters_jinja.py b/askbot/templatetags/extra_filters_jinja.py index 0d7ab0c8..7c7ffc67 100644 --- a/askbot/templatetags/extra_filters_jinja.py +++ b/askbot/templatetags/extra_filters_jinja.py @@ -18,7 +18,7 @@ from askbot import exceptions as askbot_exceptions from askbot.conf import settings as askbot_settings from django.conf import settings as django_settings from askbot.skins import utils as skin_utils -from askbot.utils.html import absolutize_urls +from askbot.utils.html import absolutize_urls, site_link from askbot.utils.html import site_url as site_url_func from askbot.utils import functions from askbot.utils import url_utils @@ -371,3 +371,19 @@ def absolute_value(number): def get_empty_search_state(unused): from askbot.search.state_manager import SearchState return SearchState.get_empty() + +@register.filter +def sub_vars(text, user=None): + """replaces placeholders {{ USER_NAME }} + {{ SITE_NAME }}, {{ SITE_LINK }} with relevant values""" + sitename_re = re.compile(r'\{\{\s*SITE_NAME\s*\}\}') + sitelink_re = re.compile(r'\{\{\s*SITE_LINK\s*\}\}') + + if user: + username_re = re.compile(r'\{\{\s*USER_NAME\s*\}\}') + text = username_re.sub(user.username, text) + + site_name = askbot_settings.APP_SHORT_NAME + text = sitename_re.sub(site_name, text) + text = sitename_re.sub(site_link('index', site_name), text) + return text |