Coverage for portality/models/atom.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-22 15:59 +0100

1from portality.models import Journal 

2from copy import deepcopy 

3 

4class AtomRecord(Journal): 

5 records = { 

6 "query" : { 

7 "bool" : { 

8 "must" : [ 

9 {"term" : {"admin.in_doaj" : True}}, 

10 # { "range" : { "last_updated" : {"gte" : "<from date>"} } } 

11 { "range" : { "created_date" : {"gte" : "<from date>"} } } 

12 ] 

13 } 

14 }, 

15 "size" : 20, 

16 # "sort" : {"last_updated" : {"order" : "desc"}} 

17 "sort" : {"created_date" : {"order" : "desc"}} 

18 } 

19 

20 def list_records(self, from_date, list_size): 

21 q = deepcopy(self.records) 

22 # q["query"]["bool"]["must"][1]["range"]["last_updated"]["gte"] = from_date 

23 q["query"]["bool"]["must"][1]["range"]["created_date"]["gte"] = from_date 

24 q["size"] = list_size 

25 

26 # do the query 

27 # print json.dumps(q) 

28 results = self.query(q=q) 

29 

30 return [AtomRecord(**hit.get("_source")) for hit in results.get("hits", {}).get("hits", [])]