From 6d200a668a7e544d72454909fef0687455b95239 Mon Sep 17 00:00:00 2001 From: Primal Pappachan Date: Thu, 12 Apr 2012 12:42:11 +0530 Subject: email is being sent only once --- aloha/allotter/views.py | 40 +++++++++++++++++++---------------- aloha/template/allotter/complete.html | 5 +++++ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/aloha/allotter/views.py b/aloha/allotter/views.py index 9474de3..18e3b2c 100644 --- a/aloha/allotter/views.py +++ b/aloha/allotter/views.py @@ -206,28 +206,32 @@ def complete_allotment(request): options_chosen = get_chosen_options(user) context = {'username': reg_no, 'email': sec_email, 'options_chosen': options_chosen, 'quit_status': quit_status} - ##Sending mail with allotment details - admin = User.objects.get(pk=1) - from_email = admin.email - subject = "JAM 2012 admissions" - content = "The following options were chosen by you \n \n" - if options_chosen: + ##Sending mail with allotment details + + if not quit_status: + admin = User.objects.get(pk=1) #getting admin user + from_email = admin.email + subject = "JAM 2012 admissions" + content = "The following options were chosen by you \n \n" + if options_chosen: + counter = 1 + for option in options_chosen: + content += "Preference Number: %s, Option Code: %s, Option Name: %s, Location: %s \n" % (counter, option.opt_code, option.opt_name, option.opt_location) + counter += 1 + + content += "\n \n \nPlease do not delete this email and keep it for reference purposes. \ + \n \n \n \n Regards, \n JAM Office, IIT Bombay" + send_mail(subject, content, from_email, [sec_email], fail_silently=True) + admin_content = content + admin_content +="\n\n\n#%s:" % (reg_no) counter = 1 for option in options_chosen: - content += "Preference Number: %s, Option Code: %s, Option Name: %s, Location: %s \n" %(counter, option.opt_code, option.opt_name, option.opt_location) - counter += 1 - - content += "\n \n \nPlease do not delete this email and keep it for reference purposes. \n \n \n \n Regards, \n JAM Office, IIT Bombay" - send_mail(subject, content, from_email, [sec_email], fail_silently=True) - admin_content = content - admin_content +="\n\n\n#%s:" % (reg_no) - counter = 1 - for option in options_chosen: admin_content += "%s,%s:" %(counter, option.opt_code) counter += 1 - admin_content +="#" - admin_content += time.ctime() - mail_admins(subject, admin_content, fail_silently=True) + admin_content +="#" + admin_content += time.ctime() + mail_admins(subject, admin_content, fail_silently=True) + return render(request, 'allotter/complete.html', context) diff --git a/aloha/template/allotter/complete.html b/aloha/template/allotter/complete.html index bf2306f..01c884b 100644 --- a/aloha/template/allotter/complete.html +++ b/aloha/template/allotter/complete.html @@ -45,8 +45,13 @@ and re-submit your choices. {% if email %} +{% if not quit_status %} + An email with the selected list of options has been sent to {{ email }} for reference. +{% endif %} + + {% endif %} {% else %} -- cgit