Coverage for portality/api/current/data_objects/journal.py: 71%

21 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-20 16:12 +0100

1from portality import models 

2 

3from portality.api.current.data_objects.common_journal_application import OutgoingCommonJournalApplication, _SHARED_STRUCT 

4 

5# we only have outgoing journals for the moment 

6from portality.lib.coerce import COERCE_MAP 

7 

8JOURNAL_STRUCT = { 

9 "objects": ["bibjson", "admin"], 

10 "fields": { 

11 "id": {"coerce": "unicode"}, 

12 "created_date": {"coerce": "utcdatetime"}, 

13 "last_updated": {"coerce": "utcdatetime"}, 

14 "last_manual_update": {"coerce": "utcdatetime"}, 

15 "es_type": {"coerce": "unicode"} 

16 }, 

17 "structs": { 

18 "admin": { 

19 "fields": { 

20 "in_doaj": {"coerce": "bool", "get__default": False}, 

21 "ticked": {"coerce": "bool", "get__default": False}, 

22 "seal": {"coerce": "bool", "get__default": False} 

23 } 

24 } 

25 } 

26} 

27 

28 

29class OutgoingJournal(OutgoingCommonJournalApplication): 

30 """ 

31 ~~APIOutgoingJournal:Model->APIOutgoingCommonJournalApplication:Model~~ 

32 ~~->Journal:Model~~ 

33 """ 

34 __SEAMLESS_COERCE__ = COERCE_MAP 

35 __SEAMLESS_STRUCT__ = [ 

36 JOURNAL_STRUCT, 

37 _SHARED_STRUCT 

38 ] 

39 

40 def __init__(self, raw=None, **kwargs): 

41 super(OutgoingJournal, self).__init__(raw, silent_prune=True, **kwargs) 

42 

43 @classmethod 

44 def from_model(cls, jm): 

45 assert isinstance(jm, models.Journal) 

46 d = super(OutgoingJournal, cls).from_model(jm) 

47 return d 

48 

49 @classmethod 

50 def from_model_by_id(cls, id_): 

51 j = models.Journal.pull(id_) 

52 return cls.from_model(j) 

53 

54 @property 

55 def data(self): 

56 return self.__seamless__.data