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 history tab for the PESSTO Object tickets*
6:Author:
7 David Young
8"""
9import sys
10import os
11import re
12import datetime
13from fundamentals import times
14import khufu
17def history_tab(
18 log,
19 request,
20 discoveryDataDictionary,
21 objectAkas,
22 atelData,
23 objectHistories):
24 """history tab
26 **Key Arguments**
28 - ``log`` -- logger
29 - ``request`` -- the pyramid request
30 - ``discoveryDataDictionary`` -- the unique discoveryData dictionary of the object in the pessto marshall database (from view_object_contextual_data)
31 - ``objectAkas`` -- object akas
32 - ``objectHistories`` -- the lightcurve data for the objects displayed on the webpage
33 - ``atelData`` -- the atel matches for the objects displayed on the webpage
36 **Return**
38 - ``history_tab`` -- for each transient ticket in the transient listings pages
40 """
41 from time import strftime
42 from marshall_webapp.templates.commonelements.tickets.single_ticket import ticket_building_blocks, tabs
43 from marshall_webapp.templates.commonelements.tickets import single_ticket
44 from marshall_webapp.templates.commonelements import forms
46 log.debug('starting the ``history_tab`` function')
48 theseHistories = []
49 theseHistories[:] = [t for t in objectHistories]
51 transientBucketId = discoveryDataDictionary["transientBucketId"]
52 content = ""
54 # determine date added to the marshall
55 dateAddedToMarshall = discoveryDataDictionary["dateAdded"]
56 objectAddedToMarshallBy = discoveryDataDictionary[
57 "objectAddedToMarshallBy"]
58 if not objectAddedToMarshallBy or objectAddedToMarshallBy.lower() == "none":
59 thisLog = "object added to the 'inbox' via the marshall's automatic import scripts"
60 if discoveryDataDictionary["decDeg"] > 30.:
61 thisLog = "object added directly to the 'archive' via the marshall's automatic import scripts (> +30 dec)"
62 else:
63 thisLog = "object added to the 'inbox' by %(objectAddedToMarshallBy)s" % locals(
64 )
65 if discoveryDataDictionary["lsq_lightcurve"]:
66 newEntry = {
67 "transientBucketId": transientBucketId,
68 "dateCreated": dateAddedToMarshall,
69 "log": "LSQ's recalibrated data added to marshall" % locals(
70 )
71 }
72 else:
73 newEntry = {
74 "transientBucketId": transientBucketId,
75 "dateCreated": dateAddedToMarshall,
76 "log": "%(thisLog)s" % locals(
77 )
78 }
79 theseHistories.append(newEntry)
81 # determine date classified
82 classificationDate = discoveryDataDictionary["classificationAddedDate"]
83 classificationSurvey = discoveryDataDictionary["classificationSurvey"]
84 classificationAddedBy = discoveryDataDictionary["classificationAddedBy"]
85 objectAddedToMarshallBy = discoveryDataDictionary[
86 "objectAddedToMarshallBy"]
87 if classificationDate:
88 newEntry = {
89 "transientBucketId": transientBucketId,
90 "dateCreated": classificationDate,
91 "log": "object classified by %(classificationSurvey)s (classification added by %(classificationAddedBy)s)" % locals(
92 )
93 }
94 theseHistories.append(newEntry)
96 from operator import itemgetter
97 theseHistories = sorted(
98 theseHistories, key=itemgetter('dateCreated'), reverse=False)
100 for hLog in theseHistories:
102 if hLog["transientBucketId"] == transientBucketId:
103 content += _generate_log_string_for_ticket(
104 log=log,
105 logDate=hLog["dateCreated"],
106 logString=hLog["log"])
108 regex = re.compile(r'by (\w*)\.\s+(\w*)')
109 content = regex.sub(lambda match: "by " + match.group(1)[0].upper(
110 ) + match.group(1)[1:] + " " + match.group(2)[0].upper() + match.group(2)[1:], content)
112 history_tab = single_ticket._ticket_tab_template(
113 log,
114 request=request,
115 tabHeader=False,
116 blockList=[content + "<br>"],
117 tabFooter=False,
118 htmlId="historytab"
119 )
121 log.debug('completed the ``history_tab`` function')
122 return history_tab
125def _generate_log_string_for_ticket(
126 log,
127 logDate,
128 logString):
129 """ generate log string for ticket
131 **Key Arguments**
133 - ``log`` -- logger
135 """
136 log.debug('starting the ``_generate_log_string_for_ticket`` function')
138 if logDate:
139 relativeDate = times.datetime_relative_to_now(logDate)
140 logDate = logDate.strftime('%Y-%m-%d %H:%M:%S')
141 else:
142 relativeDate = "?"
143 logDate = "?"
145 # add text color
146 logDate = khufu.coloredText(
147 text=logDate,
148 color="green",
149 size=3, # 1-10
150 pull=False, # "left" | "right",
151 addBackgroundColor=False
152 )
153 # add text color
154 relativeDate = khufu.coloredText(
155 text="(" + relativeDate.strip() + ")",
156 color="violet",
157 size=3, # 1-10
158 pull=False, # "left" | "right",
159 addBackgroundColor=False
160 )
162 # add text color
163 logString = khufu.coloredText(
164 text=logString,
165 color="cream",
166 size=3, # 1-10
167 pull=False, # "left" | "right",
168 addBackgroundColor=False
169 )
170 logString = """<strong>%(logDate)s</strong>   %(relativeDate)s   %(logString)s""" % locals(
171 )
172 column = khufu.grid_column(
173 span=10, # 1-12
174 offset=1, # 1-12
175 content=logString,
176 pull=False, # ["right", "left", "center"]
177 htmlId=False,
178 htmlClass=False,
179 onPhone=True,
180 onTablet=True,
181 onDesktop=True
182 )
183 grid_row = khufu.grid_row(
184 responsive=True,
185 columns=column,
186 htmlId=False,
187 htmlClass=False,
188 onPhone=True,
189 onTablet=True,
190 onDesktop=True
191 )
193 log.debug('completed the ``_generate_log_string_for_ticket`` function')
194 return grid_row
196# xt-def-with-logger