Coverage for portality/events/consumers/application_publisher_revision_notify.py: 97%
30 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
1from datetime import datetime
3from portality.events.consumer import EventConsumer
4from portality import constants
5from portality import models
6from portality.bll import DOAJ, exceptions
7from portality.lib.seamless import SeamlessException
10class ApplicationPublisherRevisionNotify(EventConsumer):
11 ID = "application:publisher:revision:notify"
13 @classmethod
14 def consumes(cls, event):
15 return event.id == constants.EVENT_APPLICATION_STATUS and \
16 event.context.get("application") is not None and \
17 event.context.get("old_status") != constants.APPLICATION_STATUS_REVISIONS_REQUIRED and \
18 event.context.get("new_status") == constants.APPLICATION_STATUS_REVISIONS_REQUIRED
20 @classmethod
21 def consume(cls, event):
22 app_source = event.context.get("application")
23 try:
24 application = models.Application(**app_source)
25 except SeamlessException as e:
26 raise exceptions.NoSuchObjectException("Unable to construct Application from supplied source - data structure validation error, {x}".format(x=e))
28 if application.owner is None:
29 return
31 svc = DOAJ.notificationsService()
33 notification = models.Notification()
34 notification.who = application.owner
35 notification.created_by = cls.ID
36 notification.classification = constants.NOTIFICATION_CLASSIFICATION_STATUS_CHANGE
37 datetime_object = datetime.strptime(application.date_applied, '%Y-%m-%dT%H:%M:%SZ')
38 date_applied = datetime_object.strftime("%d/%b/%Y")
39 notification.long = svc.long_notification(cls.ID).format(
40 application_title=application.bibjson().title,
41 date_applied=date_applied
42 )
43 notification.short = svc.short_notification(cls.ID)
45 svc.notify(notification)