Coverage for portality / events / consumers / application_editor_inprogress_notify.py: 90%
42 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# ~~ApplicationEditorInProgressNotify: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, exceptions
9from portality.lib.seamless import SeamlessException
12class ApplicationEditorInProgressNotify(EventConsumer):
13 ID = "application:editor:inprogress:notify"
15 @classmethod
16 def should_consume(cls, event):
17 return event.id == constants.EVENT_APPLICATION_STATUS and \
18 event.context.get("old_status") in [constants.APPLICATION_STATUS_READY, constants.APPLICATION_STATUS_COMPLETED] and \
19 event.context.get("new_status") == constants.APPLICATION_STATUS_IN_PROGRESS
21 @classmethod
22 def consume(cls, event):
23 context = event.context
24 app = context.get("application")
25 if app is None:
26 return None
27 try:
28 application = models.Application(**app)
29 except SeamlessException:
30 raise exceptions.NoSuchObjectException("Unable to create application model from source")
32 if application is None:
33 raise exceptions.NoSuchObjectException("Unable to create application model from source")
35 if not application.editor_group:
36 return None
38 # Notification is to the editor in charge of this application's assigned editor group
39 editor_group_name = application.editor_group
40 editor_group_id = models.EditorGroup.group_exists_by_name(name=editor_group_name)
41 eg = models.EditorGroup.pull(editor_group_id)
42 group_editor = eg.editor
44 if not group_editor:
45 return None
47 # ~~-> Notifications:Service ~~
48 svc = DOAJ.notificationsService()
50 notification = models.Notification()
51 notification.who = group_editor
52 notification.created_by = cls.ID
53 notification.classification = constants.NOTIFICATION_CLASSIFICATION_STATUS_CHANGE
54 notification.long = svc.long_notification(cls.ID).format(
55 application_title=application.bibjson().title
56 )
57 notification.short = svc.short_notification(cls.ID).format(
58 issns=application.bibjson().issns_as_text()
59 )
60 notification.action = url_for("editor.application", application_id=application.id)
62 svc.notify(notification)
63 return notification