Coverage for apps/ptf/solr/solrparams.py: 0%

41 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2024-02-28 09:09 +0000

1class SolrRequest: 

2 def __init__(self, request, q="", alias=None, site=None, default={}): 

3 if not q: 

4 self.q = request.GET.get("q", None) 

5 else: 

6 self.q = q 

7 self.filters = request.GET.getlist("f") 

8 self.ifilters = [] # filtres implicites 

9 self.path = alias or request.path 

10 self.site = site 

11 self.params = get_params(request, default=default) 

12 

13 def add_implicit_filter(self, filter): 

14 self.ifilters.append(filter) 

15 

16 

17class FilterRequest: 

18 def __init__(self, request, filters, site=None, default={}): 

19 self.q = None 

20 self.filters = filters 

21 self.ifilters = [] # filtres implicites 

22 self.path = "/select/" 

23 self.site = site 

24 self.params = get_params(request, default=default) 

25 

26 

27def get_params(request, default={}): 

28 try: 

29 page = int(request.GET.get("page", 1)) 

30 except BaseException: 

31 page = 1 

32 rows = 20 

33 start = (page - 1) * rows 

34 sort = request.GET.get("order_by", default.get("sort", None)) 

35 params = {"page": page, "start": start, "rows": rows} 

36 if sort is not None: 

37 solr_sort = [] 

38 sort = sort.split(",") 

39 for spec in sort: 

40 spec = spec.strip() 

41 if spec[0] == "-": 

42 spec = f"{spec[1:]} desc" 

43 else: 

44 spec = f"{spec} asc" 

45 solr_sort.append(spec) 

46 params["sort"] = ", ".join(solr_sort) 

47 params["fl"] = ["id"] 

48 return params