blob: 7f091144ff5f19689ec4c9f62984dd741b5a5a4f [file] [log] [blame]
mbligh94f07a22008-05-21 17:10:57 +00001#!/usr/bin/python
2
3import os, cgi, cgitb, time
4import db, unique_cookie
5
6## setting script globals
7form = cgi.FieldStorage()
8if 'label' in form.keys():
9 comment = form['label'].value
10else:
11 comment = ''
12tm = time.asctime()
13HTTP_REFERER = os.environ.get('HTTP_REFERER')
14
15
16class QueryHistoryError(Exception):
17 pass
18
19
20def log_query():
21 uid = unique_cookie.unique_id('tko_history')
22 db_obj = db.db()
23 data_to_insert = {'uid':uid, 'time_created':tm,
24 'user_comment':comment, 'url':HTTP_REFERER
25 }
26 try:
27 db_obj.insert('query_history', data_to_insert)
28 except:
29 raise QueryHistoryError("Could not save query")
30
31
32def body():
33 log_query()
34 print '<b>%s</b><br><br>' % "Your query has been saved"
35 print 'time: %s<br>' % tm
36 print 'comments: %s<br><br>' % comment
37 print '<table><tr align="center">'
38 print '<td align="center">'
39 print '<a href="query_history.cgi">View saved queries</a>&nbsp;&nbsp;'
40 print '</td>'
41 print '<td align="center">'
42 print '<a href="%s">Back to Autotest</a><br>' % HTTP_REFERER
43 print '</td>'
44
45
46def main():
47 print "Content-type: text/html\n"
48 print '<html><head><title>'
49 print '</title></head>'
50 print '<body>'
51 body()
52 print '</body>'
53 print '</html>'
54
55
56main()
57
58
59