Adds email template layout and formatting

This commit is contained in:
Mouse Reeve 2021-03-21 11:43:14 -07:00
parent 33b5639af0
commit d8a20175b6
15 changed files with 152 additions and 20 deletions

View file

@ -4,25 +4,37 @@ from django.template.loader import get_template
from bookwyrm import models
from bookwyrm.tasks import app
from bookwyrm.settings import DOMAIN
def email_data():
""" fields every email needs """
site = models.SiteSettings.objects.get()
if site.logo_small:
logo_path = '/images/{}'.format(site.logo_small.url)
else:
logo_path = '/static/images/logo-small.png'
return {
"site_name": site.name,
"logo": logo_path,
"domain": DOMAIN,
"user": None,
}
def invite_email(invite_request):
""" send out an invite code """
site = models.SiteSettings.objects.get()
data = {
"site_name": site.name,
"invite_link": invite_request.invite.link,
}
data = email_data()
data["invite_link"] = invite_request.invite.link
send_email.delay(invite_request.email, "invite", data)
def password_reset_email(reset_code):
""" generate a password reset email """
site = models.SiteSettings.objects.get()
data = {
"site_name": site.name,
"reset_link": reset_code.link,
}
data = email_data()
data["reset_link"] = reset_code.link
data["user"] = reset_code.user.diplay_name
send_email.delay(reset_code.user.email, "password_reset", data)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

View file

@ -0,0 +1,26 @@
{% load i18n %}
<div style="font-family: BlinkMacSystemFont,-apple-system,'Segoe UI',Roboto,Oxygen,Ubuntu,Cantarell,'Fira Sans','Droid Sans','Helvetica Neue',Helvetica,Arial,sans-serif; border-radius: 6px; background-color: #efefef; max-width: 632px;">
<div style="padding: 1rem; overflow: auto;">
<div style="float: left; margin-right: 1rem;">
<a style="color: #3273dc;" href="https://{{ domain }}" style="text-decoration: none;"><img src="https://{{ domain }}/{{ logo }}" alt="logo"></a>
</div>
<div>
<a style="color: black; text-decoration: none" href="https://{{ domain }}" style="text-decoration: none;"><strong>{{ site_name }}</strong><br>
{{ domain }}</a>
</div>
</div>
<div style="padding: 1rem; background-color: white;">
<p>
{% if user %}{{ user }},{% else %}{% trans "Hi there," %}{% endif %}
</p>
{% block content %}{% endblock %}
</div>
<div style="padding: 1rem; font-size: 0.8rem;">
<p style="margin: 0; color: #333;">{% blocktrans %}BookWyrm hosted on <a style="color: #3273dc;" href="https://{{ domain }}">{{ site_name }}</a>{% endblocktrans %}</p>
{% if user %}
<p style="margin: 0; color: #333;"><a style="color: #3273dc;" href="https://{{ domain }}{% url 'prefs-profile' %}">{% trans "Email preference" %}</a></p>
{% endif %}
</div>
</div>

View file

@ -1,2 +1,17 @@
{% extends 'email/html_layout.html' %}
{% load i18n %}
<a href="{{ invite_link }}">{% blocktrans %}Join {{ site_name }}{% endblocktrans %}</a>
{% block content %}
<p>
{% blocktrans %}You're invited to join {{ site_name }}!{% endblocktrans %}
</p>
{% trans "Join Now" as text %}
{% include 'email/snippets/action.html' with path=invite_link text=text %}
<p>
{% url 'code-of-conduct' as coc_path %}
{% url 'about' as about_path %}
{% blocktrans %}Learn more <a href="https://{{ domain }}{{ about_path }}">about this instance</a>.{% endblocktrans %}
</p>
{% endblock %}

View file

@ -1,2 +1,2 @@
{% load i18n %}
{% blocktrans %}You're invited! Join {{ site_name }}{% endblocktrans %}
{% blocktrans %}You're invited to join {{ site_name }}!{% endblocktrans %}

View file

@ -1,2 +1,10 @@
{% extends 'email/text_layout.html' %}
{% load i18n %}
{% blocktrans %}Join {{ site_name }}: {{ invite_link }}{% endblocktrans %}
{% block content %}
{% blocktrans %}You're invited to join {{ site_name }}! Click the link below to create an account.{% endblocktrans %}
{{ invite_link }}
{% trans "Learn more about this instance:" %} https://{{ domain }}{% url 'about' %}
{% endblock %}

View file

