Coverage for portality / events / consumers / application_publisher_quickreject_notify.py: 100%
34 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# ~~ApplicationPublisherQuickRejectNotify:Consumer~~
2from portality.events import consumer_utils
3from portality.lib import dates
4from portality.lib.dates import FMT_DATE_HUMAN_A
5from portality.util import url_for
7from portality.events.consumer import EventConsumer
8from portality import constants
9from portality import models
10from portality.bll import DOAJ, exceptions
11from portality.core import app
14class ApplicationPublisherQuickRejectNotify(EventConsumer):
15 ID = "application:publisher:quickreject:notify"
17 @classmethod
18 def should_consume(cls, event):
19 return event.id == constants.EVENT_APPLICATION_STATUS and \
20 event.context.get("application") is not None and \
21 event.context.get("old_status") != constants.APPLICATION_STATUS_REJECTED and \
22 event.context.get("new_status") == constants.APPLICATION_STATUS_REJECTED and \
23 event.context.get("process") == constants.PROCESS__QUICK_REJECT
25 @classmethod
26 def consume(cls, event):
27 app_source = event.context.get("application")
28 note = event.context.get("note")
29 if note:
30 note = "\n\n**Reason for rejection**\n\n" + note + "\n\n"
32 application = consumer_utils.parse_application(app_source)
33 if not application.owner:
34 return None
36 # ~~-> Notifications:Service ~~
37 svc = DOAJ.notificationsService()
39 notification = models.Notification()
40 notification.who = application.owner
41 notification.created_by = cls.ID
42 notification.classification = constants.NOTIFICATION_CLASSIFICATION_STATUS_CHANGE
43 datetime_object = dates.parse(application.date_applied)
44 date_applied = datetime_object.strftime(FMT_DATE_HUMAN_A)
45 notification.long = svc.long_notification(cls.ID).format(
46 title=application.bibjson().title,
47 date_applied=date_applied,
48 note=note if note is not None else "",
49 doaj_guide_url=app.config.get('BASE_URL', "https://doaj.org") + url_for("doaj.guide")
50 )
51 notification.short = svc.short_notification(cls.ID).format(
52 issns=application.bibjson().issns_as_text()
53 )
55 # there is no action url for this notification
57 svc.notify(notification)
58 return notification