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*A ticket for a single PESSTO Object give all info known about it*
6:Author:
7 David Young
8"""
10from . import ticket_building_blocks
11from . import tabs
14def single_ticket(
15 log,
16 request,
17 discoveryDataDictionary,
18 objectComments,
19 objectAkas,
20 lightcurveData,
21 atelData,
22 objectHistories,
23 transientCrossmatches):
24 """A single ticket for a transient object tin the pessto marshall
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 - ``objectComments`` -- the comments for the object
32 - ``objectAkas`` -- the akas with surveyUrls
33 - ``lightcurveData`` -- the lightcurve data for the objects displayed on the webpage
34 - ``atelData`` -- the atel matches for the objects displayed on the webpage
35 - ``objectHistories`` -- history log for object
36 - ``transientCrossmatches`` -- catalogue crossmatches (from sherlock)
39 **Return**
41 - ``ticket`` -- a single transient's info in one HTML ticket
43 """
45 log.debug('starting the ``inbox_ticket`` function')
47 import khufu
49 tabDictionary = {}
51 observationPriority = False
52 if discoveryDataDictionary["marshallWorkflowLocation"] in ["following", "pending observation"]:
53 observationPriority = discoveryDataDictionary["observationPriority"]
55 import collections
56 tabDictionary = collections.OrderedDict(sorted(tabDictionary.items()))
58 developmentTab = tabs.development.development_tab(
59 log=log,
60 request=request,
61 discoveryDataDictionary=discoveryDataDictionary,
62 objectAkas=objectAkas,
63 atelData=atelData,
64 objectHistories=objectHistories
65 )
66 if developmentTab:
67 pass
68 # tabDictionary["development"] = developmentTab
70 # GRAB THE VARIOUS TABS THAT MAKE UP A SINGLE TICKET
71 overviewTab = tabs.overview.overview_tab(
72 log=log,
73 request=request,
74 discoveryDataDictionary=discoveryDataDictionary,
75 objectComments=objectComments,
76 objectAkas=objectAkas,
77 atelData=atelData,
78 lightcurveData=lightcurveData,
79 objectHistories=objectHistories,
80 transientCrossmatches=transientCrossmatches
81 )
82 tabDictionary["overview"] = overviewTab
84 commentCount, commentsTab = tabs.comments.comments_tab(
85 log=log,
86 request=request,
87 discoveryDataDictionary=discoveryDataDictionary,
88 objectComments=objectComments,
89 objectAkas=objectAkas,
90 atelData=atelData,
91 lightcurveData=lightcurveData,
92 transientCrossmatches=transientCrossmatches
93 )
94 tabDictionary["comments"] = commentsTab
96 photometryTab = tabs.photometry.photometry_tab(
97 log=log,
98 request=request,
99 discoveryDataDictionary=discoveryDataDictionary,
100 objectAkas=objectAkas,
101 atelData=atelData,
102 lightcurveData=lightcurveData
103 )
105 tabDictionary["photometry"] = photometryTab
107 contextTab = tabs.context.context_tab(
108 log=log,
109 request=request,
110 discoveryDataDictionary=discoveryDataDictionary,
111 objectAkas=objectAkas,
112 atelData=atelData,
113 lightcurveData=lightcurveData,
114 transientCrossmatches=transientCrossmatches
115 )
117 tabDictionary["context"] = contextTab
119 historyTab = tabs.history.history_tab(
120 log=log,
121 request=request,
122 discoveryDataDictionary=discoveryDataDictionary,
123 objectAkas=objectAkas,
124 atelData=atelData,
125 objectHistories=objectHistories
126 )
127 tabDictionary["ticket history"] = historyTab
129 dryxTab = tabs.dryx.dryx_tab(
130 log=log,
131 request=request,
132 discoveryDataDictionary=discoveryDataDictionary,
133 objectAkas=objectAkas,
134 atelData=atelData,
135 objectHistories=objectHistories
136 )
137 if dryxTab:
138 tabDictionary["dryx"] = dryxTab
140 transientBucketId = discoveryDataDictionary["transientBucketId"]
142 # build the single ticket
143 ticket = _single_ticket_template(
144 log=log,
145 transientBucketId=transientBucketId,
146 tabDictionary=tabDictionary,
147 htmlId="ticket%(transientBucketId)s" % locals(),
148 commentCount=commentCount,
149 obsPriority=observationPriority
150 )
152 log.debug('completed the ``inbox_ticket`` function')
153 return ticket
156def _single_ticket_template(
157 log,
158 transientBucketId,
159 tabDictionary={}, # { "title": tabcontent, }
160 htmlId=False,
161 commentCount=False,
162 obsPriority=False
163):
164 """single_ticket
166 **Key Arguments**
168 - ``log`` -- the logger
169 - ``transientBucketId`` -- the transientBucketId of the object to be displayed
170 - ``tabDictionary`` -- a dictionary of { "title": tabcontent, }
173 **Return**
175 - ``single_ticket`` -- build the single ticket
177 """
179 import khufu
180 if commentCount is not False:
181 contentCount = {"comments": commentCount}
182 else:
183 contentCount = {}
185 if obsPriority:
186 for n, c in zip([1, 2, 3, 4], ["green", "yellow", "red", "cream"]):
187 if obsPriority == n:
188 borderColor = c
189 else:
190 borderColor = False
192 single_ticket = khufu.tabbableNavigation(
193 contentDictionary=tabDictionary, # { name : content, }
194 fadeIn=False,
195 direction='top', # [ 'top' | 'bottom' | 'left' | 'right' ]
196 htmlClass="singleTicket border-%(borderColor)s" % locals(),
197 uniqueNavigationId=transientBucketId,
198 htmlId=htmlId,
199 contentCount=contentCount
200 )
202 return single_ticket
205def _ticket_tab_template(
206 log,
207 request,
208 tabHeader=False,
209 blockList=[],
210 tabFooter=False,
211 actionsBlock=False,
212 htmlId=False
213):
214 """ticket tab - build a tab on a ticket from a few sub-block of object data
216 **Key Arguments**
218 - ``log`` -- the logger
219 - ``request`` -- the pyramid request
220 - ``tabHeader`` -- header bar for the tab
221 - ``blockList`` -- the list of asset 'blocks' to be included in this ticket tab
222 - ``tabFooter`` -- footer bar for the tab
223 - ``actionsBlock`` -- to consume skinny column at right side
226 **Return**
228 - ``ticket_tab`` -- template for each ticket tab
230 """
231 import khufu
232 theseBlocks = ""
234 # REMOVE EMPTY BLOCKS
235 newBlockList = []
236 for block in blockList:
237 if block is not None:
238 newBlockList.append(block)
239 blockList = newBlockList
241 actionsExist = 0
242 if actionsBlock is not False:
243 actionsExist = 1
245 # EXPAND AND CONTRACT BLOCK SIZES DEPENDING ON HOW MANY BLOCKS THERE ARE
246 span = int(round(12. / (len(blockList) + actionsExist) - 0.5))
247 remainingSpans = 12 - span * len(blockList) - actionsExist
249 count = 1
250 for block in blockList:
251 thisSpan = span
252 if count < remainingSpans:
253 thisSpan = span + 1
254 count += 1
255 if thisSpan == 12:
256 if "overviewWell" in block:
257 thisSpan = 11
259 block = khufu.grid_column(
260 span=thisSpan,
261 offset=0, # 1-12
262 content=block,
263 htmlId=False,
264 htmlClass="ticketBlocks",
265 onPhone=True,
266 onTablet=True,
267 onDesktop=True
268 )
269 theseBlocks = "%(theseBlocks)s%(block)s" % locals()
271 if actionsBlock is not False:
272 actionsBlock = khufu.grid_column(
273 span=1,
274 offset=0, # 1-12
275 content=actionsBlock,
276 htmlId=False,
277 htmlClass="ticketBlocks",
278 onPhone=True,
279 onTablet=True,
280 onDesktop=True
281 )
283 theseBlocks = "%(theseBlocks)s%(actionsBlock)s" % locals()
285 if tabHeader == False:
286 tabHeader = u""
287 if tabFooter == False:
288 tabFooter = ""
290 if htmlId is False:
291 htmlId = ""
293 ticket_tab = khufu.grid_row(
294 responsive=True,
295 columns=u"%(tabHeader)s %(theseBlocks)s %(tabFooter)s" % locals(
296 ),
297 htmlId=False,
298 htmlClass=htmlId,
299 onPhone=True,
300 onTablet=True,
301 onDesktop=True
302 )
304 return ticket_tab