mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-28 19:10:35 +00:00
Email templates
This commit is contained in:
parent
8cf6eb1c13
commit
41dd915d7f
9 changed files with 53 additions and 11 deletions
|
@ -10,14 +10,9 @@ from bookwyrm.settings import DOMAIN
|
|||
def email_data():
|
||||
"""fields every email needs"""
|
||||
site = models.SiteSettings.objects.get()
|
||||
if site.logo_small:
|
||||
logo_path = f"/images/{site.logo_small.url}"
|
||||
else:
|
||||
logo_path = "/static/images/logo-small.png"
|
||||
|
||||
return {
|
||||
"site_name": site.name,
|
||||
"logo": logo_path,
|
||||
"logo": site.logo_small_url,
|
||||
"domain": DOMAIN,
|
||||
"user": None,
|
||||
}
|
||||
|
@ -46,6 +41,18 @@ def password_reset_email(reset_code):
|
|||
send_email.delay(reset_code.user.email, *format_email("password_reset", data))
|
||||
|
||||
|
||||
def moderation_report_email(report):
|
||||
"""a report was created"""
|
||||
data = email_data()
|
||||
data["reporter"] = report.reporter.localname or report.reporter.username
|
||||
data["reportee"] = report.user.localname or report.user.username
|
||||
data["report_link"] = report.remote_id
|
||||
|
||||
for admin in models.User.objects.filter(permissions="moderate_user"):
|
||||
data["user"] = admin.display_name
|
||||
send_email.delay(admin.email, *format_email("moderation_report", data))
|
||||
|
||||
|
||||
def format_email(email_name, data):
|
||||
"""render the email templates"""
|
||||
subject = get_template(f"email/{email_name}/subject.html").render(data).strip()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
""" the particulars for this instance of BookWyrm """
|
||||
import datetime
|
||||
from urllib.parse import urljoin
|
||||
|
||||
from django.db import models, IntegrityError
|
||||
from django.dispatch import receiver
|
||||
|
@ -7,9 +8,10 @@ from django.utils import timezone
|
|||
from model_utils import FieldTracker
|
||||
|
||||
from bookwyrm.preview_images import generate_site_preview_image_task
|
||||
from bookwyrm.settings import DOMAIN, ENABLE_PREVIEW_IMAGES
|
||||
from bookwyrm.settings import DOMAIN, ENABLE_PREVIEW_IMAGES, STATIC_FULL_URL
|
||||
from .base_model import BookWyrmModel, new_access_code
|
||||
from .user import User
|
||||
from .fields import get_absolute_url
|
||||
|
||||
|
||||
class SiteSettings(models.Model):
|
||||
|
@ -66,6 +68,13 @@ class SiteSettings(models.Model):
|
|||
default_settings.save()
|
||||
return default_settings
|
||||
|
||||
@property
|
||||
def logo_small_url(self):
|
||||
""" helper to build the lgoo url """
|
||||
if self.logo_small:
|
||||
return get_absolute_url(self.logo_small)
|
||||
return urljoin(STATIC_FULL_URL, "images/logo-small.png")
|
||||
|
||||
|
||||
class SiteInvite(models.Model):
|
||||
"""gives someone access to create an account on the instance"""
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<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>
|
||||
<a style="color: #3273dc;" href="https://{{ domain }}" style="text-decoration: none;"><img src="{{ 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>
|
||||
|
|
11
bookwyrm/templates/email/moderation_report/html_content.html
Normal file
11
bookwyrm/templates/email/moderation_report/html_content.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
{% extends 'email/html_layout.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<p>
|
||||
{% blocktrans %}@{{ reporter }} has flagged behavior by @{{ reportee }} for moderation. {% endblocktrans %}
|
||||
</p>
|
||||
|
||||
{% trans "View report" as text %}
|
||||
{% include 'email/snippets/action.html' with path=report_link text=text %}
|
||||
{% endblock %}
|
2
bookwyrm/templates/email/moderation_report/subject.html
Normal file
2
bookwyrm/templates/email/moderation_report/subject.html
Normal file
|
@ -0,0 +1,2 @@
|
|||
{% load i18n %}
|
||||
{% blocktrans %}New report for {{ site_name }}{% endblocktrans %}
|
|
@ -0,0 +1,9 @@
|
|||
{% extends 'email/text_layout.html' %}
|
||||
{% load i18n %}
|
||||
{% block content %}
|
||||
|
||||
{% blocktrans %}@{{ reporter}} has flagged behavior by @{{ reportee }} for moderation. {% endblocktrans %}
|
||||
|
||||
{% trans "View report" %}
|
||||
{{ report_link }}
|
||||
{% endblock %}
|
|
@ -1,4 +1,4 @@
|
|||
<html lang="{% get_lang %}">
|
||||
<html>
|
||||
<body>
|
||||
<div>
|
||||
<strong>Subject:</strong> {% include subject_path %}
|
||||
|
|
|
@ -7,7 +7,7 @@ from django.utils.decorators import method_decorator
|
|||
from django.views import View
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
from bookwyrm import forms, models
|
||||
from bookwyrm import emailing, forms, models
|
||||
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
|
@ -142,5 +142,6 @@ def make_report(request):
|
|||
if not form.is_valid():
|
||||
raise ValueError(form.errors)
|
||||
|
||||
form.save()
|
||||
report = form.save()
|
||||
emailing.moderation_report_email(report)
|
||||
return redirect(request.headers.get("Referer", "/"))
|
||||
|
|
|
@ -48,4 +48,7 @@ def email_preview(request):
|
|||
data["invite_link"] = "https://example.com/link"
|
||||
data["confirmation_link"] = "https://example.com/link"
|
||||
data["confirmation_code"] = "AKJHKDGKJSDFG"
|
||||
data["reporter"] = "ConcernedUser"
|
||||
data["reportee"] = "UserName"
|
||||
data["report_link"] = "https://example.com/link"
|
||||
return TemplateResponse(request, "email/preview.html", data)
|
||||
|
|
Loading…
Reference in a new issue