Coverage for portality / events / consumers / article_ris_generator.py: 100%
16 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# ~~ AccountCreatedEmail:Consumer ~~
2from portality.bll import DOAJ
3from portality.events.consumer import EventConsumer
4from portality import constants, models
7class ArticleRISGenerator(EventConsumer):
8 ID = "article:ris_generator"
10 @classmethod
11 def should_consume(cls, event):
12 return event.id == constants.EVENT_ARTICLE_SAVE and event.context.get("article") is not None
14 @classmethod
15 def consume(cls, event):
16 context = event.context
18 if "article" not in context:
19 raise Exception("No article found in event context")
21 # this could raise an exception, which will cause the event not be be consumed, and will be
22 # caught and logged at the level above
23 article = models.Article(**context.get("article"))
25 exportSvc = DOAJ.exportService()
26 exportSvc.ris(article, save=True)