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()
def authority_get_pis(request, authority_hrn):
query = Query.get('authority').filter_by('authority_hrn', '==', authority_hrn).select('pi_users')
results = execute_admin_query(request, query)
+ print "authority_get_pis = %s" % results
# NOTE: temporarily commented. Because results is giving empty list.
# Needs more debugging
#if not results:
def authority_get_pi_emails(request, authority_hrn):
pi_users = authority_get_pis(request,authority_hrn)
+ print "pi_users = %s" % pi_users
+
if any(d['pi_users'] == None for d in pi_users):
theme.template_name = 'email_default_recipients.txt'
default_email = render_to_string(theme.template, request)
)
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', '')
+ try:
+ # Send an email: the recipients are the PI of the authority
+ recipients = authority_get_pi_emails(wsgi_request, request['authority_hrn'])
- 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)
+ 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)
+ 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
.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,
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"
+ import traceback
+ traceback.print_exc()