blob: 85052937ced5ab9e06496d730fe83357325d68fd [file] [log] [blame]
mbligh94f07a22008-05-21 17:10:57 +00001#!/usr/bin/python
2
3import sys, os
4import MySQLdb
5import urllib, db, unique_cookie
6
mblighd34763f2008-06-06 14:28:10 +00007uid = unique_cookie.unique_id('tko_history')
8
9
mbligh94f07a22008-05-21 17:10:57 +000010def body():
mbligh15110b72009-01-13 23:33:33 +000011 db_obj = db.db()
12 condition = "uid='%s'" % uid
13 where = (condition,[])
14 try:
15 rows = db_obj.select("time_created,user_comment,url",
16 "query_history", where)
17 except MySQLdb.ProgrammingError, err:
18 print err
19 rows = ()
20 print '<table border="1">'
21 ## Display history starting with the most recent queries
22 for row in reversed(rows):
23 (time_created, user_comment, tko_url) = row
24 print '<tr>'
25 print '<td>&nbsp;%s&nbsp;</td>' % time_created
26 print '<td>&nbsp;%s&nbsp;</td>' % user_comment
27 dict_url = {'delete':time_created}
28 link = 'save_query.cgi?' + urllib.urlencode(dict_url)
29 print '<td>&nbsp;<a href="%s">Delete</a>&nbsp;</td>' % link
30 print '<td><a href="%s">%s</a></td>' % (tko_url, tko_url)
31 print '</tr>'
32 print '</table>'
mbligh099c1422008-06-06 17:42:09 +000033
mbligh15110b72009-01-13 23:33:33 +000034 last_recorded_query = ''
35 if rows:
36 (time_created, user_comment, last_recorded_query) = rows[-1]
37 ## Link "Back to Autotest" on query history page
38 back_link = os.environ.get('HTTP_REFERER')
39 ## possible complications:
40 ## a) HTTP_REFERER = None
41 ## b) HTTP_REFERER is save_query page
42 ## In both cases we still want to get to tko results.
43 ## primary fall back: link to last_recorded_query
44 ## secondary fall back: link to opening tko page
45 if not "compose_query.cgi" in str(back_link):
46 back_link = last_recorded_query
47 if not back_link: ## e.g. history is empty and/or HTTP_REFERER unknown
48 back_link = "compose_query.cgi"
49 print '<br><a href="%s">Autotest Results</a><br>' % back_link
mbligh94f07a22008-05-21 17:10:57 +000050
51
52def main():
mbligh15110b72009-01-13 23:33:33 +000053 print "Content-type: text/html\n"
54 print
55 # create the actual page
56 print '<html><head><title>'
57 print 'History of TKO usage'
58 print '</title></head><body>'
59 body()
60 print '</body></html>'
mbligh94f07a22008-05-21 17:10:57 +000061
62
63main()
64
65