-
Notifications
You must be signed in to change notification settings - Fork 16
/
journal_assed_assigned_notify.py
47 lines (37 loc) · 1.71 KB
/
journal_assed_assigned_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
# ~~JournalAssedAssignedNotify:Consumer~~
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
from portality.bll import exceptions
class JournalAssedAssignedNotify(EventConsumer):
ID = "journal:assed:assigned:notify"
@classmethod
def consumes(cls, event):
return event.id == constants.EVENT_JOURNAL_ASSED_ASSIGNED and \
event.context.get("journal") is not None
@classmethod
def consume(cls, event):
j_source = event.context.get("journal")
try:
journal = models.Journal(**j_source)
except Exception as e:
raise exceptions.NoSuchObjectException("Unable to construct Journal from supplied source - data structure validation error, {x}".format(x=e))
if not journal.editor:
raise exceptions.NoSuchPropertyException("Journal {x} does not have property `editor`".format(x=journal.id))
# ~~-> Notifications:Service ~~
svc = DOAJ.notificationsService()
notification = models.Notification()
notification.who = journal.editor
notification.created_by = cls.ID
notification.classification = constants.NOTIFICATION_CLASSIFICATION_ASSIGN
notification.long = svc.long_notification(cls.ID).format(
journal_name=journal.bibjson().title,
group_name=journal.editor_group
)
notification.short = svc.short_notification(cls.ID).format(
issns=", ".join(issn for issn in journal.bibjson().issns())
)
notification.action = url_for("editor.journal_page", journal_id=journal.id)
svc.notify(notification)