ui: Add email template & change model for author_user
This commit is contained in:
parent
da08da009d
commit
cae681eae7
22
djangoldp_notification/migrations/0005_auto_20190502_1432.py
Normal file
22
djangoldp_notification/migrations/0005_auto_20190502_1432.py
Normal file
@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.20 on 2019-05-02 14:32
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('djangoldp_notification', '0004_auto_20190425_1141'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='notification',
|
||||
name='author_user',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
@ -16,10 +16,12 @@ from djangoldp.fields import LDPUrlField
|
||||
from djangoldp.models import Model
|
||||
from djangoldp.permissions import InboxPermissions
|
||||
|
||||
from django.template import loader
|
||||
|
||||
|
||||
class Notification(Model):
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='inbox', on_delete=models.deletion.CASCADE)
|
||||
author_user = LDPUrlField()
|
||||
author_user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.deletion.CASCADE)
|
||||
object = LDPUrlField()
|
||||
type = models.CharField(max_length=255)
|
||||
summary = models.TextField()
|
||||
@ -72,5 +74,21 @@ def send_request(target, object_iri):
|
||||
|
||||
@receiver(post_save, sender=Notification)
|
||||
def send_email_on_notification(sender, instance, **kwargs):
|
||||
send_mail('Notification on staging.happy-dev.fr', instance.summary, 'from@example.com', [instance.user.email],
|
||||
fail_silently=False)
|
||||
if instance.summary and settings.JABBER_DEFAULT_HOST and instance.user.email:
|
||||
html_message = loader.render_to_string(
|
||||
'email.html',
|
||||
{
|
||||
'on': settings.JABBER_DEFAULT_HOST,
|
||||
'instance': instance
|
||||
}
|
||||
)
|
||||
send_mail(
|
||||
'Notification on ' + settings.JABBER_DEFAULT_HOST,
|
||||
instance.summary,
|
||||
settings.EMAIL_HOST_USER or "noreply@" + settings.JABBER_DEFAULT_HOST,
|
||||
[instance.user.email],
|
||||
fail_silently=False,
|
||||
html_message=html_message
|
||||
)
|
||||
else:
|
||||
raise Exception('Misconfiguration, missing JABBER_DEFAULT_HOST or incomplete instance')
|
||||
|
20
djangoldp_notification/templates/email.html
Normal file
20
djangoldp_notification/templates/email.html
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<p style='font-style:italic;color:#777'>A new {{ instance.type }} from <b>{{ instance.author_user.name }}</b> on {{ on }}</p>
|
||||
<p>{{ instance.summary }}</p>
|
||||
</div>
|
||||
<div style='margin-top:10px;'>
|
||||
<p style='font-size:small;color:#777'>
|
||||
--
|
||||
<br>
|
||||
Do not reply to this email directly, go to <a href='http://{{ on }}' target='_blank'>http://{{ on }}</a> instead.
|
||||
<br>
|
||||
<a href='#'>Unsubscribe</a>
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user