Coverage for portality/events/consumers/application_editor_inprogress_notify.py: 90%
42 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.lib import edges
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 consumes(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
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
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
47 svc = DOAJ.notificationsService()
49 notification = models.Notification()
50 notification.who = group_editor
51 notification.created_by = cls.ID
52 notification.classification = constants.NOTIFICATION_CLASSIFICATION_STATUS_CHANGE
53 notification.long = svc.long_notification(cls.ID).format(
54 application_title=application.bibjson().title
55 )
56 notification.short = svc.short_notification(cls.ID)
58 # don't make the escaped query, as url_for is also going to escape it, and it will wind up double-escaped!
59 string_id_query = edges.make_query_json(query_string=application.id)
60 # note we're using the doaj url_for wrapper, not the flask url_for directly, due to the request context hack required
61 notification.action = url_for("editor.group_suggestions", source=string_id_query)
63 svc.notify(notification)