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 actions block for the marshall object tickets*
6:Author:
7 David Young
8"""
9import sys
10import os
11from datetime import datetime, date, time
12import khufu
13from marshall_webapp.templates.commonelements import commonutils as cu
14import urllib.parse
17def actions_block(
18 log,
19 request,
20 discoveryDataDictionary,
21 lightcurveData,
22 objectAkas):
23 """get ticket action block
25 **Key Arguments**
27 - ``log`` -- logger
28 - ``request`` -- the pyramid request
29 - ``lightcurveData`` -- the lightdata for the object
30 - ``discoveryDataDictionary`` -- a dictionary of the discovery data for this transient.
33 **Return**
35 - ``action_block`` -- the ticket identity block for the pesssto object
37 """
38 from marshall_webapp.templates.commonelements import forms
39 title = cu.block_title(
40 log,
41 title="actions"
42 )
44 buttonList = []
46 moveToDropdown = _get_move_to_dropdown(
47 log=log,
48 request=request,
49 discoveryDataDictionary=discoveryDataDictionary,
50 )
52 alertDropdown = _get_alert_dropdown(
53 log=log,
54 request=request,
55 discoveryDataDictionary=discoveryDataDictionary,
56 )
58 classifyButton, classifyForm = _get_classify_button(
59 log=log,
60 request=request,
61 discoveryDataDictionary=discoveryDataDictionary,
62 )
64 if not classifyButton:
65 classifyButton = ""
66 classifyForm = ""
68 changePiButton = ""
69 if discoveryDataDictionary["classifiedFlag"] == 1:
70 changePiButton = _get_change_pi_button(
71 log=log,
72 request=request,
73 discoveryDataDictionary=discoveryDataDictionary,
74 )
76 generateOBButton = ""
77 if discoveryDataDictionary["classifiedFlag"] == 0:
78 generateOBButton = _generate_ob_button(
79 log=log,
80 request=request,
81 discoveryDataDictionary=discoveryDataDictionary,
82 lightcurveData=lightcurveData,
83 objectAkas=objectAkas,
84 )
86 changePriorityDropdown = ""
87 if discoveryDataDictionary["marshallWorkflowLocation"] in ["pending observation", "allObsQueue", "following"]:
88 changePriorityDropdown = _get_priority_switcher_dropdown(
89 log=log,
90 request=request,
91 discoveryDataDictionary=discoveryDataDictionary,
92 )
94 snoozeButton = ""
95 if discoveryDataDictionary["marshallWorkflowLocation"].lower() == "inbox":
96 snoozeButton = _snooze_button(
97 log=log,
98 request=request,
99 discoveryDataDictionary=discoveryDataDictionary,
100 )
102 buttonGroup = khufu.buttonGroup(
103 buttonList=[
104 changePriorityDropdown,
105 moveToDropdown,
106 alertDropdown,
107 classifyButton,
108 changePiButton,
109 generateOBButton,
110 snoozeButton
111 ],
112 format='vertical' # [ default | toolbar | vertical ]
113 )
115 return "%(title)s %(buttonGroup)s %(classifyForm)s" % locals()
118def _get_classify_button(
119 log,
120 request,
121 discoveryDataDictionary,
122):
123 """ get classify button for the ticket topbar
125 **Key Arguments**
127 - ``log`` -- logger
128 - ``request`` -- the pyramid request object
129 - ``discoveryDataDictionary`` -- dictionary of the transient's discovery data
132 **Return**
134 - ``button`` -- the classification button with hidden modal form
136 """
137 from marshall_webapp.templates.commonelements import forms
138 now = datetime.now()
139 now = now.strftime("%Y-%m-%d")
141 log.debug('starting the ``_get_classify_button`` function')
142 # TEST THE ARGUMENTS
144 ## VARIABLES ##
145 button, thisForm = forms.classify_object_form.classify_object_form(
146 log=log,
147 request=request,
148 discoveryDataDictionary=discoveryDataDictionary
149 )
151 log.debug('completed the ``_get_classify_button`` function')
152 return button, thisForm
155def _get_move_to_dropdown(
156 log,
157 request,
158 discoveryDataDictionary,
159):
160 """ get move to dropdown for the ticket
162 **Key Arguments**
164 - ``log`` -- logger
165 - ``request`` -- the pyramid request
166 - ``discoveryDataDictionary`` -- dictionary of the transient's discovery data
169 **Return**
171 - ``thisDropdown`` -- the move to other list dropdown
173 """
174 import datetime
176 log.debug('starting the ``_get_move_to_dropdown`` function')
178 dropdownTitle = """<i class="icon-list-ul"></i>"""
179 icon = """<i class="icon-circle-arrow-up"></i>"""
181 thisMwl = discoveryDataDictionary["marshallWorkflowLocation"].lower()
182 cf = discoveryDataDictionary["classifiedFlag"]
183 snoozed = discoveryDataDictionary["snoozed"]
184 if thisMwl == "inbox":
185 linkTitleList = ["classify - high",
186 "classify - medium", "classify - low", "archive"]
187 elif thisMwl == "review for followup":
188 linkTitleList = ["followup targets", "archive"]
189 elif thisMwl == "pending observation":
190 linkTitleList = ["inbox", "observed", "archive"]
191 elif thisMwl == "following":
192 linkTitleList = ["followup complete"]
193 elif thisMwl == "followup complete":
194 linkTitleList = ["followup targets"]
195 elif thisMwl == "archive" and cf == 1:
196 linkTitleList = ["followup targets", "review for followup"]
197 elif thisMwl == "archive" and snoozed == 1:
198 linkTitleList = ["inbox", "classify - high",
199 "classify - medium", "classify - low", "archive"]
200 elif thisMwl == "archive":
201 linkTitleList = ["inbox"]
202 elif thisMwl == "pending classification":
203 dropdownTitle = "fail"
204 linkTitleList = ["classify - high",
205 "classify - medium", "classify - low", "archive"]
207 # SET OBSERVATIONAL PRIORITY NUMBERS
208 priorityList = ["high", "medium", "low"]
209 priorityColor = ["green", "yellow", "red"]
210 priorityNumberList = [1, 2, 3]
211 priority = discoveryDataDictionary["observationPriority"]
213 linkList = []
214 for title in linkTitleList:
215 newListLinkTitle = title
216 # DETERMINE THE LIST TO SEND THE TICKET TO
217 mwl = title
218 if "classify -" in title:
219 mwl = "pending observation"
220 newListLinkTitle = "classification targets"
221 elif title == "followup targets":
222 mwl = "following"
223 elif title == "observed":
224 mwl = "pending classification"
225 discoveryDataDictionary["mwl"] = mwl
227 # DETERMINE OBSERVATIONAL PRIORITY
228 num = False
229 for l, n, c in zip(priorityList, priorityNumberList, priorityColor):
230 if f"- {l}" in title:
231 # add text color
232 text = khufu.coloredText(
233 text='<i class="icon-target2"></i>',
234 color=c,
235 size=False, # 1-10
236 pull=False, # "left" | "right",
237 addBackgroundColor=False
238 )
240 title = f"""{text} {title}"""
241 num = n
243 prefix = request.registry.settings["apache prefix"]
244 discoveryDataDictionary["prefix"] = prefix
246 name = discoveryDataDictionary["masterName"]
247 href = request.route_path(
248 'transients_element', elementId=discoveryDataDictionary["transientBucketId"])
249 name = khufu.a(
250 content=name,
251 href=href
252 )
253 href = request.route_path('transients', _query={
254 'mwl': mwl})
255 newListLink = khufu.a(
256 content=newListLinkTitle,
257 href=href
258 )
260 # GENERATE THE UNDO LINK
261 href = request.route_path('transients_element', elementId=discoveryDataDictionary[
262 "transientBucketId"], _query={'mwl': discoveryDataDictionary["marshallWorkflowLocation"], "method": "put"})
263 undoLink = khufu.a(
264 content='undo.',
265 href=href,
266 htmlClass="ticketMoveToLinkUndo",
267 htmlId="ticket%(transientBucketId)s" % discoveryDataDictionary,
268 postInBackground=True,
269 )
271 notification = "%(name)s was moved to the %(newListLink)s list. %(undoLink)s" % locals(
272 )
273 notification = khufu.alert(
274 alertText=notification,
275 alertHeading='',
276 extraPadding=False,
277 alertLevel='info' # [ "warning" | "error" | "success" | "info" ]
278 )
280 notification = urllib.parse.quote(notification, safe='')
281 discoveryDataDictionary["notification"] = notification
283 href = request.route_path('transients_element', elementId=discoveryDataDictionary[
284 "transientBucketId"], _query={'mwl': mwl, 'observationPriority': num, "method": "put"})
285 link = khufu.a(
286 content=title,
287 href=href,
288 tableIndex=-1,
289 triggerStyle=False, # [ False | "dropdown" | "tab" ]
290 htmlClass="ticketMoveToLink",
291 notification=notification,
292 postInBackground=True,
293 )
294 linkListItem = khufu.li(
295 content=link, # if a subMenu for dropdown this should be <ul>
296 span=False, # [ False | 1-12 ]
297 disabled=False,
298 submenuTitle=False,
299 divider=False,
300 navStyle=False, # [ active | header ]
301 navDropDown=False,
302 pager=False # [ False | "previous" | "next" ]
303 )
304 linkList.append(linkListItem)
306 popover = khufu.popover(
307 tooltip=True,
308 placement="right", # [ top | bottom | left | right ]
309 trigger="hover", # [ False | click | hover | focus | manual ]
310 title="move object to another list",
311 content=False,
312 delay=20
313 )
315 thisDropdown = khufu.dropdown(
316 buttonSize='large',
317 buttonColor='success', # [ default | sucess | error | warning | info ]
318 menuTitle=dropdownTitle,
319 splitButton=False,
320 linkList=linkList,
321 separatedLinkList=False,
322 pull=False,
323 direction=False,
324 onPhone=True,
325 onTablet=True,
326 onDesktop=True,
327 popover=popover
328 )
330 log.debug('completed the ``_get_move_to_dropdown`` function')
331 return thisDropdown
334def _get_alert_dropdown(
335 log,
336 request,
337 discoveryDataDictionary,
338):
339 """ get alert dropdown for the ticket
341 **Key Arguments**
343 - ``log`` -- logger
344 - ``request`` -- the pyramid request
345 - ``discoveryDataDictionary`` -- dictionary of the transient's discovery data
348 **Return**
350 - ``thisDropdown`` -- the move to other alert list dropdown
352 """
353 import datetime
355 log.debug('starting the ``_get_alert_dropdown`` function')
357 dropdownTitle = "alert"
359 cf = discoveryDataDictionary["classifiedFlag"]
360 awl = discoveryDataDictionary["alertWorkflowLocation"]
362 thisDropdown = ""
363 linkList = []
364 if cf == 1 and awl == "queued for atel":
365 linkTitleList = ["atel released", "no atel to be released"]
367 for title in linkTitleList:
369 awl = title
370 if title == "atel released":
371 awl = "pessto classification released"
372 elif title == "no atel to be released":
373 awl = "archived without alert"
375 discoveryDataDictionary["awl"] = awl
377 prefix = request.registry.settings["apache prefix"]
378 discoveryDataDictionary["prefix"] = prefix
380 href = request.route_path('transients_element', elementId=discoveryDataDictionary[
381 "transientBucketId"], _query={'awl': awl, "method": "put"})
382 link = khufu.a(
383 content=title,
384 href=href,
385 tableIndex=-1,
386 triggerStyle=False, # [ False | "dropdown" | "tab" ]
387 htmlClass="ticketMoveToLink",
388 postInBackground=True,
389 )
390 linkListItem = khufu.li(
391 content=link, # if a subMenu for dropdown this should be <ul>
392 span=False, # [ False | 1-12 ]
393 disabled=False,
394 submenuTitle=False,
395 divider=False,
396 navStyle=False, # [ active | header ]
397 navDropDown=False,
398 pager=False # [ False | "previous" | "next" ]
399 )
400 linkList.append(linkListItem)
402 thisDropdown = khufu.dropdown(
403 buttonSize='large',
404 # [ default | sucess | error | warning | info ]
405 buttonColor='success',
406 menuTitle=dropdownTitle,
407 splitButton=False,
408 linkList=linkList,
409 separatedLinkList=False,
410 pull=False,
411 direction=False,
412 onPhone=True,
413 onTablet=True,
414 onDesktop=True
415 )
417 log.debug('completed the ``_get_alert_dropdown`` function')
418 return thisDropdown
421def _get_change_pi_button(
422 log,
423 request,
424 discoveryDataDictionary,
425):
426 """ get change pi for the ticket action block
428 **Key Arguments**
430 - ``log`` -- logger
431 - ``request`` -- the pyramid request
432 - ``discoveryDataDictionary`` -- dictionary of the transient's discovery data
435 **Return**
437 - ``button`` -- the change PI button and hidden modal form
439 """
440 from marshall_webapp.templates.commonelements import forms
442 now = datetime.now()
443 now = now.strftime("%Y-%m-%d")
445 log.debug('starting the ``_get_change_pi_button`` function')
446 # TEST THE ARGUMENTS
448 ## VARIABLES ##
449 changePiForm, button = forms.change_pi_form.change_pi_form(
450 log=log,
451 request=request,
452 discoveryDataDictionary=discoveryDataDictionary,
453 )
454 button = "%(button)s %(changePiForm)s" % locals()
456 log.debug('completed the ``_get_change_pi_button`` function')
457 return button
460def _generate_ob_button(
461 log,
462 request,
463 discoveryDataDictionary,
464 lightcurveData,
465 objectAkas,
466):
467 """ get generate OB button for the ticket action block
469 **Key Arguments**
471 - ``log`` -- logger
472 - ``request`` -- the pyramid request
473 - ``discoveryDataDictionary`` -- dictionary of the transient's discovery data
474 - ``lightcurveData`` -- lightcurve data for the object
475 - ``objectAkas`` -- the akas of the object
478 **Return**
480 - ``button`` - the generate OB button with hidden modal form
482 """
483 from marshall_webapp.templates.commonelements import forms
484 now = datetime.now()
485 now = now.strftime("%Y-%m-%d")
487 log.debug('starting the ``_get_classify_button`` function')
488 # TEST THE ARGUMENTS
490 ## VARIABLES ##
491 if discoveryDataDictionary["classifiedFlag"] == 0:
493 thisForm, button = forms.generate_ob_form.generate_ob_form(
494 log=log,
495 request=request,
496 discoveryDataDictionary=discoveryDataDictionary,
497 lightcurveData=lightcurveData,
498 objectAkas=objectAkas,
499 )
500 button = "%(button)s %(thisForm)s" % locals()
501 else:
502 button = None
504 log.debug('completed the ``_get_classify_button`` function')
505 return button
508def _get_priority_switcher_dropdown(
509 request,
510 discoveryDataDictionary,
511 log):
512 """ get priority switcher dropdown
514 **Key Arguments**
516 - ``log`` -- logger
517 - ``request`` -- the pyramid request
518 - ``discoveryDataDictionary`` -- dictionary of the transient's discovery data
520 """
521 log.debug('starting the ``_get_priority_switcher_dropdown`` function')
522 import datetime
524 log.debug('starting the ``_get_move_to_dropdown`` function')
526 dropdownTitle = """<span class="colortext red"><i class="icon-fire"></i></span>"""
527 dropdownTitle = """<i class="icon-fire"></i>"""
529 # Add the appropriate titles to the dropdown
530 linkTitleList = []
531 linkPriorityList = []
532 linkHiddenList = []
533 if discoveryDataDictionary["marshallWorkflowLocation"] == "following":
534 priorityList = ["critical", "important", "useful", "none"]
535 priorityNumberList = [1, 2, 3, 4]
536 else:
537 priorityList = ["high", "medium", "low"]
538 priorityNumberList = [1, 2, 3]
539 priority = discoveryDataDictionary["observationPriority"]
540 for l, n in zip(priorityList, priorityNumberList):
541 linkTitleList.append(l)
542 linkPriorityList.append(n)
543 if priority != n:
544 linkHiddenList.append(False)
545 else:
546 linkHiddenList.append(True)
548 linkList = []
549 for title, num, hidden in zip(linkTitleList, linkPriorityList, linkHiddenList):
551 prefix = request.registry.settings["apache prefix"]
552 discoveryDataDictionary["prefix"] = prefix
553 name = discoveryDataDictionary["masterName"]
554 href = request.route_path(
555 'transients_element', elementId=discoveryDataDictionary["transientBucketId"])
556 name = khufu.a(
557 content=name,
558 href=href
559 )
561 # GENERATE THE UNDO LINK
562 href = request.route_path('transients_element', elementId=discoveryDataDictionary[
563 "transientBucketId"], _query={'observationPriority': num, "method": "put"})
564 undoLink = khufu.a(
565 content='undo.',
566 href=href,
567 htmlClass="changePriorityLinkUndo",
568 htmlId="ticket%(transientBucketId)s" % discoveryDataDictionary,
569 postInBackground=True,
570 )
572 notification = "the observational priorty for %(name)s was changed to %(title)s. %(undoLink)s" % locals(
573 )
574 notification = khufu.alert(
575 alertText=notification,
576 alertHeading='',
577 extraPadding=False,
578 alertLevel='info' # [ "warning" | "error" | "success" | "info" ]
579 )
580 notification = urllib.parse.quote(notification, safe='')
581 discoveryDataDictionary["notification"] = notification
583 href = request.route_path('transients_element', elementId=discoveryDataDictionary[
584 "transientBucketId"], _query={'observationPriority': num, "method": "put"})
585 link = khufu.a(
586 content=title,
587 href=href,
588 tableIndex=-1,
589 triggerStyle=False, # [ False | "dropdown" | "tab" ]
590 htmlClass="changePriorityLink",
591 notification=notification,
592 postInBackground=True,
593 )
594 linkListItem = khufu.li(
595 content=link, # if a subMenu for dropdown this should be <ul>
596 span=False, # [ False | 1-12 ]
597 disabled=False,
598 submenuTitle=False,
599 divider=False,
600 navStyle=False, # [ active | header ]
601 navDropDown=False,
602 pager=False, # [ False | "previous" | "next" ]
603 hidden=hidden
604 )
605 linkList.append(linkListItem)
607 popover = khufu.popover(
608 tooltip=True,
609 placement="right", # [ top | bottom | left | right ]
610 trigger="hover", # [ False | click | hover | focus | manual ]
611 title="set the observational priority of this object",
612 content=False,
613 delay=20
614 )
616 thisDropdown = khufu.dropdown(
617 buttonSize='large',
618 buttonColor='success', # [ default | sucess | error | warning | info ]
619 menuTitle=dropdownTitle,
620 splitButton=False,
621 linkList=linkList,
622 separatedLinkList=False,
623 pull=False,
624 direction=False,
625 onPhone=True,
626 onTablet=True,
627 onDesktop=True,
628 popover=popover
629 )
631 log.debug('completed the ``_get_priority_switcher_dropdown`` function')
632 return thisDropdown
635def _snooze_button(
636 request,
637 discoveryDataDictionary,
638 log):
639 """ snooze button
641 **Key Arguments**
643 - ``log`` -- logger
644 - ``request`` -- the pyramid request
645 - ``discoveryDataDictionary`` -- dictionary of the transient's discovery data
647 """
648 log.debug('starting the ``_snooze_button`` function')
650 now = datetime.now()
651 now = now.strftime("%Y-%m-%d")
653 log.debug('starting the ``_get_change_pi_button`` function')
654 # TEST THE ARGUMENTS
656 mwl = discoveryDataDictionary["marshallWorkflowLocation"]
658 name = discoveryDataDictionary["masterName"]
659 href = request.route_path(
660 'transients_element', elementId=discoveryDataDictionary["transientBucketId"])
661 name = khufu.a(
662 content=name,
663 href=href
664 )
665 href = request.route_path('transients', _query={'mwl': mwl})
666 newListLink = khufu.a(
667 content="archive",
668 href=href
669 )
671 # GENERATE THE UNDO LINK
672 href = request.route_path('transients_element', elementId=discoveryDataDictionary[
673 "transientBucketId"], _query={'mwl': discoveryDataDictionary["marshallWorkflowLocation"], "method": "put"})
674 undoLink = khufu.a(
675 content='undo.',
676 href=href,
677 htmlClass="ticketMoveToLinkUndo",
678 htmlId="ticket%(transientBucketId)s" % discoveryDataDictionary,
679 postInBackground=True,
680 )
682 notification = "%(name)s was snoozed. %(undoLink)s" % locals(
683 )
684 notification = khufu.alert(
685 alertText=notification,
686 alertHeading='',
687 extraPadding=False,
688 alertLevel='info' # [ "warning" | "error" | "success" | "info" ]
689 )
690 notification = urllib.parse.quote(notification, safe='')
691 discoveryDataDictionary["notification"] = notification
693 href = request.route_path('transients_element', elementId=discoveryDataDictionary[
694 "transientBucketId"], _query={'mwl': "archive", "method": "put", "snoozed": True})
696 popover = khufu.popover(
697 tooltip=True,
698 placement="right", # [ top | bottom | left | right ]
699 trigger="hover", # [ False | click | hover | focus | manual ]
700 title="snooze - hide object until more photometry obtained",
701 content=False,
702 delay=20
703 )
705 ## VARIABLES ##
706 button = khufu.button(
707 buttonText='<i class="icon-alarm3"></i>',
708 # [ default | primary | info | success | warning | danger | inverse | link ]
709 buttonStyle='success',
710 buttonSize='large', # [ large | default | small | mini ]
711 htmlId="snooze",
712 htmlClass="ticketMoveToLink",
713 href=href,
714 pull=False, # right, left, center
715 submit=False,
716 block=False,
717 disable=False,
718 postInBackground=True,
719 dataToggle=False, # [ modal ]
720 popover=popover,
721 notification=notification
722 )
724 log.debug('completed the ``_snooze_button`` function')
725 return button
727# xt-def-with-logger