Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/local/bin/python 

2# encoding: utf-8 

3""" 

4*The model get for the `models_xmatches_catalogues_get.py` resource* 

5 

6:Author: 

7 David Young 

8""" 

9from future import standard_library 

10standard_library.install_aliases() 

11from builtins import zip 

12from builtins import object 

13import sys 

14import os 

15import khufu 

16import collections 

17import urllib.request 

18import urllib.parse 

19import urllib.error 

20import re 

21from dryxPyramid.models.models_base import base_model 

22 

23class models_xmatches_catalogues_get(base_model): 

24 """ 

25 The worker class for the models_xmatches_catalogues_get module 

26 

27 **Key Arguments** 

28 

29 - ``log`` -- logger 

30 - ``request`` -- the pyramid request 

31 - ``elementId`` -- the specific element id requests (or False) 

32  

33 """ 

34 

35 def __init__(self, log, request, elementId=False, search=False): 

36 super().__init__(log, request, elementId, search) 

37 self.resourceName = "xmatches_catalogues" 

38 

39 self.defaultQs = { 

40 "sortBy": "catalogue_table_id", 

41 "sortDesc": True 

42 } 

43 self._set_default_parameters() 

44 

45 log.debug( 

46 "instansiating a new 'models_xmatches_catalogues_get' object") 

47 return None 

48 

49 def get(self): 

50 """execute the get method on the models_xmatches_catalogues_get object 

51 

52 **Return** 

53 

54 - ``responseContent`` -- the reponse to send to the browser 

55  

56 """ 

57 self.log.debug('starting the ``get`` method') 

58 

59 sortBy = self.qs["sortBy"] 

60 if self.qs["sortDesc"] == True or self.qs["sortDesc"].lower() == "true": 

61 sortDesc = "desc" 

62 else: 

63 sortDesc = "" 

64 

65 sqlQuery = u""" 

66 SELECT  

67 * 

68 FROM 

69 (SELECT  

70 a.catalogue_table_id, 

71 a.catalogue_table_name, 

72 a.all_count, 

73 COALESCE(top_rank_count, 0) AS `top_rank_count` 

74 FROM 

75 (SELECT  

76 COUNT(*) AS all_count, 

77 catalogue_table_name, 

78 catalogue_table_id 

79 FROM 

80 sherlock_crossmatches 

81 GROUP BY catalogue_table_name) AS a 

82 LEFT JOIN (SELECT  

83 COUNT(*) AS `top_rank_count`, 

84 catalogue_table_name, 

85 catalogue_table_id 

86 FROM 

87 sherlock_crossmatches 

88 WHERE 

89 rank = 1 

90 GROUP BY catalogue_table_name) AS b ON a.catalogue_table_id = b.catalogue_table_id) AS s order by %(sortBy)s %(sortDesc)s 

91 """ % locals() 

92 objectDataTmp = self.request.db.execute(sqlQuery).fetchall() 

93 objectData = [] 

94 objectData[:] = [dict(list(zip(list(row.keys()), row))) 

95 for row in objectDataTmp] 

96 

97 responseContent = objectData 

98 

99 self.log.debug('completed the ``get`` method') 

100 return responseContent 

101 

102 # xt-class-method