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

« back to all changes in this revision

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

  • Committer: Matt Giuca
  • Date: 2009-01-19 16:03:36 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: matt.giuca@gmail.com-20090119160336-28ob0uev0hnikec3
Added new module: ivle.worksheet. This will contain general functions for
    worksheets (particularly for interacting with the DB), which don't belong
    in either tutorial or tutorialservice.
    worksheet now has get_exercise_status, which is a Storm re-implementation
    of ivle.db.get_problem_status. Much cleaner!
tutorial, tutorialservice: Now use ivle.worksheet.get_exercise_status rather
    than ivle.db.get_problem_status.
ivle.db: Renamed get_problem_status to _get_problem_status. Still required,
    but only used internally now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
import cjson
48
48
 
49
49
from ivle import (db, util, console)
 
50
import ivle.worksheet
50
51
import ivle.conf
51
52
import test # XXX: Really .test, not real test.
52
53
 
126
127
    finally:
127
128
        conn.close()
128
129
 
129
 
def handle_test(req, exercise, code, fields):
 
130
def handle_test(req, exercisesrc, code, fields):
130
131
    """Handles a test action."""
131
132
 
132
 
    exercisefile = util.open_exercise_file(exercise)
 
133
    exercisefile = util.open_exercise_file(exercisesrc)
133
134
    if exercisefile is None:
134
135
        req.throw_error(req.HTTP_NOT_FOUND,
135
136
            "The exercise was not found.")
150
151
    # Close the console
151
152
    cons.close()
152
153
 
 
154
    # Get the Exercise from the database
 
155
    exercise = ivle.database.Exercise.get_by_name(req.store, exercisesrc)
 
156
 
153
157
    conn = db.DB()
154
158
    try:
155
159
        conn.insert_problem_attempt(
156
160
            login = req.user.login,
157
 
            exercisename = exercise,
 
161
            exercisename = exercisesrc,
158
162
            date = time.localtime(),
159
163
            complete = test_results['passed'],
160
164
            attempt = code)
161
 
 
162
 
        # Query the DB to get an updated score on whether or not this problem
163
 
        # has EVER been completed (may be different from "passed", if it has
164
 
        # been completed before), and the total number of attempts.
165
 
        completed, attempts = conn.get_problem_status(req.user.login,
166
 
            exercise)
167
 
        test_results["completed"] = completed
168
 
        test_results["attempts"] = attempts
169
 
 
170
 
        req.write(cjson.encode(test_results))
171
165
    finally:
172
166
        conn.close()
173
167
 
 
168
    # Query the DB to get an updated score on whether or not this problem
 
169
    # has EVER been completed (may be different from "passed", if it has
 
170
    # been completed before), and the total number of attempts.
 
171
    completed, attempts = ivle.worksheet.get_exercise_status(req.store,
 
172
        req.user, exercise)
 
173
    test_results["completed"] = completed
 
174
    test_results["attempts"] = attempts
 
175
 
 
176
    req.write(cjson.encode(test_results))
 
177
 
174
178
def handle_getattempts(req, exercise):
175
179
    """Handles a getattempts action."""
176
180
    conn = db.DB()