Coverage for portality/events/consumers/application_assed_assigned_notify.py: 100%
29 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.bll import DOAJ
8from portality.bll import exceptions
11class ApplicationAssedAssignedNotify(EventConsumer):
12 ID = "application:assed:assigned:notify"
14 @classmethod
15 def consumes(cls, event):
16 return event.id == constants.EVENT_APPLICATION_ASSED_ASSIGNED and \
17 event.context.get("application") is not None
19 @classmethod
20 def consume(cls, event):
21 app_source = event.context.get("application")
23 try:
24 application = models.Application(**app_source)
25 except Exception as e:
26 raise exceptions.NoSuchObjectException("Unable to construct Application from supplied source - data structure validation error, {x}".format(x=e))
28 if not application.editor:
29 raise exceptions.NoSuchPropertyException("Application {x} does not have property `editor`".format(x=application.id))
31 svc = DOAJ.notificationsService()
33 notification = models.Notification()
34 notification.who = application.editor
35 notification.created_by = cls.ID
36 notification.classification = constants.NOTIFICATION_CLASSIFICATION_ASSIGN
37 notification.long = svc.long_notification(cls.ID).format(
38 journal_title=application.bibjson().title,
39 group_name=application.editor_group
40 )
41 notification.short = svc.short_notification(cls.ID)
42 notification.action = url_for("editor.application", application_id=application.id)
44 svc.notify(notification)