6 import urllib
, db
, unique_cookie
8 uid
= unique_cookie
.unique_id('tko_history')
13 condition
= "uid='%s'" % uid
14 where
= (condition
,[])
16 rows
= db_obj
.select("time_created,user_comment,url",
17 "tko_query_history", where
)
18 except MySQLdb
.ProgrammingError
, err
:
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
26 print '<td> %s </td>' % time_created
27 print '<td> %s </td>' % user_comment
28 dict_url
= {'delete':time_created
}
29 link
= 'save_query.cgi?' + urllib
.urlencode(dict_url
)
30 print '<td> <a href="%s">Delete</a> </td>' % link
31 print '<td><a href="%s">%s</a></td>' % (tko_url
, tko_url
)
35 last_recorded_query
= ''
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
54 print "Content-type: text/html\n"
56 # create the actual page
57 print '<html><head><title>'
58 print 'History of TKO usage'
59 print '</title></head><body>'
61 print '</body></html>'