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

« back to all changes in this revision

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

  • Committer: Nick Chadwick
  • Date: 2009-03-03 01:48:48 UTC
  • mto: (1099.1.227 exercise-ui)
  • mto: This revision was merged to the branch mainline in revision 1162.
  • Revision ID: chadnickbok@gmail.com-20090303014848-dyurvmtmbneohd7f
Modified the setup script to include '.txt' files.

This allows the automatic inclusion of definitions.txt from the rst
code, as it is needed by all worksheets.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
import ivle.database
29
29
from ivle.database import Exercise, ExerciseAttempt, ExerciseSave, Worksheet, \
30
30
                          Offering, Subject, Semester, WorksheetExercise
31
 
import ivle.worksheet
 
31
import ivle.worksheet.utils
32
32
import ivle.conf
33
33
import ivle.webapp.tutorial.test
34
 
 
35
34
from ivle.webapp.base.rest import (JSONRESTView, named_operation,
36
35
                                   require_permission)
37
36
from ivle.webapp.errors import NotFound
52
51
            raise NotFound()
53
52
        
54
53
        self.worksheet_exercise = req.store.find(WorksheetExercise,
55
 
            WorksheetExercise.exercise_id == exercise,
 
54
            WorksheetExercise.exercise_id == unicode(exercise),
56
55
            WorksheetExercise.worksheet_id == Worksheet.id,
57
56
            Worksheet.offering_id == Offering.id,
 
57
            Worksheet.identifier == unicode(worksheet),
58
58
            Offering.subject_id == Subject.id,
59
59
            Subject.code == subject,
60
60
            Offering.semester_id == Semester.id,
113
113
        # Query the DB to get an updated score on whether or not this problem
114
114
        # has EVER been completed (may be different from "passed", if it has
115
115
        # been completed before), and the total number of attempts.
116
 
        completed, attempts = ivle.worksheet.get_exercise_status(req.store,
117
 
            req.user, self.worksheet_exercise)
 
116
        completed, attempts = ivle.worksheet.utils.get_exercise_status(
 
117
                req.store, req.user, self.worksheet_exercise)
118
118
        test_results["completed"] = completed
119
119
        test_results["attempts"] = attempts
120
120
 
136
136
        except ValueError:
137
137
            raise NotFound()
138
138
 
 
139
        # XXX Hack around Google Code issue #87
 
140
        # Query from the given date +1 secnod.
 
141
        # Date is in seconds (eg. 3:47:12), while the data is in finer time
 
142
        # (eg. 3:47:12.3625). The query "date <= 3:47:12" will fail because
 
143
        # 3:47:12.3625 is greater. Hence we do the query from +1 second,
 
144
        # "date <= 3:47:13", and it finds the correct submission, UNLESS there
 
145
        # are multiple submissions inside the same second.
 
146
        date += datetime.timedelta(seconds=1)
 
147
 
139
148
        worksheet_exercise = req.store.find(WorksheetExercise,
140
149
            WorksheetExercise.exercise_id == exercise,
141
150
            WorksheetExercise.worksheet_id == Worksheet.id,
147
156
            Semester.year == year,
148
157
            Semester.semester == semester).one()
149
158
            
150
 
        attempt = ivle.worksheet.get_exercise_attempt(req.store, user,
 
159
        attempt = ivle.worksheet.utils.get_exercise_attempt(req.store, user,
151
160
                        worksheet_exercise, as_of=date,
152
161
                        allow_inactive=HISTORY_ALLOW_INACTIVE) 
153
162
 
161
170
        return {'code': self.context.text}
162
171
 
163
172
 
164
 
class ExerciseRESTView(JSONRESTView):
 
173
class WorksheetExerciseRESTView(JSONRESTView):
165
174
    '''REST view of an exercise.'''
166
175
 
167
176
    def get_permissions(self, user):
253
262
        self.context.assessable = self.convert_bool(assessable)
254
263
        self.context.data = unicode(data)
255
264
        self.context.format = unicode(format)
256
 
        ivle.worksheet.update_exerciselist(self.context)
 
265
        ivle.worksheet.utils.update_exerciselist(self.context)
257
266
        
258
267
        return {"result": "ok"}
259
268
 
305
314
        
306
315
        # This call is added for clarity, as the worksheet is implicitly added.        
307
316
        req.store.add(new_worksheet)
308
 
        
309
 
        ivle.worksheet.update_exerciselist(new_worksheet)
310
 
        
 
317
 
 
318
        ivle.worksheet.utils.update_exerciselist(new_worksheet)
 
319
 
311
320
        return {"result": "ok"}
312
321
 
313
322
    @named_operation('edit')