Coverage for portality/bll/services/notifications.py: 100%
22 statements
« prev ^ index » next coverage.py v6.4.2, created at 2022-08-04 15:38 +0100
« prev ^ index » next coverage.py v6.4.2, created at 2022-08-04 15:38 +0100
1# ~~Notifications:Service~~
2from portality import models
3from portality.core import app
4from portality import app_email
5from portality.ui.messages import Messages
6from portality.bll.exceptions import NoSuchObjectException, NoSuchPropertyException
9class NotificationsService(object):
10 def notify(self, notification):
11 # first just save the notification
12 notification.save()
14 # now send an email to the notification target
15 acc = models.Account.pull(notification.who)
16 if acc is None:
17 raise NoSuchObjectException(Messages.EXCEPTION_NOTIFICATION_NO_ACCOUNT.format(x=notification.who))
19 if acc.email is None:
20 raise NoSuchPropertyException(Messages.EXCEPTION_NOTIFICATION_NO_EMAIL.format(x=notification.who))
22 to = [acc.email]
23 fro = app.config.get('SYSTEM_EMAIL_FROM', 'helpdesk@doaj.org')
24 subject = app.config.get("SERVICE_NAME", "") + " - " + notification.short
26 app_email.send_markdown_mail(to=to,
27 fro=fro,
28 subject=subject,
29 template_name="email/notification_email.jinja2",
30 markdown_template_name="email/notification_email.jinja2", # for the moment the markdown and plaintext templates are the same
31 user=acc,
32 message=notification.long,
33 action=notification.action,
34 url_root=app.config.get("BASE_URL"))
36 return notification
38 def long_notification(self, message_id):
39 return app.jinja_env.globals["data"]["notifications"].get(message_id, {}).get("long")
41 def short_notification(self, message_id):
42 return app.jinja_env.globals["data"]["notifications"].get(message_id, {}).get("short", Messages.NOTIFY__DEFAULT_SHORT_NOTIFICATION)