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 filter dropdown used to filter the tickets displayed in the marshall*
6:Author:
7 David Young
8"""
9import sys
10import os
11import re
12import khufu
15def ticket_table_filter_dropdown(
16 log,
17 request,
18 filterBy=False,
19 filterValue=False,
20 filterOp=False
21):
22 """ticket table filter dropdown
24 **Key Arguments**
26 - ``log`` -- the logger
27 - ``request`` -- the request
28 - ``filterBy`` -- what parameter to filter by
29 - ``filterValue`` -- the value to filter the parameter with
30 - ``filterOp`` -- the filter operator
32 **Return**
34 - ``filterDropdown`` -- the filter dropdown for the transient listing pages
35 """
36 buttonfilterBy = ""
38 routename = request.matched_route.name
39 if "elementId" in request.matchdict:
40 elementId = request.matchdict["elementId"]
41 else:
42 elementId = False
44 theseParams = dict(request.params)
45 alist = ["sortBy", "sortDesc"]
46 for i in alist:
47 if i in theseParams:
48 del theseParams[i]
50 # GENERATE THE FILTER OPTION LIST
51 filterList = [
52 "predicted SN",
53 "predicted NT",
54 "predicted AGN",
55 "predicted orphan",
56 "predicted CV",
57 u"predicted Var★"
58 ]
60 filterList = sorted(filterList)
61 filterList = ["remove filter"] + filterList
62 if filterBy == "sherlockClassification":
63 buttonfilterBy = "predicted " + filterValue
64 try:
65 filterList.remove("predicted " + filterValue)
66 except:
67 pass
68 if not filterBy:
69 try:
70 filterList.remove("remove filter")
71 except:
72 pass
74 # ADD LINKS TO OPTIONS
75 linkList = []
76 for option in filterList:
77 if "predicted" in option:
78 dbValue = option.replace("predicted ", "")
79 theseParams["filterBy2"] = "sherlockClassification"
80 theseParams["filterValue2"] = dbValue
81 theseParams["filterOp2"] = 'eq'
82 if "remove filter" in option:
83 theseParams["filterBy2"] = False
84 theseParams["filterValue2"] = False
85 theseParams["filterOp2"] = False
87 thisLink = request.route_path(
88 routename, elementId=elementId, _query=theseParams)
89 thisLink = khufu.a(
90 content=option,
91 href=thisLink,
92 )
93 thisLink = khufu.li(
94 content=thisLink, # if a subMenu for dropdown this should be <ul>
95 )
96 linkList.append(thisLink)
98 topButtonLink = request.route_path(
99 routename, elementId=elementId, _query=theseParams)
101 # add text color
102 if filterBy:
103 color = "red"
104 else:
105 color = "black"
106 filterIcon = khufu.coloredText(
107 text="""<i class="icon-filter"></i>""",
108 color=color,
109 size=False, # 1-10
110 pull=False, # "left" | "right"
111 )
113 popover = khufu.popover(
114 tooltip=True,
115 placement="left", # [ top | bottom | left | right ]
116 trigger="hover", # [ False | click | hover | focus | manual ]
117 title="filter tickets by a given transient parameter",
118 content=False,
119 delay=20
120 )
122 sortDropdown = khufu.dropdown(
123 buttonSize='default',
124 buttonColor='default', # [ default | sucess | error | warning | info ]
125 menuTitle=" %(filterIcon)s %(buttonfilterBy)s" % locals(),
126 linkList=linkList,
127 pull="right",
128 # use javascript to explode contained links
129 direction='down', # [ down | up ]
130 onPhone=True,
131 onTablet=True,
132 onDesktop=True,
133 popover=popover
134 )
136 return sortDropdown