fix: use local instance
This commit is contained in:
parent
5f25431182
commit
9416c27971
@ -80,31 +80,41 @@ def send_request(target, object_iri):
|
|||||||
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):
|
|
||||||
where = "has sent you a private message"
|
|
||||||
else:
|
else:
|
||||||
where = "mention you on " + where
|
who = requests.get(instance.author).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')
|
who = "Unknown Person"
|
||||||
else:
|
|
||||||
if created:
|
try:
|
||||||
raise Exception('Djangoldp_notifications: Misconfiguration, missing JABBER_DEFAULT_HOST or no mail for user found')
|
if instance.object.startswith(settings.SITE_URL):
|
||||||
|
where = str(Model.resolve_id(instance.object.replace(settings.SITE_URL,'')))
|
||||||
|
else:
|
||||||
|
where = requests.get(instance.object).json()['name']
|
||||||
|
except:
|
||||||
|
where = "Unknown place"
|
||||||
|
|
||||||
|
if(who == where):
|
||||||
|
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
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user