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

« back to all changes in this revision

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

  • Committer: mattgiuca
  • Date: 2008-03-15 12:25:41 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:707
tutorialservice: "submit" requests now return "completed" and "attempts"
    fields as well. They query the DB for the completed and attempt stats.
tutorial.js: Handling the submit response: Now updates the summary bar,
    setting the ball to green and "Complete" if successful, and also updating
    the number of attempts made dynamically.

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
 
89
89
    conn = db.DB()
90
90
 
91
 
    conn.write_problem_save(
92
 
        login = req.user.login,
93
 
        exercisename = exercise,
94
 
        date = time.localtime(),
95
 
        text = code)
 
91
    try:
 
92
        conn.write_problem_save(
 
93
            login = req.user.login,
 
94
            exercisename = exercise,
 
95
            date = time.localtime(),
 
96
            text = code)
 
97
    finally:
 
98
        conn.close()
96
99
 
97
100
def handle_test(req, exercise, code, fields):
98
101
    """Handles a test action."""
108
111
    # Run the test cases. Get the result back as a JSONable object.
109
112
    # Return it.
110
113
    test_results = exercise_obj.run_tests(code)
111
 
    req.write(cjson.encode(test_results))
112
114
 
113
115
    conn = db.DB()
114
 
 
115
 
    conn.insert_problem_attempt(
116
 
        login = req.user.login,
117
 
        exercisename = exercise,
118
 
        date = time.localtime(),
119
 
        complete = test_results['passed'],
120
 
        attempt = code)
 
116
    try:
 
117
        conn.insert_problem_attempt(
 
118
            login = req.user.login,
 
119
            exercisename = exercise,
 
120
            date = time.localtime(),
 
121
            complete = test_results['passed'],
 
122
            attempt = code)
 
123
 
 
124
        # Query the DB to get an updated score on whether or not this problem
 
125
        # has EVER been completed (may be different from "passed", if it has
 
126
        # been completed before), and the total number of attempts.
 
127
        completed, attempts = conn.get_problem_status(req.user.login,
 
128
            exercise)
 
129
        test_results["completed"] = completed
 
130
        test_results["attempts"] = attempts
 
131
 
 
132
        req.write(cjson.encode(test_results))
 
133
    finally:
 
134
        conn.close()
121
135
 
122
136
def handle_run(req, exercise, code, fields):
123
137
    """Handles a run action."""