Coverage for portality/events/consumers/journal_assed_assigned_notify.py: 100%
29 statements
« prev ^ index » next coverage.py v6.4.2, created at 2022-11-09 15:10 +0000
« prev ^ index » next coverage.py v6.4.2, created at 2022-11-09 15:10 +0000
1# from flask import url_for
2from portality.util import url_for
4from portality.events.consumer import EventConsumer
5from portality import constants
6from portality import models
7from portality.bll import DOAJ
8from portality.bll import exceptions
11class JournalAssedAssignedNotify(EventConsumer):
12 ID = "journal:assed:assigned:notify"
14 @classmethod
15 def consumes(cls, event):
16 return event.id == constants.EVENT_JOURNAL_ASSED_ASSIGNED and \
17 event.context.get("journal") is not None
19 @classmethod
20 def consume(cls, event):
21 j_source = event.context.get("journal")
23 try:
24 journal = models.Journal(**j_source)
25 except Exception as e:
26 raise exceptions.NoSuchObjectException("Unable to construct Journal from supplied source - data structure validation error, {x}".format(x=e))
28 if not journal.editor:
29 raise exceptions.NoSuchPropertyException("Journal {x} does not have property `editor`".format(x=journal.id))
31 svc = DOAJ.notificationsService()
33 notification = models.Notification()
34 notification.who = journal.editor
35 notification.created_by = cls.ID
36 notification.classification = constants.NOTIFICATION_CLASSIFICATION_ASSIGN
37 notification.long = svc.long_notification(cls.ID).format(
38 journal_name=journal.bibjson().title,
39 group_name=journal.editor_group
40 )
41 notification.short = svc.short_notification(cls.ID)
42 notification.action = url_for("editor.journal_page", journal_id=journal.id)
44 svc.notify(notification)