39
39
'ProjectSet', 'Project', 'ProjectGroup', 'ProjectGroupMembership',
40
40
'Exercise', 'Worksheet', 'WorksheetExercise',
41
41
'ExerciseSave', 'ExerciseAttempt',
42
'AlreadyEnrolledError', 'TestCase', 'TestSuite', 'TestSuiteVar'
42
'AlreadyEnrolledError'
45
45
def _kwarg_init(self, **kwargs):
130
130
fieldval = self.acct_exp
131
131
return fieldval is not None and datetime.datetime.now() > fieldval
135
return self.state == 'enabled' and not self.account_expired
137
133
def _get_enrolments(self, justactive):
138
134
return Store.of(self).find(Enrolment,
139
135
Enrolment.user_id == self.id,
201
197
return store.find(cls, cls.login == unicode(login)).one()
203
def get_permissions(self, user):
204
if user and user.rolenm == 'admin' or user is self:
205
return set(['view', 'edit'])
209
199
# SUBJECTS AND ENROLMENTS #
211
201
class Subject(Storm):
224
214
def __repr__(self):
225
215
return "<%s '%s'>" % (type(self).__name__, self.short_name)
227
def get_permissions(self, user):
231
if user.rolenm == 'admin':
235
217
class Semester(Storm):
236
218
__storm_table__ = "semester"
284
264
e = Enrolment(user=user, offering=self, active=True)
285
265
self.enrolments.add(e)
287
def get_permissions(self, user):
291
if user.rolenm == 'admin':
295
267
class Enrolment(Storm):
296
268
__storm_table__ = "enrolment"
297
269
__storm_primary__ = "user_id", "offering_id"
399
371
# Note: Table "problem" is called "Exercise" in the Object layer, since
400
372
# it's called that everywhere else.
401
373
__storm_table__ = "problem"
402
#TODO: Add in a field for the user-friendly identifier
403
id = Unicode(primary=True, name="identifier")
405
description = Unicode()
375
id = Int(primary=True, name="problemid")
376
name = Unicode(name="identifier")
411
379
worksheets = ReferenceSet(id,
412
380
'WorksheetExercise.exercise_id',
413
381
'WorksheetExercise.worksheet_id',
417
test_suites = ReferenceSet(id, 'TestSuite.exercise_id')
419
385
__init__ = _kwarg_init
421
387
def __repr__(self):
422
388
return "<%s %s>" % (type(self).__name__, self.name)
391
def get_by_name(cls, store, name):
393
Get the Exercise from the db associated with a given store and name.
394
If the exercise is not in the database, creates it and inserts it
397
ex = store.find(cls, cls.name == unicode(name)).one()
400
ex = Exercise(name=unicode(name))
425
405
class Worksheet(Storm):
426
406
__storm_table__ = "worksheet"
428
408
id = Int(primary=True, name="worksheetid")
429
409
# XXX subject is not linked to a Subject object. This is a property of
430
410
# the database, and will be refactored.
431
offering_id = Int(name="offeringid")
432
412
name = Unicode(name="identifier")
433
413
assessable = Bool()
434
414
mtime = DateTime()
436
attempts = ReferenceSet(id, "ExerciseAttempt.worksheetid")
437
offering = Reference(offering_id, 'Offering.id')
439
416
exercises = ReferenceSet(id,
440
417
'WorksheetExercise.worksheet_id',
441
418
'WorksheetExercise.exercise_id',
473
449
store.find(WorksheetExercise,
474
450
WorksheetExercise.worksheet == self).remove()
476
def get_permissions(self, user):
477
return self.offering.get_permissions(user)
479
452
class WorksheetExercise(Storm):
480
453
__storm_table__ = "worksheet_problem"
483
456
worksheet_id = Int(name="worksheetid")
484
457
worksheet = Reference(worksheet_id, Worksheet.id)
485
exercise_id = Unicode(name="problemid")
458
exercise_id = Int(name="problemid")
486
459
exercise = Reference(exercise_id, Exercise.id)
487
460
optional = Bool()
504
477
__storm_table__ = "problem_save"
505
478
__storm_primary__ = "exercise_id", "user_id", "date"
507
exercise_id = Unicode(name="problemid")
480
exercise_id = Int(name="problemid")
508
481
exercise = Reference(exercise_id, Exercise.id)
509
482
user_id = Int(name="loginid")
510
483
user = Reference(user_id, User.id)
511
484
date = DateTime()
514
worksheet = Reference(worksheetid, Worksheet.id)
516
487
__init__ = _kwarg_init
540
511
text = Unicode(name="attempt")
541
512
complete = Bool()
544
def get_permissions(self, user):
545
return set(['view']) if user is self.user else set()
547
class TestSuite(Storm):
548
"""A Testsuite acts as a container for the test cases of an exercise."""
549
__storm_table__ = "test_suite"
550
__storm_primary__ = "exercise_id", "suiteid"
553
exercise_id = Unicode(name="problemid")
554
description = Unicode()
558
exercise = Reference(exercise_id, Exercise.id)
559
test_cases = ReferenceSet(suiteid, 'TestCase.suiteid')
560
variables = ReferenceSet(suiteid, 'TestSuiteVar.suiteid')
562
class TestCase(Storm):
563
"""A TestCase is a member of a TestSuite.
565
It contains the data necessary to check if an exercise is correct"""
566
__storm_table__ = "test_case"
567
__storm_primary__ = "testid", "suiteid"
571
suite = Reference(suiteid, "TestSuite.suiteid")
574
test_default = Unicode()
577
parts = ReferenceSet(testid, "TestCasePart.testid")
579
__init__ = _kwarg_init
581
class TestSuiteVar(Storm):
582
"""A container for the arguments of a Test Suite"""
583
__storm_table__ = "suite_variables"
584
__storm_primary__ = "varid"
589
var_value = Unicode()
593
suite = Reference(suiteid, "TestSuite.suiteid")
595
__init__ = _kwarg_init
597
class TestCasePart(Storm):
598
"""A container for the test elements of a Test Case"""
599
__storm_table__ = "test_case_parts"
600
__storm_primary__ = "partid"
605
part_type = Unicode()
606
test_type = Unicode()
610
test = Reference(testid, "TestCase.testid")
612
__init__ = _kwarg_init