feat: Add option to send test-html e-mail
This commit is contained in:
		@@ -119,4 +119,23 @@
 | 
			
		||||
            </button>
 | 
			
		||||
        </form>
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="block">
 | 
			
		||||
        <h2 class="title is-2">{% translate 'Testemail versenden' %}</h2>
 | 
			
		||||
        <form method="post">
 | 
			
		||||
            {% csrf_token %}
 | 
			
		||||
            <input type="hidden" name="action" value="send_test_email">
 | 
			
		||||
            <div class="field has-addons">
 | 
			
		||||
                <p class="control">
 | 
			
		||||
                    {% trans 'E-Mail Addresse an die die Test E-Mail gesendet werden soll' as target_email %}
 | 
			
		||||
                    <label hidden="hidden" aria-hidden="false" for="test_email_address">{{ target_email }}</label>
 | 
			
		||||
                    <input class="input" id="test_email_address" name="test_email_address" type="text" placeholder="me@example.org">
 | 
			
		||||
                </p>
 | 
			
		||||
                <p class="control">
 | 
			
		||||
                    <button type="submit" class="button is-primary">
 | 
			
		||||
                        {% translate 'E-Mail senden testen' %}
 | 
			
		||||
                    </button>
 | 
			
		||||
                </p>
 | 
			
		||||
            </div>
 | 
			
		||||
        </form>
 | 
			
		||||
    </div>
 | 
			
		||||
{% endblock content %}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,76 @@
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html lang="{{ LANGUAGE_CODE }}">
 | 
			
		||||
