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

« back to all changes in this revision

Viewing changes to ivle/webapp/tutorial/service.py

  • Committer: William Grant
  • Date: 2009-12-10 02:38:01 UTC
  • mfrom: (1394.2.15 test-exercise)
  • Revision ID: grantw@unimelb.edu.au-20091210023801-mmbkfawdwbmvmoli
Add an ExerciseView, allowing testing of an exercise before adding it to a worksheet. Also some exercise editor UI tweaks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
'''AJAX backend for the tutorial application.'''
21
21
 
22
 
import os
23
22
import datetime
24
23
 
25
24
import genshi
26
25
from storm.locals import Store
27
26
 
28
 
import ivle.console
29
27
import ivle.database
30
28
from ivle.database import Exercise, ExerciseAttempt, ExerciseSave, Worksheet, \
31
29
                          Offering, Subject, Semester, User, WorksheetExercise
32
30
import ivle.worksheet.utils
33
 
import ivle.webapp.tutorial.test
34
31
from ivle.webapp.base.rest import (JSONRESTView, named_operation,
35
32
                                   require_permission)
36
33
from ivle.webapp.errors import NotFound
38
35
 
39
36
TIMESTAMP_FORMAT = '%Y-%m-%d %H:%M:%S'
40
37
 
 
38
 
41
39
class AttemptsRESTView(JSONRESTView):
42
40
    '''REST view of a user's attempts at an exercise.'''
43
41
 
58
56
    @require_permission('edit')
59
57
    def PUT(self, req, data):
60
58
        """ Tests the given submission """
61
 
        # Start a console to run the tests on
62
 
        jail_path = os.path.join(req.config['paths']['jails']['mounts'],
63
 
                                 req.user.login)
64
 
        working_dir = os.path.join("/home", req.user.login)
65
 
        cons = ivle.console.Console(req.config, req.user.unixid, jail_path,
66
 
                                    working_dir)
67
 
 
68
 
        # Parse the file into a exercise object using the test suite
69
 
        exercise_obj = ivle.webapp.tutorial.test.parse_exercise_file(
70
 
                            self.context.worksheet_exercise.exercise, cons)
71
 
 
72
 
        # Run the test cases. Get the result back as a JSONable object.
73
 
        # Return it.
74
 
        test_results = exercise_obj.run_tests(data['code'])
75
 
 
76
 
        # Close the console
77
 
        cons.close()
 
59
        test_results = ivle.worksheet.utils.test_exercise_submission(
 
60
            req.config, req.user, self.context.worksheet_exercise.exercise,
 
61
            data['code'])
78
62
 
79
63
        attempt = ivle.database.ExerciseAttempt(user=req.user,
80
64
            worksheet_exercise = self.context.worksheet_exercise,