Skip to content
Snippets Groups Projects
Verified Commit 9416c279 authored by Jean-Baptiste Pasquier's avatar Jean-Baptiste Pasquier
Browse files

fix: use local instance

parent 5f254311
No related branches found
No related tags found
No related merge requests found
...@@ -79,32 +79,42 @@ def send_request(target, object_iri): ...@@ -79,32 +79,42 @@ 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: try:
who = requests.get(instance.author).json()['name'] or 'Unknown Person' # I've no idea how to handle dead links. if instance.author.startswith(settings.SITE_URL):
where = requests.get(instance.object).json()['name'] or 'some unknown place' # So let's get to the unknown :) who = str(Model.resolve_id(instance.author.replace(settings.SITE_URL,'')))
if(instance.author == instance.object): else:
where = "has sent you a private message" who = requests.get(instance.author).json()['name']
except:
who = "Unknown Person"
try:
if instance.object.startswith(settings.SITE_URL):
where = str(Model.resolve_id(instance.object.replace(settings.SITE_URL,'')))
else: else:
where = "mention you on " + where where = requests.get(instance.object).json()['name']
html_message = loader.render_to_string(
'email.html',
{
'on': settings.JABBER_DEFAULT_HOST,
'instance': instance,
'author': who,
'object': where
}
)
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=True,
html_message=html_message
)
except: except:
logging.error('Djangoldp_notifications: Can\'t mail the user') where = "Unknown place"
else:
if created: if(who == where):
raise Exception('Djangoldp_notifications: Misconfiguration, missing JABBER_DEFAULT_HOST or no mail for user found') where = "has sent you a private message"
else:
where = "mention you on " + where
html_message = loader.render_to_string(
'email.html',
{
'on': settings.JABBER_DEFAULT_HOST,
'instance': instance,
'author': who,
'object': where
}
)
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=True,
html_message=html_message
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment