~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/apps/tutorialservice/__init__.py

  • Committer: drtomc
  • Date: 2008-03-06 04:15:08 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:661
tutorialservice: log submitted attempts to the database.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
# Returns a JSON response string indicating the results.
36
36
 
37
37
import os
 
38
import time
38
39
 
39
40
import cjson
40
41
 
 
42
from common import db
41
43
import test
42
44
import conf
43
45
 
93
95
    test_results = exercise_obj.run_tests(code)
94
96
    req.write(cjson.encode(test_results))
95
97
 
 
98
    conn = db.DB()
 
99
 
 
100
    x = conn.get_single({'identifier':exercise},
 
101
                        'problem', ['problemid'], ['identifier'])
 
102
    problemid = x['problemid']
 
103
 
 
104
    x = conn.get_single({'login':req.user.login},
 
105
                        'login', ['loginid'], ['login'])
 
106
    loginid = x['loginid']
 
107
 
 
108
    rec = {}
 
109
    rec['problemid'] = problemid
 
110
    rec['loginid'] = loginid
 
111
    rec['date'] = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())
 
112
    rec['complete'] = test_results['passed']
 
113
    rec['attempt'] = code
 
114
 
 
115
    print >> open("/tmp/attempts.txt", "a"), repr(rec)
 
116
 
 
117
    conn.insert(rec, 'problem_attempt',
 
118
                set(['problemid','loginid','date','complete','attempt']))
 
119
 
96
120
def handle_run(req, exercise, code, fields):
97
121
    """Handles a run action."""
98
122
    # Extremely makeshift.