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 HTML template module for the `templates_xmatches_catalogues.py` resource*
6:Author:
7 David Young
8"""
9from __future__ import print_function
10from __future__ import absolute_import
11from builtins import zip
12from builtins import object
13import sys
14import os
15import khufu
16import re
17from marshall_webapp.models.xmatches_catalogues import models_xmatches_catalogues_get
18from marshall_webapp.models.xmatches_catalogues.element import models_xmatches_element_catalogues_get
20class templates_xmatches_catalogues(object):
21 """
22 The worker class for the templates_xmatches_catalogues module
24 **Key Arguments**
26 - ``log`` -- logger
27 - ``request`` -- the pyramid request
28 - ``elementId`` -- the element id of the resource requested (or false)
30 """
32 def __init__(
33 self,
34 log,
35 request,
36 elementId=False,
37 format=False
38 ):
39 self.log = log
40 self.request = request
41 self.elementId = elementId
42 # xt-self-arg-tmpx
44 log.debug(
45 "instansiating a new 'templates_xmatches_catalogues' object")
47 return None
49 def get(self):
50 """get the templates_xmatches_catalogues object
52 **Return**
54 - ``webpage`` -- the webpage
56 """
57 self.log.debug('starting the ``get`` method')
59 from marshall_webapp.templates.commonelements.pagetemplates import defaultpagetemplate
61 if self.elementId == False:
62 xmatches_catalogues = models_xmatches_catalogues_get(
63 log=self.log,
64 request=self.request
65 )
66 self.catalogues = xmatches_catalogues.get()
68 from marshall_webapp.templates.commonelements.pagetemplates import defaultpagetemplate
70 # add text color
71 text = khufu.coloredText(
72 text="<BR>Click on the <em>associated transient</em> links to reveal matched transient tickets<br><br>",
73 color="grey",
74 size=4, # 1-10
75 pull="right", # "left" | "right",
76 addBackgroundColor=False
77 )
79 maincontent = text + self.create_table()
81 webpage = defaultpagetemplate(
82 log=self.log,
83 request=self.request,
84 bodyId=False,
85 pageTitle="ePESSTO+ Marshall",
86 topNavBar=False,
87 sideBar="xmatches",
88 mainContent=maincontent,
89 relativePathFromDocRoot=False,
90 thisPageName="xmatches"
91 )
92 else:
93 from .templates_resources_transients import templates_resources_transients
94 webpage = templates_resources_transients(
95 log=self.log,
96 request=self.request,
97 tcsCatalogueId=self.elementId
98 ).get()
100 self.log.debug('completed the ``get`` method')
101 return webpage
103 def create_table(
104 self):
105 """create table
107 **Return**
109 - ``table``
111 """
112 self.log.debug('starting the ``create_table`` method')
114 columnsNames = ["Catalogue",
115 "Associated Transients", "Top Rank Associated Transients"]
116 columnsNamesDB = ["catalogue_table_name",
117 "all_count", "top_rank_count"]
119 for row in self.catalogues:
120 print(row)
121 matchObject = re.finditer(
122 r'.*_(v\d.*)',
123 row["catalogue_table_name"],
124 flags=0 # re.S
125 )
127 for k, v in list(dict(row).items()):
128 if isinstance(v, float):
129 row[k] = "{:,.0f}".format(v)
131 href = self.request.route_path(
132 'xmatches_element_catalogues', elementId=row["catalogue_table_id"])
133 row["all_count"] = khufu.a(
134 content=row["all_count"],
135 href=href
136 )
138 href = self.request.route_path(
139 'xmatches_element_catalogues', elementId=row["catalogue_table_id"], )
140 row["all_count"] = khufu.a(
141 content=row["all_count"],
142 href=href
143 )
145 href = self.request.route_path('xmatches_element_catalogues', elementId=row[
146 "catalogue_table_id"], _query={'tcsRank': 1})
147 row["top_rank_count"] = khufu.a(
148 content=row["top_rank_count"],
149 href=href
150 )
152 import khufu.tables.sortable_table as sortable_table
153 # build a sortable table
154 table = sortable_table(
155 currentPageUrl=self.request.path_qs,
156 columnsToDisplay=columnsNamesDB,
157 tableRowsDictionary=self.catalogues,
158 log=self.log,
159 defaultSort=False
160 )
162 # REPLACE COLUMN NAMES WITH DISPLAY NAMES (E.G. FOR WHEN MYSQL COLUMN
163 # NAMES ARE USED)
164 nd = table.modifyDisplayNameDict
165 for o, n in zip(columnsNamesDB, columnsNames):
166 nd[o] = n
168 table = table.get()
170 self.log.debug('completed the ``create_table`` method')
171 return table
173 # xt-class-method