Coverage for portality / events / consumers / application_publisher_inprogress_notify.py: 97%
35 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-04 09:41 +0100
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-04 09:41 +0100
1# ~~ApplicationPublisherInProgressNotify:Consumer~~
2from portality.events import consumer_utils
3from portality.util import url_for
4from portality.core import app
5from portality.events.consumer import EventConsumer
6from portality import constants
7from portality import models
8from portality.bll import DOAJ, exceptions
9from portality.lib.seamless import SeamlessException
10from portality.lib.dates import human_date
12class ApplicationPublisherInprogressNotify(EventConsumer):
13 ID = "application:publisher:inprogress:notify"
15 @classmethod
16 def should_consume(cls, event):
17 return event.id == constants.EVENT_APPLICATION_STATUS and \
18 event.context.get("application") is not None and \
19 event.context.get("old_status") == constants.APPLICATION_STATUS_PENDING and \
20 event.context.get("new_status") == constants.APPLICATION_STATUS_IN_PROGRESS
22 @classmethod
23 def consume(cls, event):
24 app_source = event.context.get("application")
25 try:
26 application = models.Application(**app_source)
27 except SeamlessException as e:
28 raise exceptions.NoSuchObjectException("Unable to construct Application from supplied source - data structure validation error, {x}".format(x=e))
30 if application.owner is None:
31 return None
33 # ~~-> Notifications:Service ~~
34 svc = DOAJ.notificationsService()
36 notification = models.Notification()
37 notification.who = application.owner
38 notification.created_by = cls.ID
39 notification.classification = constants.NOTIFICATION_CLASSIFICATION_STATUS_CHANGE
41 title = application.bibjson().title
42 date_applied = human_date(application.date_applied)
43 volunteers = app.config.get("BASE_URL") + url_for("doaj.volunteers")
45 notification.long = svc.long_notification(cls.ID).format(
46 title=title,
47 date_applied=date_applied,
48 volunteers_url=volunteers
49 )
50 notification.short = svc.short_notification(cls.ID).format(
51 issns=application.bibjson().issns_as_text()
52 )
54 svc.notify(notification)
55 return notification