Coverage for portality / events / consumers / journal_assed_assigned_notify.py: 100%

30 statements  

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

1# ~~JournalAssedAssignedNotify:Consumer~~ 

2from portality.events import consumer_utils 

3from portality.util import url_for 

4 

5from portality.events.consumer import EventConsumer 

6from portality import constants 

7from portality import models 

8from portality.bll import DOAJ 

9from portality.bll import exceptions 

10 

11 

12class JournalAssedAssignedNotify(EventConsumer): 

13 ID = "journal:assed:assigned:notify" 

14 

15 @classmethod 

16 def should_consume(cls, event): 

17 return event.id == constants.EVENT_JOURNAL_ASSED_ASSIGNED and \ 

18 event.context.get("journal") is not None 

19 

20 @classmethod 

21 def consume(cls, event): 

22 j_source = event.context.get("journal") 

23 

24 try: 

25 journal = models.Journal(**j_source) 

26 except Exception as e: 

27 raise exceptions.NoSuchObjectException("Unable to construct Journal from supplied source - data structure validation error, {x}".format(x=e)) 

28 

29 if not journal.editor: 

30 raise exceptions.NoSuchPropertyException("Journal {x} does not have property `editor`".format(x=journal.id)) 

31 

32 # ~~-> Notifications:Service ~~ 

33 svc = DOAJ.notificationsService() 

34 

35 notification = models.Notification() 

36 notification.who = journal.editor 

37 notification.created_by = cls.ID 

38 notification.classification = constants.NOTIFICATION_CLASSIFICATION_ASSIGN 

39 notification.long = svc.long_notification(cls.ID).format( 

40 journal_name=journal.bibjson().title, 

41 group_name=journal.editor_group 

42 ) 

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

44 issns=journal.bibjson().issns_as_text() 

45 ) 

46 

47 # No action possible due to page removed (see portality.view.editor.journal_page(journal_id)) 

48 # notification.action = url_for("editor.journal_page", journal_id=journal.id) 

49 

50 svc.notify(notification) 

51 return notification