diff --git a/esp/esp/program/controllers/confirmation.py b/esp/esp/program/controllers/confirmation.py index 4654307fa3..a9de9e64f1 100644 --- a/esp/esp/program/controllers/confirmation.py +++ b/esp/esp/program/controllers/confirmation.py @@ -37,7 +37,7 @@ from esp.users.models import ESPUser, Record from esp.program.modules.module_ext import DBReceipt -from django.template import Template +from django.template import Template, Context from django.template.loader import select_template from esp.dbmail.models import send_mail @@ -52,10 +52,12 @@ def send_confirmation_email(self, user, program, repeat=False, override=False): if (created or repeat) and (options.send_confirmation or override): try: receipt_template = Template(DBReceipt.objects.get(program=program, action='confirmemail').receipt) + receipt_text = receipt_template.render(Context({'user': user, 'program': program})) except: - receipt_template = select_template(['program/confemails/%s_confemail.txt' %(program.id),'program/confirm_email.txt']) + receipt_template = select_template(['program/confemails/%s_confemail.txt' %(program.id),'program/confemails/default.txt']) + receipt_text = receipt_template.render({'user': user, 'program': program}) send_mail("Thank you for registering for %s!" %(program.niceName()), \ - receipt_template.render({'user': user, 'program': program}), \ + receipt_text, \ (ESPUser.email_sendto_address(program.director_email, program.niceName() + " Directors")), \ [user.email], True) diff --git a/esp/esp/program/modules/forms/admincore.py b/esp/esp/program/modules/forms/admincore.py index cc1f7c9dbc..29744ffe63 100644 --- a/esp/esp/program/modules/forms/admincore.py +++ b/esp/esp/program/modules/forms/admincore.py @@ -1,6 +1,7 @@ from decimal import Decimal from django import forms from django.contrib import admin +from django.template.loader import select_template from django.utils.safestring import mark_safe from form_utils.forms import BetterForm, BetterModelForm @@ -9,7 +10,7 @@ from esp.program.controllers.lunch_constraints import LunchConstraintGenerator from esp.program.forms import ProgramCreationForm from esp.program.models import RegistrationType, Program -from esp.program.modules.module_ext import ClassRegModuleInfo, StudentClassRegModuleInfo +from esp.program.modules.module_ext import ClassRegModuleInfo, StudentClassRegModuleInfo, DBReceipt from esp.tagdict import all_program_tags, tag_categories from esp.tagdict.models import Tag @@ -111,6 +112,62 @@ class Meta: ]# Here you can also add description for each fieldset. model = StudentClassRegModuleInfo +class ReceiptsForm(BetterForm): + confirm = forms.CharField(widget=forms.Textarea(attrs={'class': 'fullwidth'}), + help_text = "This receipt is shown on the website when a student clicks the 'confirm registration' button.\ + If no text is supplied, the default text will be used.", + required = False) + confirmemail = forms.CharField(widget=forms.Textarea(attrs={'class': 'fullwidth'}), + help_text = "This receipt is sent via email when a student clicks the 'confirm registration' button.\ + If no text is supplied, the default text will be used.", + required = False) + cancel = forms.CharField(widget=forms.Textarea(attrs={'class': 'fullwidth'}), + help_text = "This receipt is shown on the website when a student clicks the 'cancel registration' button.\ + If no text is supplied, the student will be redirected to the main student registration page instead.", + required = False) + + def __init__(self, *args, **kwargs): + self.program = kwargs.pop('program') + super(ReceiptsForm, self).__init__(*args, **kwargs) + for action in ['confirm', 'confirmemail', 'cancel']: + receipts = DBReceipt.objects.filter(program=self.program, action=action) + if receipts.count() > 0: + receipt_text = receipts.latest('id').receipt + elif action == "confirm": + template = select_template(['program/receipts/%s_custom_receipt.html' %(self.program.id), 'program/receipts/default.html']) + receipt_text = open(template.origin.name, 'r').read().encode('UTF-8') + elif action == "confirmemail": + template = select_template(['program/confemails/%s_confemail.txt' %(self.program.id),'program/confemails/default.txt']) + receipt_text = open(template.origin.name, 'r').read().encode('UTF-8') + else: + receipt_text = "".encode('UTF-8') + self.fields[action].initial = receipt_text + + def save(self): + for action in ['confirm', 'confirmemail', 'cancel']: + receipts = DBReceipt.objects.filter(program=self.program, action=action) + cleaned_text = self.cleaned_data[action].replace('\r\n', '\n').strip() # Use unix line endings and strip whitespace just in case + if cleaned_text == "": + receipts.delete() + else: + if action == "confirm": + template = select_template(['program/receipts/%s_custom_receipt.html' %(self.program.id), 'program/receipts/default.html']) + default_text = open(template.origin.name, 'r').read().strip() + elif action == "confirmemail": + template = select_template(['program/confemails/%s_confemail.txt' %(self.program.id),'program/confemails/default.txt']) + default_text = open(template.origin.name, 'r').read().strip() + elif action == "cancel": + default_text = "" + if cleaned_text == default_text: + receipts.delete() + else: + receipt, created = DBReceipt.objects.get_or_create(program=self.program, action=action) + receipt.receipt = cleaned_text + receipt.save() + + class Meta: + fieldsets = [('Student Registration Receipts', {'fields': ['confirm', 'confirmemail', 'cancel']})] + class ProgramTagSettingsForm(BetterForm): """ Form for changing tags associated with a program. """ def __init__(self, *args, **kwargs): diff --git a/esp/esp/program/modules/handlers/admincore.py b/esp/esp/program/modules/handlers/admincore.py index 93d031b692..0061a60476 100644 --- a/esp/esp/program/modules/handlers/admincore.py +++ b/esp/esp/program/modules/handlers/admincore.py @@ -125,13 +125,14 @@ def main(self, request, tl, one, two, module, extra, prog): @aux_call @needs_admin def settings(self, request, tl, one, two, module, extra, prog): - from esp.program.modules.forms.admincore import ProgramSettingsForm, TeacherRegSettingsForm, StudentRegSettingsForm + from esp.program.modules.forms.admincore import ProgramSettingsForm, TeacherRegSettingsForm, StudentRegSettingsForm, ReceiptsForm context = {} submitted_form = "" crmi = ClassRegModuleInfo.objects.get(program=prog) scrmi = StudentClassRegModuleInfo.objects.get(program=prog) old_url = prog.url context['open_section'] = extra + forms = {} #If one of the forms was submitted, process it and save if valid if request.method == 'POST': @@ -143,29 +144,34 @@ def settings(self, request, tl, one, two, module, extra, prog): form.save() #If the url for the program is now different, redirect to the new settings page if prog.url is not old_url: - return HttpResponseRedirect( '/manage/%s/settings' % (prog.url)) - prog_form = form + return HttpResponseRedirect( '/manage/%s/settings/program' % (prog.url)) + else: + forms['program'] = form context['open_section'] = "program" elif submitted_form == "crmi": form = TeacherRegSettingsForm(request.POST, instance = crmi) if form.is_valid(): form.save() - crmi_form = form + else: + forms['crmi'] = form context['open_section'] = "crmi" elif submitted_form == "scrmi": form = StudentRegSettingsForm(request.POST, instance = scrmi) if form.is_valid(): form.save() - scrmi_form = form + else: + forms['scrmi'] = form context['open_section'] = "scrmi" - if form.is_valid(): - form.save() - #If the url for the program is now different, redirect to the new settings page - if prog.url is not old_url: - return HttpResponseRedirect( '/manage/%s/settings/%s' % (prog.url, context['open_section'])) + elif submitted_form == "receipts": + form = ReceiptsForm(request.POST, program = prog) + if form.is_valid(): + form.save() + else: + forms['receipts'] = form + context['open_section'] = "receipts" #Set up any other forms on the page - if submitted_form != "program": + if "program" not in forms: prog_dict = {} prog_dict.update(model_to_dict(prog)) #We need to populate all of these manually @@ -176,21 +182,25 @@ def settings(self, request, tl, one, two, module, extra, prog): line_items = pac.get_lineitemtypes(required_only=True).filter(text="Program admission").values('amount_dec') prog_dict['base_cost'] = int(sum(x["amount_dec"] for x in line_items)) prog_dict["sibling_discount"] = prog.sibling_discount - prog_form = ProgramSettingsForm(prog_dict, instance = prog) + forms['program'] = ProgramSettingsForm(prog_dict, instance = prog) + + if "crmi" not in forms: + forms['crmi'] = TeacherRegSettingsForm(instance = crmi) - if submitted_form != "crmi": - crmi_form = TeacherRegSettingsForm(instance = crmi) + if "scrmi" not in forms: + forms['scrmi'] = StudentRegSettingsForm(instance = scrmi) - if submitted_form != "scrmi": - scrmi_form = StudentRegSettingsForm(instance = scrmi) + if "receipts" not in forms: + forms['receipts'] = ReceiptsForm(program = prog) context['one'] = one context['two'] = two context['program'] = prog context['forms'] = [ - ("Program Settings", "program", prog_form), - ("Teacher Registration Settings", "crmi", crmi_form), - ("Student Registration Settings", "scrmi", scrmi_form), + ("Program Settings", "program", forms['program']), + ("Teacher Registration Settings", "crmi", forms['crmi']), + ("Student Registration Settings", "scrmi", forms['scrmi']), + ("Registration Receipts", "receipts", forms['receipts']) ] return render_to_response(self.baseDir()+'settings.html', request, context) diff --git a/esp/esp/program/modules/handlers/studentregcore.py b/esp/esp/program/modules/handlers/studentregcore.py index f03fab09d7..a430f9f83b 100644 --- a/esp/esp/program/modules/handlers/studentregcore.py +++ b/esp/esp/program/modules/handlers/studentregcore.py @@ -48,8 +48,8 @@ from datetime import datetime from django.db import models from django.contrib import admin -from django.template import Template -from esp.middleware.threadlocalrequest import AutoRequestContext as Context +from django.template import Template, Context +from esp.middleware.threadlocalrequest import AutoRequestContext from django.http import HttpResponse from django.template.loader import render_to_string, get_template, select_template import operator @@ -207,18 +207,15 @@ def confirmreg_forreal(self, request, tl, one, two, module, extra, prog, new_reg cfe = ConfirmationEmailController() cfe.send_confirmation_email(request.user, self.program) + context["request"] = request + context["program"] = prog + try: receipt_text = DBReceipt.objects.get(program=self.program, action='confirm').receipt - context["request"] = request - context["program"] = prog - return HttpResponse( Template(receipt_text).render( Context(context, autoescape=False) ) ) + return HttpResponse( Template(receipt_text).render( Context(context) ) ) except DBReceipt.DoesNotExist: - try: - receipt = 'program/receipts/'+str(prog.id)+'_custom_receipt.html' - return render_to_response(receipt, request, context) - except: - receipt = 'program/receipts/default.html' - return render_to_response(receipt, request, context) + receipt = select_template(['program/receipts/%s_custom_receipt.html' %(prog.id), 'program/receipts/default.html']) + return HttpResponse( receipt.render( AutoRequestContext(context, autoescape=False) ) ) @aux_call @needs_student @@ -252,7 +249,7 @@ def cancelreg(self, request, tl, one, two, module, extra, prog): context = {} context["request"] = request context["program"] = prog - return HttpResponse( Template(receipt_text).render( Context(context, autoescape=False) ) ) + return HttpResponse( Template(receipt_text).render( Context(context) ) ) except: return self.goToCore(tl) diff --git a/esp/esp/themes/theme_data/fruitsalad/less/main.less b/esp/esp/themes/theme_data/fruitsalad/less/main.less index 2b5c160641..4aa1517350 100644 --- a/esp/esp/themes/theme_data/fruitsalad/less/main.less +++ b/esp/esp/themes/theme_data/fruitsalad/less/main.less @@ -649,10 +649,6 @@ color: #fff; font-size: 12pt; text-decoration: none; } -.fullwidth { -width: 560px; -margin: auto; -} /* * Admin Toolbar diff --git a/esp/templates/program/confemails/41_confemail.txt b/esp/templates/program/confemails/41_confemail.txt deleted file mode 100644 index ffb2282f8e..0000000000 --- a/esp/templates/program/confemails/41_confemail.txt +++ /dev/null @@ -1,20 +0,0 @@ -Dear {{ user.first_name }}, - -Thank you for registering for Splash! This is a preliminary confirmation email for your Splash registration; you can come back and change your classes and access online payment until registration closes on November 18th. Here are some things you should know: - -1. You may notice that your schedule has no room numbers on it. The schedule you receive when you check in at Splash will have room numbers for your classes on it. - -2. When you arrive at MIT for Splash, you can pay and pick up your schedule at check-in. Starting at 8:00am on Saturday, Check-in will be in the Du Pont Gymnasium in Building W31 (http://whereis.mit.edu/?selection=W31&zoom=17). Note that this is a different location from past years; we have moved to a larger room to accommodate all of you. - -At 10:00am on Saturday, check-in will close for an hour so that we can move to Lobby 10 (http://whereis.mit.edu/?selection=10&zoom=17). Check-in will be in Lobby 10 starting from 11am and continuing through the remainder of Splash. - -3. You can pre-order t-shirts, meal tickets, or photos online. T-shirts, photos, and dinner tickets are $10; lunch tickets are $5. Please note that if you receive financial aid, you get lunch tickets for both days for free. - -4. If you have not yet paid and are not receiving financial aid, you can either pay by credit card online or at check-in by cash or check. The same goes if you want to order a t-shirt, a photo, or meal tickets. If you have paid online, you will get into a faster line for check-in. - -5. Thank you for registering! Students are the lifeblood of our program, and we're thrilled that you can join us for what looks to be the biggest Splash! yet. - -Paul Kominers -Chris Kennedy -Splash Directors - diff --git a/esp/templates/program/confemails/default.txt b/esp/templates/program/confemails/default.txt new file mode 100644 index 0000000000..205d7b11bc --- /dev/null +++ b/esp/templates/program/confemails/default.txt @@ -0,0 +1,7 @@ +Dear {{ user.first_name }}, + +Thank you for registering for {{ program.niceName }}! This is a preliminary confirmation email for your {{ program.program_type }} registration; you can come back and change your classes until registration closes. We will contact you via email with further information. + +{{ program.niceName }} Directors + + diff --git a/esp/templates/program/modules/admincore/directory.html b/esp/templates/program/modules/admincore/directory.html index 63cbfe9290..1b71e17744 100644 --- a/esp/templates/program/modules/admincore/directory.html +++ b/esp/templates/program/modules/admincore/directory.html @@ -132,7 +132,7 @@
{{ fieldset.description }}
{% endif %} -
- + |