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

« back to all changes in this revision

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

  • Committer: Nick Chadwick
  • Date: 2009-03-09 00:15:21 UTC
  • mfrom: (1099.6.4 new-dispatch)
  • mto: This revision was merged to the branch mainline in revision 1162.
  • Revision ID: chadnickbok@gmail.com-20090309001521-dffcygyuyvs2cap0
finished the exercise-ui. It is now ready to be merged with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
                          TestSuiteVar, TestCasePart
24
24
from ivle.webapp.base.rest import (JSONRESTView, named_operation,
25
25
                                   require_permission)
26
 
from ivle.webapp.errors import NotFound
 
26
from ivle.webapp.errors import NotFound, BadRequest
27
27
 
28
28
 
29
29
class ExercisesRESTView(JSONRESTView):
91
91
        self.context.include = unicode(include)
92
92
        self.context.num_rows = int(num_rows)
93
93
        return {'result': 'moo'}
 
94
    
 
95
    @named_operation(u'edit')
 
96
    def delete_exercise(self, req, id):
 
97
        
 
98
        if self.context.worksheets.count() is not 0:
 
99
            raise BadRequest()
 
100
        
 
101
        #XXX: Not sure if this works
 
102
        for suite in req.context.test_suites:
 
103
            for variable in suite.variables:
 
104
                req.store.remove(variable)
 
105
            for test_case in suite.test_cases:
 
106
                for test_part in test_case.parts:
 
107
                    req.store.remove(test_part)
 
108
                req.store.remove(test_case)
 
109
            req.store.remove(suite)
 
110
        
 
111
        req.store.remove(self.context)
 
112
        return {'result': 'ok'}
94
113
        
95
114
    @named_operation(u'edit')
96
115
    def add_suite(self, req, description, function, stdin):
121
140
        suite.stdin = unicode(stdin)
122
141
        
123
142
        return {'result': 'ok'}
 
143
    
 
144
    @named_operation(u'edit')
 
145
    def delete_suite(self, req, suiteid):
 
146
        
 
147
        suite = req.store.find(TestSuite,
 
148
            TestSuite.suiteid == int(suiteid),
 
149
            TestSuite.exercise_id == self.context.id).one()
 
150
        if suite is None:
 
151
            raise NotFound()
 
152
        
 
153
        for variable in suite.variables:
 
154
            req.store.remove(variable)
 
155
        for test_case in suite.test_cases:
 
156
            for test_part in test_case.parts:
 
157
                req.store.remove(test_part)
 
158
            req.store.remove(test_case)
 
159
        req.store.remove(suite)
 
160
        
 
161
        return {'result': 'ok'}
124
162
      
125
163
    @named_operation(u'edit')
126
164
    def add_var(self, req, suiteid, var_type, var_name, var_val, argno):
161
199
        return {'result': 'ok'}
162
200
    
163
201
    @named_operation(u'edit')
 
202
    def delete_var(self, req, suiteid, varid):
 
203
        var = req.store.find(TestSuiteVar,
 
204
            TestSuiteVar.varid == int(varid),
 
205
            TestSuiteVar.suiteid == int(suiteid)).one()
 
206
        if var is None:
 
207
            raise NotFound()
 
208
        
 
209
        req.store.remove(var)
 
210
        
 
211
        return {'result': 'ok'}
 
212
    
 
213
    @named_operation(u'edit')
164
214
    def add_testcase(self, req, suiteid, passmsg, failmsg, default):
165
215
        
