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,
284
278
e = Enrolment(user=user, offering=self, active=True)
285
279
self.enrolments.add(e)
287
def get_permissions(self, user):
291
if user.rolenm == 'admin':
295
281
class Enrolment(Storm):
296
282
__storm_table__ = "enrolment"
297
283
__storm_primary__ = "user_id", "offering_id"
399
385
# Note: Table "problem" is called "Exercise" in the Object layer, since
400
386
# it's called that everywhere else.
401
387
__storm_table__ = "problem"
402
#TODO: Add in a field for the user-friendly identifier
403
id = Unicode(primary=True, name="identifier")
405
description = Unicode()
389
id = Int(primary=True, name="problemid")
390
name = Unicode(name="identifier")
411
393
worksheets = ReferenceSet(id,
412
394
'WorksheetExercise.exercise_id',
413
395
'WorksheetExercise.worksheet_id',
417
test_suites = ReferenceSet(id, 'TestSuite.exercise_id')
419
399
__init__ = _kwarg_init
421
401
def __repr__(self):
422
402
return "<%s %s>" % (type(self).__name__, self.name)
405
def get_by_name(cls, store, name):
407
Get the Exercise from the db associated with a given store and name.
408
If the exercise is not in the database, creates it and inserts it
411
ex = store.find(cls, cls.name == unicode(name)).one()
414
ex = Exercise(name=unicode(name))
425
419
class Worksheet(Storm):
426
420
__storm_table__ = "worksheet"
428
422
id = Int(primary=True, name="worksheetid")
429
423
# XXX subject is not linked to a Subject object. This is a property of
430
424
# the database, and will be refactored.
431
offering_id = Int(name="offeringid")
432
426
name = Unicode(name="identifier")
433
427
assessable = Bool()
434
428
mtime = DateTime()
436
attempts = ReferenceSet(id, "ExerciseAttempt.worksheetid")
437
offering = Reference(offering_id, 'Offering.id')
439
430
exercises = ReferenceSet(id,
440
431
'WorksheetExercise.worksheet_id',
441
432
'WorksheetExercise.exercise_id',
473
463
store.find(WorksheetExercise,
474
464
WorksheetExercise.worksheet == self).remove()
476
def get_permissions(self, user):
477
return self.offering.get_permissions(user)
479
466
class WorksheetExercise(Storm):
480
467
__storm_table__ = "worksheet_problem"
483
470
worksheet_id = Int(name="worksheetid")
484
471
worksheet = Reference(worksheet_id, Worksheet.id)
485
exercise_id = Unicode(name="problemid")
472
exercise_id = Int(name="problemid")
486
473
exercise = Reference(exercise_id, Exercise.id)
487
474
optional = Bool()
504
491
__storm_table__ = "problem_save"
505
492
__storm_primary__ = "exercise_id", "user_id", "date"
507
exercise_id = Unicode(name="problemid")
494
exercise_id = Int(name="problemid")
508
495
exercise = Reference(exercise_id, Exercise.id)
509
496
user_id = Int(name="loginid")
510
497
user = Reference(user_id, User.id)
511
498
date = DateTime()
514
worksheet = Reference(worksheetid, Worksheet.id)
516
501
__init__ = _kwarg_init
540
525
text = Unicode(name="attempt")
541
526
complete = Bool()
544
529
def get_permissions(self, user):
545
530
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