send mail to report reviewers

This commit is contained in:
Laura Klünder 2019-12-24 18:20:39 +01:00
parent cb467d7f54
commit d5086f79c0
4 changed files with 57 additions and 3 deletions

25
src/c3nav/site/tasks.py Normal file
View file

@ -0,0 +1,25 @@
import logging
from django.conf import settings
from django.contrib.auth.models import User
from django.core.mail import send_mail
from c3nav.celery import app
logger = logging.getLogger('c3nav')
@app.task(bind=True, max_retries=3)
def send_report_notification(self, pk, author, title, description, reviewers):
subject = '[c3nav] New Report by %s: %s' % (author, title)
for user in User.objects.filter(pk=reviewers):
if not user.email:
continue
text = (
('Hi %s!\n\n' % user.username) +
('A new Report has ben submitted by %s:\n\n' % author) +
('---\n\n') +
(title+'\n\n'+description)
)
send_mail(subject, text, settings.MAIL_FROM, [user.email])

View file

@ -3,6 +3,7 @@
{% block content %}
<main class="account">
{% include 'site/fragment_messages.html' %}
<h2>{% trans 'Report' %}: {{ report.title }}</h2>
<p><em>
{% if report.open %}
@ -19,7 +20,6 @@
{{ report.created }}
</em></p>
{% include 'site/fragment_messages.html' %}
{% include 'site/fragment_report_meta.html' %}
{% for field in form %}