166
216
        suite = req.store.find(TestSuite,
180
230
        req.store.add(new_case)
181
231
        
182
232
        return {'result': 'ok'}
 
233
    
 
234
    @named_operation(u'edit')
 
235
    def edit_testcase(self, req, suiteid, testid, passmsg, failmsg, default):
 
236
        
 
237
        suite = req.store.find(TestSuite,
 
238
            TestSuite.suiteid == int(suiteid),
 
239
            TestSuite.exercise_id == self.context.id).one()
 
240
        if suite is None:
 
241
            raise NotFound('testsuite')
 
242
        
 
243
        test_case = req.store.find(TestCase,
 
244
            TestCase.suiteid == suite.suiteid,
 
245
            TestCase.testid == int(testid)).one()
 
246
        if test_case is None:
 
247
            raise NotFound('testcase')
 
248
        
 
249
        test_case.passmsg = unicode(passmsg)
 
250
        test_case.failmsg = unicode(failmsg)
 
251
        test_case.default = unicode(default)
 
252
        
 
253
        return {'result': 'ok'}
 
254
    
 
255
    @named_operation(u'edit')
 
256
    def delete_testcase(self, req, suiteid, testid):
 
257
        
 
258
        suite = req.store.find(TestSuite,
 
259
            TestSuite.suiteid == int(suiteid),
 
260
            TestSuite.exercise_id == self.context.id).one()
 
261
        if suite is None:
 
262
            raise NotFound()
 
263
        
 
264
        test_case = req.store.find(TestCase,
 
265
            TestCase.suiteid == suite.suiteid,
 
266
            TestCase.testid == int(testid)).one()
 
267
        if test_case is None:   
 
268
            raise NotFound()
 
269
            
 
270
        for test_part in test_case.parts:
 
271
            req.store.remove(test_part)
 
272
        req.store.remove(test_case)
 
273
        
 
274
        return {'result': 'ok'}
 
275
    
 
276
    @named_operation(u'edit')
 
277
    def edit_testpart(self, req, suiteid, testid, partid, part_type, test_type, 
 
278
                      data, filename):
 
279
    
 
280
        suite = req.store.find(TestSuite,
 
281
            TestSuite.suiteid == int(suiteid),
 
282
            TestSuite.exercise_id == self.context.id).one()
 
283
        if suite is None:
 
284
            raise NotFound('testsuite')
 
285
        
 
286
        test_case = req.store.find(TestCase,
 
287
            TestCase.suiteid == suite.suiteid,
 
288
            TestCase.testid == int(testid)).one()
 
289
        if test_case is None:
 
290
            raise NotFound('testcase')
 
291
        
 
292
        test_part = req.store.find(TestCasePart,
 
293
            TestCasePart.testid == test_case.testid,
 
294
            TestCasePart.partid == int(partid)).one()
 
295
        if test_part is None:
 
296
            raise NotFound('testcasepart')
 
297
        
 
298
        test_part.part_type = unicode(part_type)
 
299
        test_part.test_type = unicode(test_type)
 
300
        test_part.data = unicode(data)
 
301
        test_part.filename = unicode(filename)
 
302
        
 
303
        return {'result': 'ok'}
 
304
    
 
305
    @named_operation(u'edit')
 
306
    def add_testpart(self, req, suiteid, testid, part_type, test_type, 
 
307
                      data, filename):
 
308
    
 
309
        suite = req.store.find(TestSuite,
 
310
            TestSuite.suiteid == int(suiteid),
 
311
            TestSuite.exercise_id == self.context.id).one()
 
312
        if suite is None:
 
313
            raise NotFound('testsuite')
 
314
        
 
315
        test_case = req.store.find(TestCase,
 
316
            TestCase.suiteid == suite.suiteid,
 
317
            TestCase.testid == int(testid)).one()
 
318
        if test_case is None:
 
319
            raise NotFound('testcase')
 
320
        
 
321
        test_part = TestCasePart()
 
322
        test_part.part_type = unicode(part_type)
 
323
        test_part.test_type = unicode(test_type)
 
324
        test_part.data = unicode(data)
 
325
        test_part.filename = unicode(filename)
 
326
        
 
327
        test_case.parts.add(test_part)
 
328
        
 
329
        return {'result': 'ok'}
 
330
    
 
331
    @named_operation(u'edit')
 
332
    def delete_testpart(self, req, suiteid, testid, partid):
 
333
        suite = req.store.find(TestSuite,
 
334
            TestSuite.suiteid == int(suiteid),
 
335
            TestSuite.exercise_id == self.context.id).one()
 
336
        if suite is None:
 
337
            raise NotFound()
 
338
        
 
339
        test_case = req.store.find(TestCase,
 
340
            TestCase.suiteid == suite.suiteid,
 
341
            TestCase.testid == int(testid)).one()
 
342
        if test_case is None:
 
343
            raise NotFound()
 
344
        
 
345
        test_part = req.store.find(TestCasePart,
 
346
            TestCasePart.testid == test_case.testid,
 
347
            TestCasePart.partid == int(partid)).one()
 
348
        if test_part is None:
 
349
            raise NotFound('testcasepart')
 
350
        
 
351
        req.store.remove(test_part)
 
352
        
 
353
        return {'result': 'ok'}