-
Notifications
You must be signed in to change notification settings - Fork 16
/
application_editor_completed_notify.py
67 lines (55 loc) · 2.55 KB
/
application_editor_completed_notify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# ~~ApplicationEditorCompletedNotify:Consumer~~
from portality.events import consumer_utils
from portality.util import url_for
from portality.events.consumer import EventConsumer
from portality import constants
from portality import models
from portality.bll import DOAJ, exceptions
from portality.lib.seamless import SeamlessException
class ApplicationEditorCompletedNotify(EventConsumer):
ID = "application:editor:completed:notify"
@classmethod
def should_consume(cls, event):
return event.id == constants.EVENT_APPLICATION_STATUS and \
event.context.get("old_status") != constants.APPLICATION_STATUS_COMPLETED and \
event.context.get("new_status") == constants.APPLICATION_STATUS_COMPLETED
@classmethod
def consume(cls, event):
context = event.context
app = context.get("application")
if app is None:
return
try:
application = models.Application(**app)
except SeamlessException:
raise exceptions.NoSuchObjectException("Unable to create application model from source")
if application is None:
raise exceptions.NoSuchObjectException("Unable to create application model from source")
if not application.editor_group:
return
# The associate editor in question is who created this event
associate_editor = "unknown associate editor"
if application.editor:
associate_editor = event.who
# Notification is to the editor in charge of this application's assigned editor group
editor_group_name = application.editor_group
editor_group_id = models.EditorGroup.group_exists_by_name(name=editor_group_name)
eg = models.EditorGroup.pull(editor_group_id)
group_editor = eg.editor
if not group_editor:
return
# ~~-> Notifications:Service ~~
svc = DOAJ.notificationsService()
notification = models.Notification()
notification.who = group_editor
notification.created_by = cls.ID
notification.classification = constants.NOTIFICATION_CLASSIFICATION_STATUS_CHANGE
notification.long = svc.long_notification(cls.ID).format(
application_title=application.bibjson().title,
associate_editor=associate_editor
)
notification.short = svc.short_notification(cls.ID).format(
issns=application.bibjson().issns_as_text()
)
notification.action = url_for("editor.application", application_id=application.id)
svc.notify(notification)