Hide keyboard shortcuts

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*View switcher buttons for ticket table toolbar* 

5 

6:Author: 

7 David Young 

8""" 

9 

10 

11def view_switcher_buttons( 

12 log, 

13 params, 

14 request, 

15 elementId=False, 

16 tcsTableName=False 

17): 

18 """view_switcher_buttons 

19 

20 **Key Arguments** 

21 

22 - ``log`` -- logger 

23 - ``params`` -- the request params (defaults added if not populated) 

24 - ``request`` -- the pyramid request 

25 - ``elementId`` -- the transientBucketId 

26 

27 

28 **Return** 

29 

30 - ``viewSwitcherButton`` + ``downloadsButton`` 

31 

32 """ 

33 import khufu 

34 theseLinks = "" 

35 

36 # The various view options 

37 format = ["html_tickets", "html_table", "csv", "json", "plain_table"] 

38 linkText = ["tickets", "table", "csv", "json", "plain text"] 

39 

40 for f, l in zip(format, linkText): 

41 # skip the current view 

42 if params["format"] == f: 

43 continue 

44 thisLink = _link_for_popover( 

45 log=log, 

46 request=request, 

47 format=f, 

48 params=params, 

49 linkText=l, 

50 elementId=elementId 

51 ) 

52 theseLinks = "%(theseLinks)s %(thisLink)s" % locals() 

53 

54 popover = khufu.popover( 

55 tooltip=False, 

56 placement="bottom", # [ top | bottom | left | right ] 

57 trigger="hover", # [ False | click | hover | focus | manual ] 

58 title="view switcher", 

59 content=theseLinks, 

60 delay=20 

61 ) 

62 viewSwitcherButton = khufu.button( 

63 buttonText="""<i class="icon-eye3"></i>""" % locals(), 

64 # [ default | primary | info | success | warning | danger | inverse | link ] 

65 buttonStyle='default', 

66 buttonSize='default', # [ large | default | small | mini ] 

67 htmlId=False, 

68 href=False, 

69 pull=False, # right, left, center 

70 submit=False, 

71 block=False, 

72 disable=False, 

73 dataToggle=False, # [ modal ] 

74 popover=popover 

75 ) 

76 

77 theseLinks = "" 

78 

79 # The various download options 

80 format = ["csv", "json", "plain_table"] 

81 linkText = ["csv", "json", "plain text"] 

82 

83 for f, l in zip(format, linkText): 

84 # skip the current view 

85 if params["format"] == f: 

86 continue 

87 thisLink = _link_for_popover( 

88 log=log, 

89 request=request, 

90 format=f, 

91 params=params, 

92 linkText=l, 

93 download=True, 

94 elementId=elementId, 

95 tcsTableName=tcsTableName 

96 ) 

97 theseLinks = "%(theseLinks)s %(thisLink)s" % locals() 

98 popover = khufu.popover( 

99 tooltip=False, 

100 placement="bottom", # [ top | bottom | left | right ] 

101 trigger="hover", # [ False | click | hover | focus | manual ] 

102 title="download options", 

103 content=theseLinks, 

104 delay=20 

105 ) 

106 downloadsButton = khufu.button( 

107 buttonText="""<i class="icon-save"></i>""" % locals(), 

108 # [ default | primary | info | success | warning | danger | inverse | link ] 

109 buttonStyle='default', 

110 buttonSize='default', # [ large | default | small | mini ] 

111 htmlId=False, 

112 href=False, 

113 pull=False, # right, left, center 

114 submit=False, 

115 block=False, 

116 disable=False, 

117 dataToggle=False, # [ modal ] 

118 popover=popover 

119 ) 

120 

121 return viewSwitcherButton + downloadsButton 

122 

123 

124def ntt_view_button( 

125 log, 

126 params, 

127 elementId, 

128 request 

129): 

130 """ntt_view_button 

131 

132 **Key Arguments** 

133 

134 - ``log`` -- logger 

135 - ``params`` -- the request params (defaults added if not populated) 

136 - ``request`` -- the pyramid request 

137 

138 

139 **Return** 

140 

141 - ``viewSwitcherButton`` -- the view switching button 

142 

