def send(request): """ Send the email to the current in-cache query, and redirect out """ if request.method == 'POST': form = EmailForm(request.POST) if form.is_valid(): # should always be true..!!! sender = '"%s" <%s>' % (form.cleaned_data['sendername'], form.cleaned_data['senderemail']) terms = request.session.get('profilequery', []) recipients = build_profile_query(terms) emails = [] for r in recipients: emails.append(r.user.email) 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('profile_query')) else: return Http404()
def preview(request): """ Preview email - including HTML body, and ability to edit email """ if request.method == 'POST': form = EmailForm(request.POST) if form.is_valid(): data = form.cleaned_data else: data = None terms = request.session.get('profilequery', []) parsed_terms = [] for id, term in enumerate(terms): # parse to human-readable format parsed_terms.append(parse_profile_term(term, id)) recipients = build_profile_query(terms).count() return render_to_response("profile_query/email_preview.html", { 'form': form, 'terms': parsed_terms, 'data': data, 'recipients': recipients }, context_instance=RequestContext(request)) else: return Http404()
def preview(request): """ Preview email - including HTML body, and ability to edit email """ if request.method == 'POST': form = EmailForm(request.POST) if form.is_valid(): data = form.cleaned_data else: data = None terms = request.session.get('profilequery', []) parsed_terms = [] for id, term in enumerate(terms): # parse to human-readable format parsed_terms.append(parse_profile_term(term, id)) recipients = build_profile_query(terms).count() return render_to_response("profile_query/email_preview.html", {'form': form, 'terms': parsed_terms, 'data': data, 'recipients': recipients}, context_instance=RequestContext(request)) else: return Http404()
def download(request): terms = request.session.get('profilequery', []) if request.method == 'POST': form = CsvForm(request.POST) if form.is_valid(): # so simple a form, I don't see how you can mess it up... =) response = HttpResponse(mimetype='text/csv') response['Content-Disposition'] = 'attachment; filename=myewb-export.csv' writer = csv.writer(response) row = [] if form.cleaned_data['first_name']: row.append('First Name') if form.cleaned_data['last_name']: row.append('Last Name') if form.cleaned_data['email']: row.append('Email') if form.cleaned_data['gender']: row.append('Gender') if form.cleaned_data['language']: row.append('Language') if form.cleaned_data['date_of_birth']: row.append('Date of Birth') writer.writerow(row) profiles = build_profile_query(terms) for p in profiles: row = [] if form.cleaned_data['first_name']: row.append(p.first_name) if form.cleaned_data['last_name']: row.append(p.last_name) if form.cleaned_data['email']: row.append(p.user2.email) if form.cleaned_data['gender']: row.append(p.gender) if form.cleaned_data['language']: row.append(p.language) if form.cleaned_data['date_of_birth']: row.append(p.date_of_birth) writer.writerow(row) return response else: form = CsvForm() parsed_terms = [] for id, term in enumerate(terms): # parse to human-readable format parsed_terms.append(parse_profile_term(term, id)) return render_to_response("profile_query/export.html", {'form': form, 'terms': parsed_terms}, context_instance=RequestContext(request))