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_views.py` resource*
6:Author:
7 David Young
8"""
9from __future__ import absolute_import
10from builtins import zip
11from builtins import object
12import sys
13import os
14import khufu
15import re
16from marshall_webapp.models.xmatches_views import models_xmatches_views_get
17from marshall_webapp.models.xmatches_views.element import models_xmatches_element_views_get
19class templates_xmatches_views(object):
20 """
21 The worker class for the templates_xmatches_views module
23 **Key Arguments**
25 - ``log`` -- logger
26 - ``request`` -- the pyramid request
27 - ``elementId`` -- the element id of the resource requested (or false)
29 """
31 def __init__(
32 self,
33 log,
34 request,
35 elementId=False,
36 format=False
37 ):
38 self.log = log
39 self.request = request
40 self.elementId = elementId
41 # xt-self-arg-tmpx
43 log.debug(
44 "instansiating a new 'templates_xmatches_views' object")
46 return None
48 def get(self):
49 """get the templates_xmatches_views object
51 **Return**
53 - ``webpage`` -- the webpage
55 """
56 self.log.debug('starting the ``get`` method')
58 from marshall_webapp.templates.commonelements.pagetemplates import defaultpagetemplate
60 if self.elementId == False:
61 xmatches_views = models_xmatches_views_get(
62 log=self.log,
63 request=self.request
64 )
65 self.catalogues = xmatches_views.get()
67 from marshall_webapp.templates.commonelements.pagetemplates import defaultpagetemplate
69 # add text color
70 text = khufu.coloredText(
71 text="<BR>Click on the <em>associated transient</em> links to reveal matched transient tickets<br><br>",
72 color="grey",
73 size=4, # 1-10
74 pull="right", # "left" | "right",
75 addBackgroundColor=False
76 )
78 maincontent = text + self.create_table()
80 webpage = defaultpagetemplate(
81 log=self.log,
82 request=self.request,
83 bodyId=False,
84 pageTitle="ePESSTO+ Marshall",
85 topNavBar=False,
86 sideBar="xmatches",
87 mainContent=maincontent,
88 relativePathFromDocRoot=False,
89 thisPageName="xmatches"
90 )
91 else:
92 from .templates_resources_transients import templates_resources_transients
93 webpage = templates_resources_transients(
94 log=self.log,
95 request=self.request,
96 tcsCatalogueId=self.elementId
97 ).get()
99 self.log.debug('completed the ``get`` method')
100 return webpage
102 def create_table(
103 self):
104 """create table
106 **Return**
108 - ``table``
110 """
111 self.log.debug('starting the ``create_table`` method')
113 columnsNames = ["Catalogue", "Sources", "Number Rows",
114 "Associated Transients", "Top Rank Associated Transients"]
115 columnsNamesDB = ["table_name", "object_types", "number_of_rows",
116 "all_transient_associations", "top_ranked_transient_associations"]
118 for row in self.catalogues:
119 row["table_name"] = row["table_name"].replace("tcs_cat_", "")
120 matchObject = re.finditer(
121 r'.*_(v\d.*)',
122 row["table_name"],
123 flags=0 # re.S
124 )
125 for match in matchObject:
126 replaceMe = match.group(1).replace("_", ".")
127 row["table_name"] = row["table_name"].replace(
128 match.group(1), replaceMe)
130 row["table_name"] = row["table_name"].replace(
131 "_", " ").replace(" final", "")
133 for k, v in list(dict(row).items()):
134 if isinstance(v, float):
135 row[k] = "{:,.0f}".format(v)
137 href = self.request.route_path(
138 'xmatches_element_views', elementId=row["table_id"])
139 row["all_transient_associations"] = khufu.a(
140 content=row["all_transient_associations"],
141 href=href
142 )
144 href = self.request.route_path(
145 'xmatches_element_views', elementId=row["table_id"], )
146 row["all_transient_associations"] = khufu.a(
147 content=row["all_transient_associations"],
148 href=href
149 )
151 href = self.request.route_path('xmatches_element_views', elementId=row[
152 "table_id"], _query={'tcsRank': 1})
153 row["top_ranked_transient_associations"] = khufu.a(
154 content=row["top_ranked_transient_associations"],
155 href=href
156 )
158 import khufu.tables.sortable_table as sortable_table
159 # build a sortable table
160 table = sortable_table(
161 currentPageUrl=self.request.path_qs,
162 columnsToDisplay=columnsNamesDB,
163 tableRowsDictionary=self.catalogues,
164 log=self.log,
165 defaultSort=False
166 )
168 # REPLACE COLUMN NAMES WITH DISPLAY NAMES (E.G. FOR WHEN MYSQL COLUMN
169 # NAMES ARE USED)
170 nd = table.modifyDisplayNameDict
171 for o, n in zip(columnsNamesDB, columnsNames):
172 nd[o] = n
174 table = table.get()
176 self.log.debug('completed the ``create_table`` method')
177 return table
179 # xt-class-method