Coverage for portality / events / consumers / journal_editor_group_assigned_notify.py: 97%
33 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-04 09:41 +0100
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-04 09:41 +0100
1# ~~JournalEditorGroupAssignedNotify:Consumer~~
2from portality.events import consumer_utils
3from portality.util import url_for
5from portality.events.consumer import EventConsumer
6from portality import constants
7from portality import models
8from portality.bll import DOAJ
9from portality.bll import exceptions
12class JournalEditorGroupAssignedNotify(EventConsumer):
13 ID = "journal:editor_group:assigned:notify"
15 @classmethod
16 def should_consume(cls, event):
17 return event.id == constants.EVENT_JOURNAL_EDITOR_GROUP_ASSIGNED and \
18 event.context.get("journal") is not None
20 @classmethod
21 def consume(cls, event):
22 j_source = event.context.get("journal")
24 try:
25 journal = models.Journal(**j_source)
26 except Exception as e:
27 raise exceptions.NoSuchObjectException("Unable to construct Journal from supplied source - data structure validation error, {x}".format(x=e))
29 if not journal.editor_group:
30 return None
32 editor_group = models.EditorGroup.pull_by_key("name", journal.editor_group)
34 if not editor_group.editor:
35 raise exceptions.NoSuchPropertyException("Editor Group {x} does not have property `editor`".format(x=editor_group.id))
37 # ~~-> Notifications:Service ~~
38 svc = DOAJ.notificationsService()
40 notification = models.Notification()
41 notification.who = editor_group.editor
42 notification.created_by = cls.ID
43 notification.classification = constants.NOTIFICATION_CLASSIFICATION_ASSIGN
45 notification.long = svc.long_notification(cls.ID).format(
46 journal_name=journal.bibjson().title
47 )
48 notification.short = svc.short_notification(cls.ID).format(
49 issns=journal.bibjson().issns_as_text()
50 )
52 # No action possible due to page removed (see portality.view.editor.journal_page(journal_id))
53 # notification.action = url_for("editor.journal_page", journal_id=journal.id)
55 svc.notify(notification)
56 return notification