Coverage for portality/events/consumers/application_publisher_quickreject_notify.py: 100%
34 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
3from datetime import datetime
5from portality.events.consumer import EventConsumer
6from portality import constants
7from portality import models
8from portality.bll import DOAJ, exceptions
9from portality.core import app
12class ApplicationPublisherQuickRejectNotify(EventConsumer):
13 ID = "application:publisher:quickreject:notify"
15 @classmethod
16 def consumes(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_REJECTED and \
20 event.context.get("new_status") == constants.APPLICATION_STATUS_REJECTED and \
21 event.context.get("process") == constants.PROCESS__QUICK_REJECT
23 @classmethod
24 def consume(cls, event):
25 app_source = event.context.get("application")
26 note = event.context.get("note")
27 if note:
28 note = "\n\n**Reason for rejection**\n\n" + note + "\n\n"
30 try:
31 application = models.Application(**app_source)
32 except Exception as e:
33 raise exceptions.NoSuchObjectException("Unable to construct Application from supplied source - data structure validation error, {x}".format(x=e))
35 if not application.owner:
36 return
38 svc = DOAJ.notificationsService()
40 notification = models.Notification()
41 notification.who = application.owner
42 notification.created_by = cls.ID
43 notification.classification = constants.NOTIFICATION_CLASSIFICATION_STATUS_CHANGE
44 datetime_object = datetime.strptime(application.date_applied, '%Y-%m-%dT%H:%M:%SZ')
45 date_applied = datetime_object.strftime("%d/%b/%Y")
46 notification.long = svc.long_notification(cls.ID).format(
47 title=application.bibjson().title,
48 date_applied=date_applied,
49 note=note,
50 doaj_guide_url=app.config.get('BASE_URL', "https://doaj.org") + url_for("doaj.guide")
51 )
52 notification.short = svc.short_notification(cls.ID)
54 # there is no action url for this notification
56 svc.notify(notification)