Merge branch 'jbpasquier/template-mail' into 'master'
ui: Add email template & change model for author_user See merge request startinblox/djangoldp-packages/djangoldp-notifications!11
This commit is contained in:
commit
c32b9ec73b
@ -16,6 +16,8 @@ from djangoldp.fields import LDPUrlField
|
|||||||
from djangoldp.models import Model
|
from djangoldp.models import Model
|
||||||
from djangoldp.permissions import InboxPermissions
|
from djangoldp.permissions import InboxPermissions
|
||||||
|
|
||||||
|
from django.template import loader
|
||||||
|
|
||||||
|
|
||||||
class Notification(Model):
|
class Notification(Model):
|
||||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='inbox', on_delete=models.deletion.CASCADE)
|
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='inbox', on_delete=models.deletion.CASCADE)
|
||||||
@ -72,5 +74,22 @@ def send_request(target, object_iri):
|
|||||||
|
|
||||||
@receiver(post_save, sender=Notification)
|
@receiver(post_save, sender=Notification)
|
||||||
def send_email_on_notification(sender, instance, **kwargs):
|
def send_email_on_notification(sender, instance, **kwargs):
|
||||||
send_mail('Notification on staging.happy-dev.fr', instance.summary, 'from@example.com', [instance.user.email],
|
if instance.summary and settings.JABBER_DEFAULT_HOST and instance.user.email:
|
||||||
fail_silently=True)
|
html_message = loader.render_to_string(
|
||||||
|
'email.html',
|
||||||
|
{
|
||||||
|
'on': settings.JABBER_DEFAULT_HOST,
|
||||||
|
'instance': instance,
|
||||||
|
'author': requests.get(instance.author).json()['name'] or 'Unknown user'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
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>{{ author }}</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