<head>
 | 
			
		||||
    <meta charset="UTF-8"/>
 | 
			
		||||
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
 | 
			
		||||
    <title>{% block title %}{% endblock %}</title>
 | 
			
		||||
    <style>
 | 
			
		||||
        body {
 | 
			
		||||
            margin: 0;
 | 
			
		||||
            padding: 0;
 | 
			
		||||
            background-color: #f6f6f6;
 | 
			
		||||
            font-family: Nunito, Arial, sans-serif;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        .email-wrapper {
 | 
			
		||||
            max-width: 600px;
 | 
			
		||||
            margin: 0 auto;
 | 
			
		||||
            background-color: #ffffff;
 | 
			
		||||
            border: 1px solid #e0e0e0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        .header {
 | 
			
		||||
            background-color: #6CD4FF; /* $primary */
 | 
			
		||||
            color: #292a2c; /* $link */
 | 
			
		||||
            padding: 20px;
 | 
			
		||||
            text-align: center;
 | 
			
		||||
            font-size: 24px;
 | 
			
		||||
            font-weight: bold;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        .content {
 | 
			
		||||
            padding: 30px 20px;
 | 
			
		||||
            color: #262728; /* $grey-dark */
 | 
			
		||||
            font-size: 16px;
 | 
			
		||||
            line-height: 1.5;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        .cta-button {
 | 
			
		||||
            display: inline-block;
 | 
			
		||||
            padding: 12px 20px;
 | 
			
		||||
            background-color: hsl(133deg, 100%, 41%); /* $confirm */
 | 
			
		||||
            color: #ffffff;
 | 
			
		||||
            text-decoration: none;
 | 
			
		||||
            border-radius: 4px;
 | 
			
		||||
            margin-top: 20px;
 | 
			
		||||
            font-weight: bold;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        .footer {
 | 
			
		||||
            background-color: #c4c6ce; /* $grey-light */
 | 
			
		||||
            color: #292a2c;
 | 
			
		||||
            text-align: center;
 | 
			
		||||
            padding: 15px 10px;
 | 
			
		||||
            font-size: 14px;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @media (max-width: 600px) {
 | 
			
		||||
            .content, .header, .footer {
 | 
			
		||||
                padding: 20px 15px;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    </style>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<div class="email-wrapper">
 | 
			
		||||
 | 
			
		||||
{% block header %}
 | 
			
		||||
    {% include "fellchensammlung/mail/header.html" %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
    <div class="content">
 | 
			
		||||
        {% block content %}{% endblock %}
 | 
			
		||||
    </div>
 | 
			
		||||
{% include "fellchensammlung/mail/footer.html" %}
 | 
			
		||||
</div>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
@@ -0,0 +1,3 @@
 | 
			
		||||
<div class="footer">
 | 
			
		||||
    🐀 notfellchen.org | Für Menschen die Ratten aus dem Tierschutz ein liebendes Zuhause geben wollen.
 | 
			
		||||
</div>
 | 
			
		||||
@@ -0,0 +1,3 @@
 | 
			
		||||
<div class="header">
 | 
			
		||||
    notfellchen.org
 | 
			
		||||
</div>
 | 
			
		||||
@@ -0,0 +1,18 @@
 | 
			
		||||
{% extends "fellchensammlung/mail/base.html" %}
 | 
			
		||||
{% load i18n %}
 | 
			
		||||
{% block title %}
 | 
			
		||||
    {% translate 'Test-E-Mail' %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block content %}
 | 
			
		||||
    <p>Moin,</p>
 | 
			
		||||
    <p>
 | 
			
		||||
        das ist eine Test-E-Mail.
 | 
			
		||||
    </p>
 | 
			
		||||
    <p>
 | 
			
		||||
        Hier ist ein total wichtiger Button. Klick den mal!
 | 
			
		||||
    </p>
 | 
			
		||||
    <p>
 | 
			
		||||
        <a href="https://notfellchen.org" class="cta-button">{% translate 'Zur Website' %}</a>
 | 
			
		||||
    </p>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
@@ -1,10 +1,13 @@
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
from notfellchen import settings
 | 
			
		||||
from django.utils import timezone
 | 
			
		||||
from datetime import timedelta
 | 
			
		||||
 | 
			
		||||
from django_super_deduper.merge import MergedModelInstance
 | 
			
		||||
from django.template.loader import render_to_string
 | 
			
		||||
from django.core import mail
 | 
			
		||||
from django.utils.html import strip_tags
 | 
			
		||||
 | 
			
		||||
from fellchensammlung.models import AdoptionNotice, Location, RescueOrganization, AdoptionNoticeStatus, Log, \
 | 
			
		||||
    AdoptionNoticeNotification
 | 
			
		||||
@@ -125,3 +128,13 @@ def export_orgs_as_vcf():
 | 
			
		||||
    with open(filename, "w") as f:
 | 
			
		||||
        f.write(result)
 | 
			
		||||
    print(f"Wrote {len(rescue_orgs)} contacts to {filename}")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def send_test_email(email):
 | 
			
		||||
    subject = 'Test E-Mail'
 | 
			
		||||
    html_message = render_to_string('fellchensammlung/mail/test.html', {'context': 'values'})
 | 
			
		||||
    plain_message = strip_tags(html_message)
 | 
			
		||||
    from_email = f'From <{settings.DEFAULT_FROM_EMAIL}>'
 | 
			
		||||
    to = email
 | 
			
		||||
 | 
			
		||||
    mail.send_mail(subject, plain_message, from_email, [to], html_message=html_message)
 | 
			
		||||
 
 | 
			
		||||
@@ -30,7 +30,7 @@ from .tools import i18n
 | 
			
		||||
from .tools.geo import GeoAPI, zoom_level_for_radius
 | 
			
		||||
from .tools.metrics import gather_metrics_data
 | 
			
		||||
from .tools.admin import clean_locations, get_unchecked_adoption_notices, deactivate_unchecked_adoption_notices, \
 | 
			
		||||
    deactivate_404_adoption_notices
 | 
			
		||||
    deactivate_404_adoption_notices, send_test_email
 | 
			
		||||
from .tasks import post_adoption_notice_save
 | 
			
		||||
from rest_framework.authtoken.models import Token
 | 
			
		||||
 | 
			
		||||
@@ -638,6 +638,9 @@ def instance_health_check(request):
 | 
			
		||||
            deactivate_unchecked_adoption_notices()
 | 
			
		||||
        elif action == "deactivate_404":
 | 
			
		||||
            deactivate_404_adoption_notices()
 | 
			
		||||
        elif action == "send_test_email":
 | 
			
		||||
            target_email = request.POST.get("test_email_address")
 | 
			
		||||
            send_test_email(target_email)
 | 
			
		||||
 | 
			
		||||
    number_of_adoption_notices = AdoptionNotice.objects.all().count()
 | 
			
		||||
    none_geocoded_adoption_notices = AdoptionNotice.objects.filter(location__isnull=True)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user