blob: c3485da69d0049739d26e03b254b1e60ddf8e292 [file] [log] [blame]
mbligh94f07a22008-05-21 17:10:57 +00001#!/usr/bin/python
2
mblighd34763f2008-06-06 14:28:10 +00003import os, cgi, cgitb, time, urllib
mbligh94f07a22008-05-21 17:10:57 +00004import db, unique_cookie
5
6## setting script globals
7form = cgi.FieldStorage()
8if 'label' in form.keys():
9 comment = form['label'].value
10else:
11 comment = ''
mblighd34763f2008-06-06 14:28:10 +000012dict_url = {}
13for key in form.keys():
14 dict_url[key] = form[key].value
15
mbligh94f07a22008-05-21 17:10:57 +000016tm = time.asctime()
mblighd34763f2008-06-06 14:28:10 +000017uid = unique_cookie.unique_id('tko_history')
mbligh94f07a22008-05-21 17:10:57 +000018HTTP_REFERER = os.environ.get('HTTP_REFERER')
mblighd34763f2008-06-06 14:28:10 +000019if HTTP_REFERER == None:
20 ## fall back strategy for proxy connection
21 ## substitute relative url
22 HTTP_REFERER = 'compose_query.cgi?' + urllib.urlencode(dict_url)
mbligh94f07a22008-05-21 17:10:57 +000023
24
25class QueryHistoryError(Exception):
26 pass
27
28
29def log_query():
mbligh94f07a22008-05-21 17:10:57 +000030 db_obj = db.db()
31 data_to_insert = {'uid':uid, 'time_created':tm,
mblighd34763f2008-06-06 14:28:10 +000032 'user_comment':comment, 'url':HTTP_REFERER }
mbligh94f07a22008-05-21 17:10:57 +000033 try:
34 db_obj.insert('query_history', data_to_insert)
35 except:
36 raise QueryHistoryError("Could not save query")
37
38
39def body():
40 log_query()
41 print '<b>%s</b><br><br>' % "Your query has been saved"
42 print 'time: %s<br>' % tm
43 print 'comments: %s<br><br>' % comment
44 print '<table><tr align="center">'
45 print '<td align="center">'
46 print '<a href="query_history.cgi">View saved queries</a>&nbsp;&nbsp;'
47 print '</td>'
48 print '<td align="center">'
49 print '<a href="%s">Back to Autotest</a><br>' % HTTP_REFERER
50 print '</td>'
51
52
53def main():
54 print "Content-type: text/html\n"
55 print '<html><head><title>'
56 print '</title></head>'
57 print '<body>'
58 body()
59 print '</body>'
60 print '</html>'
61
62
63main()
64
65
66