Coverage for portality / events / consumers / application_publisher_created_notify.py: 92%

36 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-04 09:41 +0100

1# ~~ApplicationPublisherCreatedNotify:Notifications~~ 

2from portality.events import consumer_utils 

3from portality.util import url_for 

4from portality.lib import dates 

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 

10 

11 

12class ApplicationPublisherCreatedNotify(EventConsumer): 

13 ID = "application:publisher:created:notify" 

14 

15 @classmethod 

16 def should_consume(cls, event): 

17 return event.id == constants.EVENT_APPLICATION_CREATED and event.context.get("application") is not None 

18 

19 @classmethod 

20 def consume(cls, event): 

21 context = event.context 

22 app = context.get("application") 

23 if app is None: 

24 return None 

25 try: 

26 application = models.Application(**app) 

27 except SeamlessException: 

28 raise exceptions.NoSuchObjectException("Could not create application object") 

29 if application is None: 

30 raise exceptions.NoSuchObjectException("Could not create application object") 

31 if not application.owner: 

32 return None 

33 

34 # ~~-> Notifications:Service ~~ 

35 svc = DOAJ.notificationsService() 

36 

37 notification = models.Notification() 

38 notification.who = application.owner 

39 notification.created_by = cls.ID 

40 notification.classification = constants.NOTIFICATION_CLASSIFICATION_CREATE 

41 notification.long = svc.long_notification(cls.ID).format(title=application.bibjson().title, 

42 journal_url=application.bibjson().journal_url, 

43 application_date=dates.human_date(application.date_applied), 

44 volunteers_url=url_for("doaj.volunteers")) 

45 notification.short = svc.short_notification(cls.ID).format( 

46 issns=application.bibjson().issns_as_text() 

47 ) 

48 

49 svc.notify(notification) 

50 return notification