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