143 """ 

144 import khufu 

145 theseLinks = "" 

146 match = False 

147 

148 if "filterBy1" in params and "filterValue1" in params and "filterOp1" in params: 

149 

150 if params["filterBy1"] == "decDeg" and params["filterValue1"] in ["30", 30] and params["filterOp1"] in ["lt", "<"]: 

151 

152 htmlClass = "on" 

153 content = "show targets > +30&deg;" 

154 params["filterBy1"] = None 

155 params["filterValue1"] = None 

156 params["filterOp1"] = None 

157 match = True 

158 

159 if match == False: 

160 htmlClass = False 

161 content = "hide targets > +30&deg;" 

162 params["filterBy1"] = "decDeg" 

163 params["filterValue1"] = 30 

164 params["filterOp1"] = "lt" 

165 

166 routename = request.matched_route.name 

167 if "q" in params: 

168 href = request.route_path('transients_search', _query=params) 

169 else: 

170 href = request.route_path( 

171 routename, elementId=elementId, _query=params) 

172 

173 popover = khufu.popover( 

174 tooltip=False, 

175 placement="bottom", # [ top | bottom | left | right ] 

176 trigger="hover", # [ False | click | hover | focus | manual ] 

177 title="Target Filter", 

178 content=content, 

179 delay=20 

180 ) 

181 viewSwitcherButton = khufu.button( 

182 buttonText="""<i class="icon-globe"></i>&nbspNTT""" % locals(), 

183 # [ default | primary | info | success | warning | danger | inverse | link ] 

184 buttonStyle='default', 

185 buttonSize='default', # [ large | default | small | mini ] 

186 htmlId=False, 

187 htmlClass=htmlClass, 

188 href=href, 

189 pull=False, # right, left, center 

190 submit=False, 

191 block=False, 

192 disable=False, 

193 dataToggle=False, # [ modal ] 

194 popover=popover 

195 ) 

196 

197 return viewSwitcherButton 

198 

199 

200def _link_for_popover( 

201 log, 

202 request, 

203 format, 

204 params, 

205 linkText=False, 

206 download=False, 

207 elementId=False, 

208 tcsTableName=False): 

209 """ link for popover 

210 

211 **Key Arguments** 

212 

213 - ``log`` -- logger 

214 - ``request`` -- pyramid request object 

215 - ``format`` -- format of view to return 

216 - ``linkText`` - text for link if different than format 

217 - ``elementId`` -- the transientBucketId 

218 

219 

220 **Return** 

221 

222 - ``thisLink`` -- the link for the popover 

223 

224 """ 

225 import khufu 

226 log.debug('starting the ``_link_for_popover`` function') 

227 

228 params["format"] = format 

229 params["method"] = "get" 

230 

231 if download: 

232 if "html" not in format: 

233 params["filename"] = "" 

234 if tcsTableName: 

235 params["filename"] = tcsTableName 

236 elif "snoozed" in params and params["snoozed"]: 

237 params["filename"] += "snoozed" 

238 elif "cf" in params and params["cf"]: 

239 params["filename"] += "classifications" 

240 elif "awl" in params and params["awl"]: 

241 params["filename"] += params["awl"] 

242 elif "mwl" in params and params["mwl"]: 

243 params["filename"] += params["mwl"] 

244 

245 elif "q" in params: 

246 params["filename"] += "search_" + params["q"] 

247 elif "snoozed" in params: 

248 params["filename"] += "snoozed" 

249 elif "filterBy1" in params: 

250 params["filename"] += "filtered" 

251 elif elementId: 

252 sqlQuery = u""" 

253 select masterName from transientBucketSummaries where transientBucketId = %(elementId)s  

254 """ % locals() 

255 objectDataTmp = request.db.execute(sqlQuery).fetchall() 

256 objectData = [] 

257 objectData[:] = [dict(list(zip(list(row.keys()), row))) 

258 for row in objectDataTmp] 

259 params["filename"] = "search_" + objectData[0]["masterName"] 

260 

261 oldnames = ["pending obs", "following", "allObsQueue"] 

262 newnames = ["classification targets", "followup targets", 

263 "classification and followup targets"] 

264 

265 for o, n in zip(oldnames, newnames): 

266 if o in params["filename"]: 

267 params["filename"] = n 

268 break 

269 

270 params["filename"] = "pessto_marshall_" + params["filename"] 

271 

272 import copy 

273 p = copy.deepcopy(params) 

274 if format == "html_table": 

275 p["limit"] = 100 

276 elif format == "html_tickets": 

277 p["limit"] = 10 

278 

279 # IF PLAIN TEXT DOWNLOAD (JSON, CSV ...) REMOVE LIMITS 

280 if "html" not in p["format"]: 

281 p = dict(p) 

282 log.debug("""p1: `%(p)s`""" % locals()) 

283 log.debug("""p2: `%(p)s`""" % locals()) 

284 

285 routename = request.matched_route.name 

286 if "q" in p: 

287 href = request.route_path('transients_search', _query=p) 

288 else: 

289 href = request.route_path( 

290 routename, elementId=elementId, _query=p) 

291 

292 if linkText: 

293 format = linkText 

294 thisLink = khufu.a( 

295 content=format, 

296 href=href 

297 ) 

298 thisLink = khufu.p( 

299 content=thisLink, 

300 textAlign="center", # [ left | center | right ] 

301 ) 

302 

303 log.debug('completed the ``_link_for_popover`` function') 

304 return thisLink