Commit e7b58eca authored by Samuel GAIST's avatar Samuel GAIST Committed by Andre Anjos

[ui][views] Refactor email sending using helper

parent 34f61425
Pipeline #25502 passed with stage
in 17 minutes and 37 seconds
......@@ -29,7 +29,6 @@
from django.shortcuts import get_object_or_404
from django.shortcuts import render
from django.template import loader
from django.template import Context
from django.contrib.auth.views import login as django_login
from django.contrib.auth.forms import PasswordChangeForm
from django.contrib.auth.models import User
......@@ -47,6 +46,8 @@ from rest_framework.authtoken.models import Token
from ..import __version__
from ..common.models import Shareable
from ..accounts.models import Profile, SupervisionTrack
from ..utils import mail
from .registration.forms import BlockedUserRevalidationForm
import datetime
......@@ -127,49 +128,25 @@ def blocked_user_reactivation(request):
supervisee.save()
#Inform by email the supervisor that he has a new supervisee request
from django.core.mail import send_mail
parsed_url = urlparse(settings.URL_PREFIX)
server_address = '%s://%s' % (parsed_url.scheme, parsed_url.hostname)
c = Context({ 'supervisor': supervisor,
'supervisee': supervisee,
'prefix': server_address,
})
try:
t = loader.get_template('registration/mail.supervisor_validation.subject.txt')
subject = t.render(c)
# Note: e-mail subject *must not* contain newlines
subject = settings.EMAIL_SUBJECT_PREFIX + ''.join(subject.splitlines())
t = loader.get_template('registration/mail.supervisor_validation_supervisee_add_request.message.txt')
message = t.render(c)
context = {
'supervisor': supervisor,
'supervisee': supervisee,
'prefix': server_address,
}
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [supervisor.email])
except:
pass
mail.send_email('registration/mail.supervisor_validation.subject.txt',
'registration/mail.supervisor_validation_supervisee_add_request.message.txt',
context,
[supervisor.email])
# inform the supervisee of his request
c = Context({ 'supervisor': supervisor,
'supervisee': supervisee,
'prefix': server_address,
})
try:
t = loader.get_template('registration/mail.supervisee_blocked_validation_wait.subject.txt')
subject = t.render(c)
# Note: e-mail subject *must not* contain newlines
subject = settings.EMAIL_SUBJECT_PREFIX + ''.join(subject.splitlines())
t = loader.get_template('registration/mail.supervisee_blocked_state_wait_for_activation.message.txt')
message = t.render(c)
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [supervisee.email])
except:
pass
mail.send_email('registration/mail.supervisee_blocked_validation_wait.subject.txt',
'registration/mail.supervisee_blocked_state_wait_for_activation.message.txt',
context,
[supervisee.email])
messages.success(request, "Your supervision request has been successfully processed.")
else:
......
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