mbligh | 94f07a2 | 2008-05-21 17:10:57 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import os, cgi, cgitb, time |
| 4 | import db, unique_cookie |
| 5 | |
| 6 | ## setting script globals |
| 7 | form = cgi.FieldStorage() |
| 8 | if 'label' in form.keys(): |
| 9 | comment = form['label'].value |
| 10 | else: |
| 11 | comment = '' |
| 12 | tm = time.asctime() |
| 13 | HTTP_REFERER = os.environ.get('HTTP_REFERER') |
| 14 | |
| 15 | |
| 16 | class QueryHistoryError(Exception): |
| 17 | pass |
| 18 | |
| 19 | |
| 20 | def 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 | |
| 32 | def 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> ' |
| 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 | |
| 46 | def 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 | |
| 56 | main() |
| 57 | |
| 58 | |
| 59 | |