def evaluation_emailpreview(request, session_id): """ Preview email - including HTML body, and ability to edit email """ session = get_object_or_404(Session, id=session_id) if request.method == 'POST': app_id = [] for field in request.POST: if field[0:4] == 'app-': try: app_id.append(int(field[4:])) except: pass applications = Application.objects.filter(id__in=app_id, session=session) form = EmailForm(request.POST) if form.is_valid(): data = form.cleaned_data else: data = None return render_to_response("apply/evaluation/email_preview.html", { 'form': form, 'data': data, 'applications': applications, 'session': session }, context_instance=RequestContext(request)) else: return HttpResponseForbidden()
def evaluation_emailpreview(request, session_id): """ Preview email - including HTML body, and ability to edit email """ session = get_object_or_404(Session, id=session_id) if request.method == 'POST': app_id = [] for field in request.POST: if field[0:4] == 'app-': try: app_id.append(int(field[4:])) except: pass applications = Application.objects.filter(id__in=app_id, session=session) form = EmailForm(request.POST) if form.is_valid(): data = form.cleaned_data else: data = None return render_to_response("apply/evaluation/email_preview.html", {'form': form, 'data': data, 'applications': applications, 'session': session}, context_instance=RequestContext(request)) else: return HttpResponseForbidden()
def evaluation_emailform(request, session_id): """ Display new email form """ session = get_object_or_404(Session, id=session_id) if request.method == 'POST': app_id = [] for field in request.POST: if field[0:4] == 'app-': try: app_id.append(int(field[4:])) except: pass applications = Application.objects.filter(id__in=app_id, session=session) form = EmailForm() return render_to_response("apply/evaluation/email_compose.html", { 'form': form, 'applications': applications, 'session': session }, context_instance=RequestContext(request))
def evaluation_emailsend(request, session_id): session = get_object_or_404(Session, id=session_id) if request.method == 'POST': app_id = [] for field in request.POST: if field[0:4] == 'app-': try: app_id.append(int(field[4:])) except: pass applications = Application.objects.filter(id__in=app_id, session=session) form = EmailForm(request.POST) if form.is_valid(): # should always be true..!!! sender = '"%s" <%s>' % (form.cleaned_data['sendername'], form.cleaned_data['senderemail']) emails = [] for app in applications: emails.append(app.profile.user2.email) try: eval = app.evaluation eval.last_email = datetime.now() eval.save() except: pass send_mail(subject=form.cleaned_data['subject'], txtMessage=None, htmlMessage=form.cleaned_data['body'], fromemail=sender, recipients=emails, use_template=False) request.user.message_set.create(message="Email sent") return HttpResponseRedirect( reverse('evaluation_list', kwargs={'session_id': session.id})) else: return HttpResponseForbidden()
def evaluation_emailsend(request, session_id): session = get_object_or_404(Session, id=session_id) if request.method == 'POST': app_id = [] for field in request.POST: if field[0:4] == 'app-': try: app_id.append(int(field[4:])) except: pass applications = Application.objects.filter(id__in=app_id, session=session) form = EmailForm(request.POST) if form.is_valid(): # should always be true..!!! sender = '"%s" <%s>' % (form.cleaned_data['sendername'], form.cleaned_data['senderemail']) emails = [] for app in applications: emails.append(app.profile.user2.email) try: eval = app.evaluation eval.last_email = datetime.now() eval.save() except: pass send_mail(subject=form.cleaned_data['subject'], txtMessage=None, htmlMessage=form.cleaned_data['body'], fromemail=sender, recipients=emails, use_template=False) request.user.message_set.create(message="Email sent") return HttpResponseRedirect(reverse('evaluation_list', kwargs={'session_id': session.id})) else: return HttpResponseForbidden()