def cancelreg(self, request, tl, one, two, module, extra, prog): self.request = request from esp.program.modules.module_ext import DBReceipt if self.have_paid(request.user): raise ESPError( False ), "You have already paid for this program! Please contact us directly (using the contact information in the footer of this page) to cancel your registration and to request a refund." recs = Record.objects.filter(user=request.user, event="reg_confirmed", program=prog) for rec in recs: rec.delete() # If the appropriate flag is set, remove the student from their classes. scrmi = prog.getModuleExtension('StudentClassRegModuleInfo') if scrmi.cancel_button_dereg: sections = request.user.getSections() for sec in sections: sec.unpreregister_student(request.user) # If a cancel receipt template is there, use it. Otherwise, return to the main studentreg page. try: receipt_text = DBReceipt.objects.get(program=self.program, action='cancel').receipt context = {} context["request"] = request context["program"] = prog return HttpResponse( Template(receipt_text).render( Context(context, autoescape=False))) except: return self.goToCore(tl)
def commprev(self, request, tl, one, two, module, extra, prog): from esp.users.models import PersistentQueryFilter from django.conf import settings filterid, listcount, subject, body = [request.POST['filterid'], request.POST['listcount'], request.POST['subject'], request.POST['body'] ] # Set From address if request.POST.has_key('from') and \ len(request.POST['from'].strip()) > 0: fromemail = request.POST['from'] else: # String together an address like [email protected] fromemail = '%s@%s' % (request.user.username, settings.SITE_INFO[1]) # Set Reply-To address if request.POST.has_key('replyto') and len(request.POST['replyto'].strip()) > 0: replytoemail = request.POST['replyto'] else: replytoemail = fromemail try: filterid = int(filterid) except: raise ESPError(), "Corrupted POST data! Please contact us at [email protected] and tell us how you got this error, and we'll look into it." userlist = PersistentQueryFilter.getFilterFromID(filterid, ESPUser).getList(ESPUser) try: firstuser = userlist[0] except: raise ESPError(), "You seem to be trying to email 0 people! Please go back, edit your search, and try again." # If they were trying to use HTML, don't sanitize the content. if '<html>' not in body: htmlbody = body.replace('<', '<').replace('>', '>').replace('\n', '<br />') else: htmlbody = body esp_firstuser = ESPUser(firstuser) contextdict = {'user' : ActionHandler(esp_firstuser, esp_firstuser), 'program': ActionHandler(self.program, esp_firstuser) } renderedtext = Template(htmlbody).render(Context(contextdict)) return render_to_response(self.baseDir()+'preview.html', request, (prog, tl), {'filterid': filterid, 'listcount': listcount, 'subject': subject, 'from': fromemail, 'replyto': replytoemail, 'body': body, 'renderedtext': renderedtext})
def alumnirsvp(request): """ This view should take the form, send an e-mail to the right people and save the data in our database. """ # If it's a success, return success page if 'success' in request.GET: return render_to_response('membership/alumniform_success.html', request, request.get_node('Q/Web/alumni'), {}) # If the form has been submitted, process it. if request.method == 'POST': data = request.POST form = AlumniRSVPForm(data, request=request) if form.is_valid(): # Save the information in the database new_rsvp = form.save() # Send an e-mail to esp-membership with details. SUBJECT_PREPEND = '[%s Alumni] RSVP From:' % settings.ORGANIZATION_SHORT_NAME to_email = [settings.DEFAULT_EMAIL_ADDRESSES['membership']] from_email = 'alumnirsvp@%s' % settings.DEFAULT_HOST t = loader.get_template('email/alumnirsvp') msgtext = t.render(Context({'form': form})) send_mail(SUBJECT_PREPEND + ' '+ form.cleaned_data['name'], msgtext, from_email, to_email, fail_silently = True) return HttpResponseRedirect(request.path + '?success=1') else: # Otherwise, the default view is a blank form. form = AlumniRSVPForm(request=request) return render_to_response('membership/alumnirsvp.html', request, request.get_node('Q/Web/alumni'), {'form': form})
def confirmreg_forreal(self, request, tl, one, two, module, extra, prog, new_reg): """ The page that is shown once the user saves their student reg, giving them the option of printing a confirmation """ self.request = request from esp.program.modules.module_ext import DBReceipt iac = IndividualAccountingController(prog, request.user) context = {} context['one'] = one context['two'] = two context['itemizedcosts'] = iac.get_transfers() user = ESPUser(request.user) context['finaid'] = user.hasFinancialAid(prog) if user.appliedFinancialAid(prog): context['finaid_app'] = user.financialaidrequest_set.filter( program=prog).order_by('-id')[0] else: context['finaid_app'] = None context['balance'] = iac.amount_due() context['owe_money'] = (context['balance'] != Decimal("0.0")) if prog.isFull() and not user.canRegToFullProgram( prog) and not self.program.isConfirmed(user): raise ESPError( log=False ), "This program has filled! It can't accept any more students. Please try again next session." modules = prog.getModules(request.user, tl) completedAll = True for module in modules: if hasattr(module, 'onConfirm'): module.onConfirm(request) if not module.isCompleted() and module.required: completedAll = False context = module.prepare(context) if completedAll: if new_reg: rec = Record.objects.create(user=user, event="reg_confirmed", program=prog) else: raise ESPError( False ), "You must finish all the necessary steps first, then click on the Save button to finish registration." cfe = ConfirmationEmailController() cfe.send_confirmation_email(request.user, self.program) 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))) 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)
def contact(request, section='esp'): """ This view should take an email and post to those people. """ from django.core.mail import send_mail if request.GET.has_key('success'): return render_to_response('contact_success.html', request, GetNode('Q/Web/about'), {}) if request.method == 'POST': form = ContactForm(request.POST) SUBJECT_PREPEND = '[webform]' domain = Site.objects.get_current().domain ok_to_send = True if form.is_valid(): to_email = [] usernames = [] if len(form.cleaned_data['sender'].strip()) == 0: email = '*****@*****.**' else: email = form.cleaned_data['sender'] usernames = ESPUser.objects.filter( email__iexact=email).values_list('username', flat=True) if usernames and not form.cleaned_data['decline_password_recovery']: m = 'password|account|log( ?)in' if re.search( m, form.cleaned_data['message'].lower()) or re.search( m, form.cleaned_data['subject'].lower()): # Ask if they want a password recovery before sending. ok_to_send = False # If they submit again, don't ask a second time. form.data = MultiValueDict(form.data) form.data['decline_password_recovery'] = True if form.cleaned_data['cc_myself']: to_email.append(email) try: to_email.append(settings.CONTACTFORM_EMAIL_ADDRESSES[ form.cleaned_data['topic'].lower()]) except KeyError: to_email.append(fallback_address) if len(form.cleaned_data['name'].strip()) > 0: email = '%s <%s>' % (form.cleaned_data['name'], email) if ok_to_send: t = loader.get_template('email/comment') msgtext = t.render( Context({ 'form': form, 'domain': domain, 'usernames': usernames })) send_mail(SUBJECT_PREPEND + ' ' + form.cleaned_data['subject'], msgtext, email, to_email, fail_silently=True) return HttpResponseRedirect(request.path + '?success') else: initial = {} if request.user.is_authenticated(): initial['sender'] = request.user.email initial[ 'name'] = request.user.first_name + ' ' + request.user.last_name if section != '': initial['topic'] = section.lower() form = ContactForm(initial=initial) return render_to_response('contact.html', request, GetNode('Q/Web/about'), {'contact_form': form})
def confirmreg_forreal(self, request, tl, one, two, module, extra, prog, new_reg): """ The page that is shown once the user saves their student reg, giving them the option of printing a confirmation """ self.request = request from esp.program.modules.module_ext import DBReceipt try: invoice = Document.get_invoice(request.user, prog.anchor, LineItemType.objects.filter(anchor=GetNode(prog.anchor.get_uri()+'/LineItemTypes/Required')), dont_duplicate=True, get_complete=True) except: invoice = Document.get_invoice(request.user, prog.anchor, LineItemType.objects.filter(anchor=GetNode(prog.anchor.get_uri()+'/LineItemTypes/Required')), dont_duplicate=True) # Why is get_complete false? receipt = Document.get_receipt(request.user, prog.anchor, [], get_complete=False) context = {} context['one'] = one context['two'] = two context['itemizedcosts'] = invoice.get_items() user = ESPUser(request.user) context['finaid'] = user.hasFinancialAid(prog.anchor) if user.appliedFinancialAid(prog): context['finaid_app'] = user.financialaidrequest_set.filter(program=prog).order_by('-id')[0] else: context['finaid_app'] = None try: context['balance'] = Decimal("%0.2f" % invoice.cost()) except EmptyTransactionException: context['balance'] = Decimal("0.0") context['owe_money'] = ( context['balance'] != Decimal("0.0") ) if prog.isFull() and not user.canRegToFullProgram(prog) and not self.program.isConfirmed(user): raise ESPError(log = False), "This program has filled! It can't accept any more students. Please try again next session." modules = prog.getModules(request.user, tl) completedAll = True for module in modules: if hasattr(module, 'onConfirm'): module.onConfirm(request) if not module.isCompleted() and module.required: completedAll = False context = module.prepare(context) if completedAll: if new_reg: bit = UserBit.objects.create(user=user, verb=GetNode("V/Flags/Public"), qsc=GetNode("/".join(prog.anchor.tree_encode()) + "/Confirmation")) else: raise ESPError(False), "You must finish all the necessary steps first, then click on the Save button to finish registration." cfe = ConfirmationEmailController() cfe.send_confirmation_email(request.user, self.program) 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) ) ) except DBReceipt.DoesNotExist: try: receipt = 'program/receipts/'+str(prog.id)+'_custom_receipt.html' return render_to_response(receipt, request, (prog, tl), context) except: receipt = 'program/receipts/default.html' return render_to_response(receipt, request, (prog, tl), context)
def send_mail(self): text = loader.get_template( "shortterm/school_response/email.txt").render( Context({'form': self})) send_mail('Survey Response: %s' % self.school, text, self.email, ["*****@*****.**"])
def alumnilookup(request): """ Provide a page where someone can look up ESP users and alumni: - search by name or year range - show stories - enter theirs or someone else's contact information """ context = {} # Usually, the default view is a blank form. context['contact_form'] = ContactInfoForm() context['lookup_form'] = AlumniLookupForm() context['info_form'] = AlumniInfoForm(request=request) # If successful, display the appropriate message from the template. if request.GET.has_key('success'): context['success'] = True # If the form has been submitted, process it. if request.method == 'POST': data = request.POST # Option 1: submitted information for someone. method = data.get('method', 'none') if method == 'submit': form1 = ContactInfoForm(data) form2 = AlumniInfoForm(data, request=request) if form2.is_valid() and form1.is_valid(): # Contact info form does additional check to see if making a new one is really necessary new_contact = form1.load_user() # Delete previous instances of this person. AlumniInfo.objects.filter(contactinfo__last_name=new_contact.last_name, contactinfo__first_name=new_contact.first_name).delete() # Save the new one into the database new_info = form2.save(commit = False) new_info.contactinfo = new_contact new_info.save() # Send an e-mail to esp-membership with details. SUBJECT_PREPEND = '[%s Alumni] Information Submitted:' % settings.ORGANIZATION_SHORT_NAME to_email = [settings.DEFAULT_EMAIL_ADDRESSES['membership']] from_email = 'alumniform@%s' % settings.DEFAULT_HOST t = loader.get_template('email/alumniinfo') msgtext = t.render(Context({'contact_form': form1, 'main_form': form2})) send_mail(SUBJECT_PREPEND + ' '+ form1.cleaned_data['first_name'] + ' ' + form1.cleaned_data['last_name'], msgtext, from_email, to_email, fail_silently = True) return HttpResponseRedirect(request.path + '?success=1') else: # Hand back the form if it has errors. context['contact_form'] = form1 context['info_form'] = form2 elif method == 'lookup': form = AlumniLookupForm(data) if form.is_valid(): # Find the user requested. alumni_list = AlumniInfo.lookup(form.cleaned_data) # Populate the context for the page with links to enter more information. context['lookup_performed'] = True context['lookup_list'] = list(alumni_list) else: # Hand back the form if it has errors. context['lookup_form'] = form return render_to_response('membership/alumnilookup.html', request, request.get_node('Q/Web/alumni'), context)