X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=portal%2Factions.py;h=c612b096290839ff26660f5eca47bd2a305d7ffd;hb=dc85c90ae585a11d616330f0180c974f5b35072d;hp=e39d48050f2d17f390fb85ac34c2f54f30757b23;hpb=a5361a5bcf8457eea5f25fed266db99a5fa7ac88;p=myslice.git diff --git a/portal/actions.py b/portal/actions.py index e39d4805..c612b096 100644 --- a/portal/actions.py +++ b/portal/actions.py @@ -6,9 +6,9 @@ import json from django.contrib.auth.models import User from django.template.loader import render_to_string -from django.core.mail import send_mail,EmailMultiAlternatives +from django.core.mail import EmailMultiAlternatives -from theme import ThemeView +from myslice.theme import ThemeView theme = ThemeView() @@ -399,25 +399,27 @@ def create_pending_slice(wsgi_request, request, email): ) s.save() - # Send an email: the recipients are the PI of the authority - recipients = authority_get_pi_emails(wsgi_request, request['authority_hrn']) - - theme.template_name = 'slice_request_email.txt' - text_content = render_to_string(theme.template, request) - - theme.template_name = 'slice_request_email.html' - html_content = render_to_string(theme.template, request) - - theme.template_name = 'slice_request_email_subject.txt' - subject = render_to_string(theme.template, request) - subject = subject.replace('\n', '') - - sender = email - msg = EmailMultiAlternatives(subject, text_content, sender, [recipients]) - print msg - msg.attach_alternative(html_content, "text/html") - msg.send() - #send_mail(subject, msg, email, recipients) + try: + # Send an email: the recipients are the PI of the authority + recipients = authority_get_pi_emails(wsgi_request, request['authority_hrn']) + + theme.template_name = 'slice_request_email.txt' + text_content = render_to_string(theme.template, request) + + theme.template_name = 'slice_request_email.html' + html_content = render_to_string(theme.template, request) + + theme.template_name = 'slice_request_email_subject.txt' + subject = render_to_string(theme.template, request) + subject = subject.replace('\n', '') + + sender = email + msg = EmailMultiAlternatives(subject, text_content, sender, [recipients]) + print msg + msg.attach_alternative(html_content, "text/html") + msg.send() + except Exception, e: + print "Failed to send email, please check the mail templates and the SMTP configuration of your server" #------------------------------------------------------------------------------- # REQUESTS - Users @@ -561,7 +563,7 @@ def create_pending_user(wsgi_request, request, user_detail): .select('platform_id') reg_platform = execute_admin_query(wsgi_request, reg_platform_query) - registry_platform_id = reg_platform[0]['platform_id'] + reg_platform_id = reg_platform[0]['platform_id'] account_params = { 'platform_id' : reg_platform_id, # XXX ALERT !! 'user_id' : user_id, @@ -572,24 +574,27 @@ def create_pending_user(wsgi_request, request, user_detail): except Exception, e: print "Failed creating manifold account on platform %s for user: %s" % ('myslice', request['email']) - # Send an email: the recipients are the PI of the authority - # If No PI is defined for this Authority, send to a default email (different for each theme) - recipients = authority_get_pi_emails(wsgi_request, request['authority_hrn']) + try: + # Send an email: the recipients are the PI of the authority + # If No PI is defined for this Authority, send to a default email (different for each theme) + recipients = authority_get_pi_emails(wsgi_request, request['authority_hrn']) + + theme.template_name = 'user_request_email.html' + html_content = render_to_string(theme.template, request) - theme.template_name = 'user_request_email.html' - html_content = render_to_string(theme.template, request) - - theme.template_name = 'user_request_email.txt' - text_content = render_to_string(theme.template, request) - - theme.template_name = 'user_request_email_subject.txt' - subject = render_to_string(theme.template, request) - subject = subject.replace('\n', '') - - theme.template_name = 'email_default_sender.txt' - sender = render_to_string(theme.template, request) - sender = sender.replace('\n', '') - - msg = EmailMultiAlternatives(subject, text_content, sender, [recipients]) - msg.attach_alternative(html_content, "text/html") - msg.send() + theme.template_name = 'user_request_email.txt' + text_content = render_to_string(theme.template, request) + + theme.template_name = 'user_request_email_subject.txt' + subject = render_to_string(theme.template, request) + subject = subject.replace('\n', '') + + theme.template_name = 'email_default_sender.txt' + sender = render_to_string(theme.template, request) + sender = sender.replace('\n', '') + + msg = EmailMultiAlternatives(subject, text_content, sender, [recipients]) + msg.attach_alternative(html_content, "text/html") + msg.send() + except Exception, e: + print "Failed to send email, please check the mail templates and the SMTP configuration of your server"