1
# IVLE - Informatics Virtual Learning Environment
2
# Copyright (C) 2007-2009 The University of Melbourne
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
# Author: Nick Chadwick
22
from ivle.database import Exercise, TestSuite, TestCase, \
23
TestSuiteVar, TestCasePart
24
from ivle.webapp.base.rest import (JSONRESTView, named_operation,
26
from ivle.webapp.errors import NotFound
29
class ExercisesRESTView(JSONRESTView):
30
"""Rest view for adding an exercise."""
32
#Only lecturers and admins can add exercises
33
def get_permissions(self, user):
35
if user.rolenm in ('admin', 'lecturer'):
42
@named_operation('save')
43
def add_exercise(self, req, identifier, name, description, partial, solution, include, num_rows):
45
new_exercise = Exercise()
46
new_exercise.id = unicode(identifier)
47
new_exercise.description = description
48
new_exercise.partial = partial
49
new_exercise.solution = solution
50
new_exercise.include = include
51
new_exercise.num_rows = num_rows
53
req.store.add(new_exercise)
55
return {'result': 'ok'}
59
class ExerciseRESTView(JSONRESTView):
60
"""View for updating Exercises"""
62
def get_permissions(self, user):
64
if user.rolenm in ('admin', 'lecturer'):
71
def __init__(self, req, exercise):
73
self.context = req.store.find(Exercise,
74
Exercise.id == exercise).one()
76
if self.context is None:
79
@named_operation('edit')
80
def update_exercise(self, req, name, description, partial,
81
solution, include, num_rows):
83
self.context.name = unicode(name)
84
self.context.description = unicode(description)
85
self.context.partial = unicode(partial)
86
self.context.solution = unicode(solution)
87
self.context.include = unicode(include)
88
self.context.num_rows = int(num_rows)
90
return {'result': 'ok'}
92
@named_operation('edit')
93
def add_suite(self, req, description, seq_no, function, stdin):
95
new_suite = TestSuite()
96
new_suite.description = description
97
new_suite.seq_no = seq_no
98
new_suite.function = function
99
new_suite.stdin = stdin
100
new_suite.exercise = self.context
102
req.store.add(new_suite)
104
return {'result': 'ok'}
107
class TestSuiteRESTView():
108
"""View for updating Test Suites, adding variable and adding test parts."""
110
def get_permissions(self, user):
112
if user.rolenm in ('admin', 'lecturer'):
119
@named_operation('edit')
120
def edit_testsuite(self, req, suiteid):
122
test_suite = req.store.find(TestSuite,
123
TestSuite.suite.id == suiteid).one()
125
if test_suite is not None:
128
return {'result': 'NOT IMPLEMENTED'}