From 3b3196d4ea45a52138d911ce350a464e44f59649 Mon Sep 17 00:00:00 2001 From: Federico Justus Denkena Date: Fri, 9 Feb 2024 23:37:46 +0100 Subject: [PATCH] add admin action to resend welcome mail --- templates/{mail.html => welcome_mail.html} | 0 templates/{mail.txt => welcome_mail.txt} | 0 website/admin.py | 13 ++++++++++++- website/views.py | 6 +++--- 4 files changed, 15 insertions(+), 4 deletions(-) rename templates/{mail.html => welcome_mail.html} (100%) rename templates/{mail.txt => welcome_mail.txt} (100%) diff --git a/templates/mail.html b/templates/welcome_mail.html similarity index 100% rename from templates/mail.html rename to templates/welcome_mail.html diff --git a/templates/mail.txt b/templates/welcome_mail.txt similarity index 100% rename from templates/mail.txt rename to templates/welcome_mail.txt diff --git a/website/admin.py b/website/admin.py index 68810834..2e92707f 100644 --- a/website/admin.py +++ b/website/admin.py @@ -1,10 +1,21 @@ from django.contrib import admin from .models import Registrant, Author, Category, Post, Contact -# Register your models here. +from django.core.mail import send_mail +from django.template.loader import render_to_string + class RegistrantAdmin(admin.ModelAdmin): list_display = ('name',) readonly_fields = ['timestamp'] list_filter = ['payed', 'rate_reduced', 'canceled', 'team'] + actions = ['welcome_mail',] + + @admin.action(description='Send welcome mail again...') + def welcome_mail(self, request, queryset): + for reg in queryset: + msg_plain = render_to_string('welcome_mail.txt', {"form": reg}) + msg_html = render_to_string('welcome_mail.html', {"form": reg}) + send_mail(f'Herzlich Willkommen zur Im·Puls-Tagung, {reg.name}', msg_plain, 'buero@im-puls.org', [f"{reg.mail}"], fail_silently=False, html_message=msg_html) + send_mail(f'Neue Anmeldung: {reg.name}', msg_plain, 'buero@im-puls.org', ["webmaster@denkena-consulting.com"], fail_silently=False, html_message=msg_html) admin.site.register(Registrant, RegistrantAdmin) admin.site.register(Author) diff --git a/website/views.py b/website/views.py index 14ce642c..4f07fafc 100644 --- a/website/views.py +++ b/website/views.py @@ -90,7 +90,7 @@ def failure(request): def mail(request): #context = {"form": Registrant.objects.all()[6]} - return render(request, 'mail.html',) + return render(request, 'welcome_mail.html',) def anmeldung(request): if request.method == 'POST': @@ -100,8 +100,8 @@ def anmeldung(request): form = register_form.cleaned_data name = register_form.cleaned_data["name"] mail = register_form.cleaned_data["mail"] - msg_plain = render_to_string('mail.txt', {"form": form}) - msg_html = render_to_string('mail.html', {"form": form}) + msg_plain = render_to_string('welcome_mail.txt', {"form": form}) + msg_html = render_to_string('welcome_mail.html', {"form": form}) send_mail(f'Herzlich Willkommen zur Im·Puls-Tagung, {name}', msg_plain, 'buero@im-puls.org', ["xenia.medvedeva@posteo.de","buero@im-puls.org","webmaster@denkena-consulting.com"], fail_silently=False, html_message=msg_html) send_mail(f'Herzlich Willkommen zur Im·Puls-Tagung, {name}', msg_plain, 'buero@im-puls.org', [mail], fail_silently=False, html_message=msg_html) register_form = RegisterForm()