@ -1,2 +1,15 @@
{% extends 'email/html_layout.html' %}
{% load i18n %}
{% blocktrans %}Your password reset link is: {{ reset_link }}{% endblocktrans %}
{% block content %}
<p>
{% blocktrans %}You requested to reset your {{ site_name }} password. Click the link below to set a new password and log in to your account.{% endblocktrans %}
</p>
{% trans "Reset Password" as text %}
{% include 'email/snippets/action.html' with path=reset_link text=text %}
<p>
{% trans "If you didn't request to reset your password, you can ignore this email." %}
</p>
{% endblock %}

View file

@ -1,2 +1,2 @@
{% load i18n %}
{% blocktrans %}Reset your password on {{ site_name }}{% endblocktrans %}
{% blocktrans %}Reset your {{ site_name }} password{% endblocktrans %}

View file

@ -1,2 +1,9 @@
{% extends 'email/text_layout.html' %}
{% load i18n %}
{% blocktrans %}Your password reset link is: {{ reset_link }}{% endblocktrans %}
{% block content %}
{% blocktrans %}You requested to reset your {{ site_name }} password. Click the link below to set a new password and log in to your account.{% endblocktrans %}
{{ reset_link }}
{% trans "If you didn't request to reset your password, you can ignore this email." %}
{% endblock %}

View file

@ -0,0 +1,19 @@
<html>
<body>
<div>
<strong>Subject:</strong> {% include subject_path %}
</div>
<hr>
<strong>Html email:</strong>
<div style="border: 1px solid #c0c0c0; margin: 2em; padding: 1em;">
{% include html_content_path %}
</div>
<hr>
<strong>Text email:</strong>
<div style="border: 1px solid #c0c0c0; margin: 2em; padding: 1em; white-space: pre;">
{% include text_content_path %}
</div>
</body>
</html>

View file

@ -0,0 +1,5 @@
<p style="text-align: center; margin: 2rem;">
<a href="{{ path }}" style="background-color: #3273dc; color: #fff; border-radius: 4px; padding: 0.5rem 1rem; text-decoration: none;">
{{ text }}
</a>
</p>

View file

@ -0,0 +1,3 @@
{% load i18n %}
{% if user %}{{ user.display_name }},{% else %}{% trans "Hi there," %}{% endif %}
{% block content %}{% endblock %}

View file

@ -8,7 +8,9 @@
<div class="column is-half">
<div class="block">
<h1 class="title">{% trans "Reset Password" %}</h1>
{% if message %}<p>{{ message }}</p>{% endif %}
{% if message %}<p class="notification is-primary">{{ message }}</p>{% endif %}
<p>{% trans "A link to reset your password will be sent to your email address" %}</p>
<form name="password-reset" method="post" action="/password-reset">
{% csrf_token %}
@ -16,6 +18,9 @@
<label class="label" for="id_email_register">{% trans "Email address:" %}</label>
<div class="control">
<input type="email" name="email" maxlength="254" class="input" id="id_email_register">
{% if error %}
<p class="help is-danger">{{ error }}</p>
{% endif %}
</div>
</div>
<div class="field is-grouped">

View file

@ -48,6 +48,11 @@ urlpatterns = [
),
# admin
re_path(r"^settings/site-settings", views.Site.as_view(), name="settings-site"),
re_path(
r"^settings/email-preview",
views.site.email_preview,
name="settings-email-preview",
),
re_path(
r"^settings/federation", views.Federation.as_view(), name="settings-federation"
),
@ -87,8 +92,8 @@ urlpatterns = [
),
re_path(r"^report/?$", views.make_report, name="report"),
# landing pages
re_path(r"^about/?$", views.About.as_view()),
path("", views.Home.as_view()),
re_path(r"^about/?$", views.About.as_view(), name="about"),
path("", views.Home.as_view(), name="landing"),
re_path(r"^discover/?$", views.Discover.as_view()),
re_path(r"^notifications/?$", views.Notifications.as_view()),
# feeds

View file

@ -5,7 +5,7 @@ from django.template.response import TemplateResponse
from django.utils.decorators import method_decorator
from django.views import View
from bookwyrm import forms, models
from bookwyrm import emailing, forms, models
# pylint: disable= no-self-use
@ -33,3 +33,17 @@ class Site(View):
form.save()
return redirect("settings-site")
@login_required
@permission_required("bookwyrm.edit_instance_settings", raise_exception=True)
def email_preview(request):
""" for development, renders and example email template """
template = request.GET.get('email')
data = emailing.email_data()
data["subject_path"] = "email/{}/subject.html".format(template)
data["html_content_path"] = "email/{}/html_content.html".format(template)
data["text_content_path"] = "email/{}/text_content.html".format(template)
data["reset_link"] = "https://example.com/link"
data["invite_link"] = "https://example.com/link"
return TemplateResponse(request, "email/preview.html", data)