Commit 002831db authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

astakos: Move email subjects from settings to messages

Email subjects are parameterized by site name and application-
specific data. Other than that they should be constants rather
than settings.

Remove unused GROUP_CREATION_SUBJECT.
parent c161784e
......@@ -61,14 +61,6 @@ In `/etc/synnefo/astakos.conf` add:
ASTAKOS_GLOBAL_MESSAGES = []
ASTAKOS_PROFILE_EXTRA_LINKS = []
ASTAKOS_INVITATION_EMAIL_SUBJECT = 'Invitation to %s' % ASTAKOS_SITENAME
ASTAKOS_GREETING_EMAIL_SUBJECT = 'Welcome to %s' % ASTAKOS_SITENAME
ASTAKOS_FEEDBACK_EMAIL_SUBJECT = 'Feedback from %s' % ASTAKOS_SITENAME
ASTAKOS_VERIFICATION_EMAIL_SUBJECT = '%s account activation is needed' % ASTAKOS_SITENAME
ASTAKOS_ADMIN_NOTIFICATION_EMAIL_SUBJECT = '%s account created (%%(user)s)' % ASTAKOS_SITENAME
ASTAKOS_HELPDESK_NOTIFICATION_EMAIL_SUBJECT = '%s account activated (%%(user)s)' % ASTAKOS_SITENAME
ASTAKOS_EMAIL_CHANGE_EMAIL_SUBJECT = 'Email change on %s' % ASTAKOS_SITENAME
ASTAKOS_PASSWORD_RESET_EMAIL_SUBJECT = 'Password reset on %s' % ASTAKOS_SITENAME
EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'
......
......@@ -547,7 +547,7 @@ class ExtendedPasswordResetForm(PasswordResetForm):
}
message = render_to_string(email_template_name, c)
from_email = settings.SERVER_EMAIL
send_mail(_(settings.PASSWORD_RESET_EMAIL_SUBJECT),
send_mail(_(astakos_messages.PASSWORD_RESET_EMAIL_SUBJECT),
message,
from_email,
[user.email],
......
......@@ -89,7 +89,8 @@ def send_verification(user, template_name='im/activation_email.txt'):
'site_name': settings.SITENAME,
'support': settings.CONTACT_EMAIL})
sender = settings.SERVER_EMAIL
send_mail(_(settings.VERIFICATION_EMAIL_SUBJECT), message, sender, [user.email],
send_mail(_(astakos_messages.VERIFICATION_EMAIL_SUBJECT), message, sender,
[user.email],
connection=get_connection())
logger.info("Sent user verirfication email: %s", user.log_display)
......@@ -130,7 +131,8 @@ def send_account_pending_moderation_notification(
Notify admins that a new user has verified his email address and moderation
step is required to activate his account.
"""
subject = _(settings.ACCOUNT_CREATION_SUBJECT) % {'user': user.email}
subject = (_(astakos_messages.ACCOUNT_CREATION_SUBJECT) %
{'user': user.email})
return _send_admin_notification(template_name, {}, subject=subject,
user=user, msg="account creation")
......@@ -149,7 +151,8 @@ def send_account_activated_notification(
sender = settings.SERVER_EMAIL
recipient_list = [e[1] for e in settings.HELPDESK +
settings.MANAGERS + settings.ADMINS]
send_mail(_(settings.HELPDESK_NOTIFICATION_EMAIL_SUBJECT) % {'user': user.email},
send_mail(_(astakos_messages.HELPDESK_NOTIFICATION_EMAIL_SUBJECT) %
{'user': user.email},
message, sender, recipient_list, connection=get_connection())
msg = 'Sent helpdesk admin notification for %s' % user.email
logger.log(settings.LOGGING_LEVEL, msg)
......@@ -159,7 +162,7 @@ def send_invitation(invitation, template_name='im/invitation.txt'):
"""
Send invitation email.
"""
subject = _(settings.INVITATION_EMAIL_SUBJECT)
subject = _(astakos_messages.INVITATION_EMAIL_SUBJECT)
url = '%s?code=%d' % (join_urls(settings.BASEURL, reverse('index')), invitation.code)
message = render_to_string(template_name, {
'invitation': invitation,
......@@ -183,7 +186,7 @@ def send_greeting(user, email_template_name='im/welcome_email.txt'):
Raises SMTPException, socket.error
"""
subject = _(settings.GREETING_EMAIL_SUBJECT)
subject = _(astakos_messages.GREETING_EMAIL_SUBJECT)
message = render_to_string(email_template_name, {
'user': user,
'url': join_urls(settings.BASEURL, reverse('index')),
......@@ -198,7 +201,7 @@ def send_greeting(user, email_template_name='im/welcome_email.txt'):
def send_feedback(msg, data, user, email_template_name='im/feedback_mail.txt'):
subject = _(settings.FEEDBACK_EMAIL_SUBJECT)
subject = _(astakos_messages.FEEDBACK_EMAIL_SUBJECT)
from_email = settings.SERVER_EMAIL
recipient_list = [e[1] for e in settings.HELPDESK]
content = render_to_string(email_template_name, {
......@@ -219,7 +222,8 @@ def send_change_email(
'ec': ec}
message = render_to_string(email_template_name, c)
from_email = settings.SERVER_EMAIL
send_mail(_(settings.EMAIL_CHANGE_EMAIL_SUBJECT), message, from_email,
send_mail(_(astakos_messages.EMAIL_CHANGE_EMAIL_SUBJECT), message,
from_email,
[ec.new_email_address], connection=get_connection())
msg = 'Sent change email for %s' % ec.user.log_display
logger.log(settings.LOGGING_LEVEL, msg)
......
......@@ -32,6 +32,8 @@
# or implied, of GRNET S.A.
from django.conf import settings
import astakos.im.settings as astakos_settings
LOGGED_IN_WARNING = 'It seems that you are already logged in.'
ACCOUNT_ALREADY_VERIFIED = 'This account is already verified.'
......@@ -248,6 +250,37 @@ AUTH_PROVIDER_ACCOUNT_INACTIVE = 'Your account is disabled.'
AUTH_PROVIDER_ADD_TO_EXISTING_ACCOUNT = "You can add {method_prompt} to your existing account from your " \
" <a href='{profile_url}'>profile page</a>"
# Email subjects
_SITENAME = astakos_settings.SITENAME
INVITATION_EMAIL_SUBJECT = 'Invitation to %s' % _SITENAME
GREETING_EMAIL_SUBJECT = 'Welcome to %s' % _SITENAME
FEEDBACK_EMAIL_SUBJECT = 'Feedback from %s' % _SITENAME
VERIFICATION_EMAIL_SUBJECT = '%s account activation is needed' % _SITENAME
ACCOUNT_CREATION_SUBJECT = '%s account created (%%(user)s)' % _SITENAME
HELPDESK_NOTIFICATION_EMAIL_SUBJECT = \
'%s account activated (%%(user)s)' % _SITENAME
EMAIL_CHANGE_EMAIL_SUBJECT = 'Email change on %s ' % _SITENAME
PASSWORD_RESET_EMAIL_SUBJECT = 'Password reset on %s ' % _SITENAME
PROJECT_CREATION_SUBJECT = \
'%s project application created (%%(name)s)' % _SITENAME
PROJECT_APPROVED_SUBJECT = \
'%s project application approved (%%(name)s)' % _SITENAME
PROJECT_DENIED_SUBJECT = \
'%s project application denied (%%(name)s)' % _SITENAME
PROJECT_TERMINATION_SUBJECT = \
'%s project terminated (%%(name)s)' % _SITENAME
PROJECT_SUSPENSION_SUBJECT = \
'%s project suspended (%%(name)s)' % _SITENAME
PROJECT_MEMBERSHIP_CHANGE_SUBJECT = \
'%s project membership changed (%%(name)s)' % _SITENAME
PROJECT_MEMBERSHIP_ENROLL_SUBJECT = \
'%s project enrollment (%%(name)s)' % _SITENAME
PROJECT_MEMBERSHIP_REQUEST_SUBJECT = \
'%s project membership request (%%(name)s)' % _SITENAME
PROJECT_MEMBERSHIP_LEAVE_REQUEST_SUBJECT = \
'%s project membership leave request (%%(name)s)' % _SITENAME
messages = locals().keys()
for msg in messages:
if msg == msg.upper():
......
......@@ -2,16 +2,17 @@ import logging
from django.utils.translation import ugettext as _
from astakos.im import settings
from astakos.im.notifications import build_notification, NotificationError
from astakos.im import messages
logger = logging.getLogger(__name__)
MEM_CHANGE_NOTIF = {
'subject' : _(settings.PROJECT_MEMBERSHIP_CHANGE_SUBJECT),
'subject' : _(messages.PROJECT_MEMBERSHIP_CHANGE_SUBJECT),
'template': 'im/projects/project_membership_change_notification.txt',
}
MEM_ENROLL_NOTIF = {
'subject' : _(settings.PROJECT_MEMBERSHIP_ENROLL_SUBJECT),
'subject' : _(messages.PROJECT_MEMBERSHIP_ENROLL_SUBJECT),
'template': 'im/projects/project_membership_enroll_notification.txt',
}
......@@ -47,7 +48,7 @@ def membership_request_notify(project, requested_user):
notification = build_notification(
SENDER,
[project.application.owner.email],
_(settings.PROJECT_MEMBERSHIP_REQUEST_SUBJECT) % project.__dict__,
_(messages.PROJECT_MEMBERSHIP_REQUEST_SUBJECT) % project.__dict__,
template= 'im/projects/project_membership_request_notification.txt',
dictionary={'object':project, 'user':requested_user.email})
notification.send()
......@@ -59,7 +60,8 @@ def membership_leave_request_notify(project, requested_user):
notification = build_notification(
SENDER,
[project.application.owner.email],
_(settings.PROJECT_MEMBERSHIP_LEAVE_REQUEST_SUBJECT) % project.__dict__,
_(messages.PROJECT_MEMBERSHIP_LEAVE_REQUEST_SUBJECT) %
project.__dict__,
template= 'im/projects/project_membership_leave_request_notification.txt',
dictionary={'object':project, 'user':requested_user.email})
notification.send()
......@@ -70,7 +72,7 @@ def application_submit_notify(application):
try:
notification = build_notification(
SENDER, NOTIFY_RECIPIENTS,
_(settings.PROJECT_CREATION_SUBJECT) % application.__dict__,
_(messages.PROJECT_CREATION_SUBJECT) % application.__dict__,
template='im/projects/project_creation_notification.txt',
dictionary={'object':application})
notification.send()
......@@ -82,7 +84,7 @@ def application_deny_notify(application):
notification = build_notification(
SENDER,
[application.owner.email],
_(settings.PROJECT_DENIED_SUBJECT) % application.__dict__,
_(messages.PROJECT_DENIED_SUBJECT) % application.__dict__,
template='im/projects/project_denial_notification.txt',
dictionary={'object':application})
notification.send()
......@@ -94,7 +96,7 @@ def application_approve_notify(application):
notification = build_notification(
SENDER,
[application.owner.email],
_(settings.PROJECT_APPROVED_SUBJECT) % application.__dict__,
_(messages.PROJECT_APPROVED_SUBJECT) % application.__dict__,
template='im/projects/project_approval_notification.txt',
dictionary={'object':application})
notification.send()
......@@ -106,7 +108,7 @@ def project_termination_notify(project):
notification = build_notification(
SENDER,
[project.application.owner.email],
_(settings.PROJECT_TERMINATION_SUBJECT) % project.__dict__,
_(messages.PROJECT_TERMINATION_SUBJECT) % project.__dict__,
template='im/projects/project_termination_notification.txt',
dictionary={'object':project}
).send()
......@@ -118,7 +120,7 @@ def project_suspension_notify(project):
notification = build_notification(
SENDER,
[project.application.owner.email],
_(settings.PROJECT_SUSPENSION_SUBJECT) % project.__dict__,
_(messages.PROJECT_SUSPENSION_SUBJECT) % project.__dict__,
template='im/projects/project_suspension_notification.txt',
dictionary={'object':project}
).send()
......
......@@ -100,60 +100,6 @@ EMAILCHANGE_ACTIVATION_DAYS = getattr(
from logging import INFO
LOGGING_LEVEL = getattr(settings, 'ASTAKOS_LOGGING_LEVEL', INFO)
# Configurable email subjects
INVITATION_EMAIL_SUBJECT = getattr(
settings, 'ASTAKOS_INVITATION_EMAIL_SUBJECT',
'Invitation to %s' % SITENAME)
GREETING_EMAIL_SUBJECT = getattr(settings, 'ASTAKOS_GREETING_EMAIL_SUBJECT',
'Welcome to %s' % SITENAME)
FEEDBACK_EMAIL_SUBJECT = getattr(settings, 'ASTAKOS_FEEDBACK_EMAIL_SUBJECT',
'Feedback from %s' % SITENAME)
VERIFICATION_EMAIL_SUBJECT = getattr(
settings, 'ASTAKOS_VERIFICATION_EMAIL_SUBJECT',
'%s account activation is needed' % SITENAME)
ACCOUNT_CREATION_SUBJECT = getattr(
settings, 'ASTAKOS_ACCOUNT_CREATION_SUBJECT',
'%s account created (%%(user)s)' % SITENAME)
GROUP_CREATION_SUBJECT = getattr(
settings, 'ASTAKOS_GROUP_CREATION_SUBJECT',
'%s group created (%%(group)s)' % SITENAME)
HELPDESK_NOTIFICATION_EMAIL_SUBJECT = getattr(
settings, 'ASTAKOS_HELPDESK_NOTIFICATION_EMAIL_SUBJECT',
'%s account activated (%%(user)s)' % SITENAME)
EMAIL_CHANGE_EMAIL_SUBJECT = getattr(
settings, 'ASTAKOS_EMAIL_CHANGE_EMAIL_SUBJECT',
'Email change on %s ' % SITENAME)
PASSWORD_RESET_EMAIL_SUBJECT = getattr(
settings, 'ASTAKOS_PASSWORD_RESET_EMAIL_SUBJECT',
'Password reset on %s ' % SITENAME)
PROJECT_CREATION_SUBJECT = getattr(
settings, 'ASTAKOS_PROJECT_CREATION_SUBJECT',
'%s project application created (%%(name)s)' % SITENAME)
PROJECT_APPROVED_SUBJECT = getattr(
settings, 'ASTAKOS_PROJECT_APPROVED_SUBJECT',
'%s project application approved (%%(name)s)' % SITENAME)
PROJECT_DENIED_SUBJECT = getattr(
settings, 'ASTAKOS_PROJECT_DENIED_SUBJECT',
'%s project application denied (%%(name)s)' % SITENAME)
PROJECT_TERMINATION_SUBJECT = getattr(
settings, 'ASTAKOS_PROJECT_TERMINATION_SUBJECT',
'%s project terminated (%%(name)s)' % SITENAME)
PROJECT_SUSPENSION_SUBJECT = getattr(
settings, 'ASTAKOS_PROJECT_SUSPENSION_SUBJECT',
'%s testing project suspended (%%(name)s)' % SITENAME)
PROJECT_MEMBERSHIP_CHANGE_SUBJECT = getattr(
settings, 'ASTAKOS_PROJECT_MEMBERSHIP_CHANGE_SUBJECT',
'%s testing project membership changed (%%(name)s)' % SITENAME)
PROJECT_MEMBERSHIP_ENROLL_SUBJECT = getattr(
settings, 'ASTAKOS_PROJECT_MEMBERSHIP_ENROLL_SUBJECT',
'%s testing project enrollment (%%(name)s)' % SITENAME)
PROJECT_MEMBERSHIP_REQUEST_SUBJECT = getattr(
settings, 'ASTAKOS_PROJECT_MEMBERSHIP_REQUEST_SUBJECT',
'%s testing project membership request (%%(name)s)' % SITENAME)
PROJECT_MEMBERSHIP_LEAVE_REQUEST_SUBJECT = getattr(
settings, 'ASTAKOS_PROJECT_MEMBERSHIP_LEAVE_REQUEST_SUBJECT',
'%s testing project membership leave request (%%(name)s)' % SITENAME)
# Set how many objects should be displayed per page
PAGINATE_BY = getattr(settings, 'ASTAKOS_PAGINATE_BY', 8)
......
......@@ -85,23 +85,6 @@
#from logging import INFO
#ASTAKOS_LOGGING_LEVEL = INFO
# Email subjects configuration. For admin/helper notification emails %(user)s
# maps to registered/activated user email.
#ASTAKOS_INVITATION_EMAIL_SUBJECT = 'Invitation to %s' % SITENAME
#ASTAKOS_GREETING_EMAIL_SUBJECT = 'Welcome to %s' % SITENAME
#ASTAKOS_FEEDBACK_EMAIL_SUBJECT = 'Feedback from %s ' % SITENAME
#ASTAKOS_VERIFICATION_EMAIL_SUBJECT = '%s account activation is needed' % SITENAME
#ASTAKOS_ACCOUNT_CREATION_SUBJECT = '%s account created (%%(user)s)' % SITENAME)
#ASTAKOS_GROUP_CREATION_SUBJECT = '%s group created (%%(group)s)' % SITENAME)
#ASTAKOS_HELPDESK_NOTIFICATION_EMAIL_SUBJECT = '%s account activated (%%(user)s)' % SITENAME
#ASTAKOS_EMAIL_CHANGE_EMAIL_SUBJECT = 'Email change on %s ' % SITENAME
#ASTAKOS_PASSWORD_RESET_EMAIL_SUBJECT = 'Password reset on %s ' % SITENAME
#ASTAKOS_PROJECT_CREATION_SUBJECT = '%s project application created (%%(name)s)' % SITENAME
#ASTAKOS_PROJECT_APPROVED_SUBJECT = '%s project application approved (%%(name)s)' % SITENAME
#ASTAKOS_PROJECT_TERMINATION_SUBJECT = '%s project terminated (%%(name)s)' % SITENAME
#ASTAKOS_PROJECT_SUSPENSION_SUBJECT = '%s project suspended (%%(name)s)' % SITENAME
#ASTAKOS_PROJECT_MEMBERSHIP_CHANGE_SUBJECT = '%s project membership changed (%%(name)s)' % SITENAME
# Set how many objects should be displayed per page
#ASTAKOS_PAGINATE_BY = 10
# Set how many objects should be displayed per page in show all groups page
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment