Coverage for portality / events / consumers / application_maned_ready_notify.py: 97%
34 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# ~~ApplicationManedReadyNotify:Consumer~~
2from portality.events import consumer_utils
3from portality.util import url_for
4from portality.events.consumer import EventConsumer
5from portality import constants
6from portality import models
7from portality.bll import DOAJ, exceptions
10class ApplicationManedReadyNotify(EventConsumer):
11 ID = "application:maned:ready:notify"
13 @classmethod
14 def should_consume(cls, event):
15 return event.id == constants.EVENT_APPLICATION_STATUS and \
16 event.context.get("application") is not None and \
17 event.context.get("old_status") != constants.APPLICATION_STATUS_READY and \
18 event.context.get("new_status") == constants.APPLICATION_STATUS_READY
20 @classmethod
21 def consume(cls, event):
22 app_source = event.context.get("application")
24 application = consumer_utils.parse_application(app_source)
25 if not application.editor_group:
26 return None
29 eg = models.EditorGroup.pull_by_key("name", application.editor_group)
30 managing_editor = eg.maned
31 if not managing_editor:
32 return None
34 editor = eg.editor
35 if not editor:
36 editor = "unknown editor"
38 # ~~-> Notifications:Service ~~
39 svc = DOAJ.notificationsService()
41 notification = models.Notification()
42 notification.who = managing_editor
43 notification.created_by = cls.ID
44 notification.classification = constants.NOTIFICATION_CLASSIFICATION_STATUS_CHANGE
45 notification.long = svc.long_notification(cls.ID).format(
46 application_title=application.bibjson().title,
47 editor=editor,
48 group_name=application.editor_group
49 )
50 notification.short = svc.short_notification(cls.ID).format(
51 issns=application.bibjson().issns_as_text()
52 )
53 notification.action = url_for("admin.application", application_id=application.id)
55 svc.notify(notification)
56 return notification