update: fix !8
This commit is contained in:
parent
9ad830dbbb
commit
f278f759fb
@ -79,12 +79,20 @@ def send_request(target, object_iri):
|
|||||||
@receiver(post_save, sender=Notification)
|
@receiver(post_save, sender=Notification)
|
||||||
def send_email_on_notification(sender, instance, created, **kwargs):
|
def send_email_on_notification(sender, instance, created, **kwargs):
|
||||||
if created and instance.summary and settings.JABBER_DEFAULT_HOST and instance.user.email:
|
if created and instance.summary and settings.JABBER_DEFAULT_HOST and instance.user.email:
|
||||||
|
try:
|
||||||
|
who = requests.get(instance.author).json()['name'] or 'Unknown Person' # I've no idea how to handle dead links.
|
||||||
|
where = requests.get(instance.object).json()['name'] or 'some unknown place' # So let's get to the unknown :)
|
||||||
|
if(instance.author == instance.object):
|
||||||
|
where = "has sent you a private message"
|
||||||
|
else:
|
||||||
|
where = "mention you on " + where
|
||||||
html_message = loader.render_to_string(
|
html_message = loader.render_to_string(
|
||||||
'email.html',
|
'email.html',
|
||||||
{
|
{
|
||||||
'on': settings.JABBER_DEFAULT_HOST,
|
'on': settings.JABBER_DEFAULT_HOST,
|
||||||
'instance': instance,
|
'instance': instance,
|
||||||
'author': requests.get(instance.author).json()['name'] or 'Unknown user'
|
'author': who,
|
||||||
|
'object': where
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
send_mail(
|
send_mail(
|
||||||
@ -95,6 +103,8 @@ def send_email_on_notification(sender, instance, created, **kwargs):
|
|||||||
fail_silently=True,
|
fail_silently=True,
|
||||||
html_message=html_message
|
html_message=html_message
|
||||||
)
|
)
|
||||||
|
except:
|
||||||
|
logging.error('Djangoldp_notifications: Can\'t mail the user')
|
||||||
else:
|
else:
|
||||||
if created:
|
if created:
|
||||||
raise Exception('Misconfiguration, missing JABBER_DEFAULT_HOST or incomplete instance')
|
raise Exception('Djangoldp_notifications: Misconfiguration, missing JABBER_DEFAULT_HOST or no mail for user found')
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
<p style='font-style:italic;color:#777'>A new {{ instance.type }} from <b>{{ author }}</b> on {{ on }}</p>
|
<p style='font-style:italic;color:#777'><b>{{ author }}</b> {{ object }} from on {{ on }}</p>
|
||||||
<p>{{ instance.summary }}</p>
|
<p>{{ instance.summary }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div style='margin-top:10px;'>
|
<div style='margin-top:10px;'>
|
||||||
|
Loading…
Reference in New Issue
Block a user