def users_admin_email_all(request): if request.method == "POST": form = EmailForm(request.POST) if form.is_valid(): all_users = MyUser.objects.filter(approved = True) recipients = [user.email for user in all_users] subject = form.cleaned_data["subject"] plain_text_content = strip_tags(form.cleaned_data["body"]) html_content = form.cleaned_data["body"] msg = EmailMultiAlternatives(subject=subject, body=plain_text_content, to=[DEFAULT_FROM_EMAIL], bcc=recipients) msg.attach_alternative(html_content, "text/html") msg.send() message = "E-mail sent." messages.add_message(request, messages.INFO, message) #return HttpResponse(str(msg.recipients())) return redirect("users_admin") return render(request, "trwibc_app/users_admin_email.html", {"form": form, "all": True,}) form = EmailForm() return render(request, "trwibc_app/users_admin_email.html", {"form": form, "all": True,})
def rsvp_admin(request, event_id): event = get_object_or_404(Event, id = event_id) yesses = RSVP.objects.filter(event = event, attending = "yes") maybes = RSVP.objects.filter(event = event, attending = "maybe") nos = RSVP.objects.filter(event = event, attending = "no") non_members = event.rsvpnonmember_set.all() if request.method == "POST": form = EmailForm(request.POST) if form.is_valid(): rsvps = list(chain(yesses, maybes)) recipients = [rsvp.person.email for rsvp in rsvps] recipients += [non_member.email for non_member in non_members] subject = form.cleaned_data["subject"] plain_text_content = strip_tags(form.cleaned_data["body"]) html_content = form.cleaned_data["body"] msg = EmailMultiAlternatives(subject=subject, body=plain_text_content, to=[DEFAULT_FROM_EMAIL], bcc=recipients) msg.attach_alternative(html_content, "text/html") msg.send() #return HttpResponse(str(msg.recipients())) message = "Email sent." messages.add_message(request, messages.INFO, message) return redirect("events_admin") return render(request, "trwibc_app/rsvp_admin.html", {"event": event, "yesses": yesses, "maybes": maybes, "nos": nos, "non_members": non_members, "form": form,}) form = EmailForm() return render(request, "trwibc_app/rsvp_admin.html", {"event": event, "yesses": yesses, "maybes": maybes, "nos": nos, "non_members": non_members, "form": form,})
def users_admin_email(request, member_id): member = get_object_or_404(MyUser, id = member_id) if request.method == "POST": form = EmailForm(request.POST) if form.is_valid(): to = member.email subject = form.cleaned_data["subject"] plain_text_content = strip_tags(form.cleaned_data["body"]) html_content = form.cleaned_data["body"] msg = EmailMultiAlternatives(subject=subject, body=plain_text_content, to=[to], cc=[DEFAULT_FROM_EMAIL]) msg.attach_alternative(html_content, "text/html") msg.send() message = "E-mail sent." messages.add_message(request, messages.INFO, message) return redirect("users_admin") return render(request, "trwibc_app/users_admin_email.html", {"form": form, "member": member,}) form = EmailForm() return render(request, "trwibc_app/users_admin_email.html", {"form": form, "member": member,})