39
39
'ProjectSet', 'Project', 'ProjectGroup', 'ProjectGroupMembership',
40
40
'Exercise', 'Worksheet', 'WorksheetExercise',
41
41
'ExerciseSave', 'ExerciseAttempt',
42
'AlreadyEnrolledError'
42
'AlreadyEnrolledError', 'TestCase', 'TestSuite', 'TestSuiteVar'
45
45
def _kwarg_init(self, **kwargs):
54
54
Returns the Storm connection string, generated from the conf file.
56
return "postgres://%s:%s@%s:%d/%s" % (ivle.conf.db_user,
57
ivle.conf.db_password, ivle.conf.db_host, ivle.conf.db_port,
59
clusterstr += ivle.conf.db_user
60
if ivle.conf.db_password:
61
clusterstr += ':' + ivle.conf.db_password
64
host = ivle.conf.db_host or 'localhost'
65
port = ivle.conf.db_port or 5432
67
clusterstr += '%s:%d' % (host, port)
69
return "postgres://%s/%s" % (clusterstr, ivle.conf.db_dbname)
130
141
fieldval = self.acct_exp
131
142
return fieldval is not None and datetime.datetime.now() > fieldval
146
return self.state == 'enabled' and not self.account_expired
133
148
def _get_enrolments(self, justactive):
134
149
return Store.of(self).find(Enrolment,
135
150
Enrolment.user_id == self.id,
197
212
return store.find(cls, cls.login == unicode(login)).one()
214
def get_permissions(self, user):
215
if user and user.rolenm == 'admin' or user is self:
216
return set(['view', 'edit'])
199
220
# SUBJECTS AND ENROLMENTS #
201
222
class Subject(Storm):
214
235
def __repr__(self):
215
236
return "<%s '%s'>" % (type(self).__name__, self.short_name)
238
def get_permissions(self, user):
242
if user.rolenm == 'admin':
217
246
class Semester(Storm):
218
247
__storm_table__ = "semester"
264
295
e = Enrolment(user=user, offering=self, active=True)
265
296
self.enrolments.add(e)
298
def get_permissions(self, user):
302
if user.rolenm == 'admin':
267
306
class Enrolment(Storm):
268
307
__storm_table__ = "enrolment"
269
308
__storm_primary__ = "user_id", "offering_id"
371
410
# Note: Table "problem" is called "Exercise" in the Object layer, since
372
411
# it's called that everywhere else.
373
412
__storm_table__ = "problem"
375
id = Int(primary=True, name="problemid")
376
name = Unicode(name="identifier")
413
#TODO: Add in a field for the user-friendly identifier
414
id = Unicode(primary=True, name="identifier")
416
description = Unicode()
379
422
worksheets = ReferenceSet(id,
380
423
'WorksheetExercise.exercise_id',
381
424
'WorksheetExercise.worksheet_id',
428
test_suites = ReferenceSet(id, 'TestSuite.exercise_id')
385
430
__init__ = _kwarg_init
387
432
def __repr__(self):
388
433
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))
405
436
class Worksheet(Storm):
406
437
__storm_table__ = "worksheet"
408
439
id = Int(primary=True, name="worksheetid")
409
440
# XXX subject is not linked to a Subject object. This is a property of
410
441
# the database, and will be refactored.
442
offering_id = Int(name="offeringid")
412
443
name = Unicode(name="identifier")
413
444
assessable = Bool()
414
445
mtime = DateTime()
447
attempts = ReferenceSet(id, "ExerciseAttempt.worksheetid")
448
offering = Reference(offering_id, 'Offering.id')
416
450
exercises = ReferenceSet(id,
417
451
'WorksheetExercise.worksheet_id',
418
452
'WorksheetExercise.exercise_id',
449
484
store.find(WorksheetExercise,
450
485
WorksheetExercise.worksheet == self).remove()
487
def get_permissions(self, user):
488
return self.offering.get_permissions(user)
452
490
class WorksheetExercise(Storm):
453
491
__storm_table__ = "worksheet_problem"
456
494
worksheet_id = Int(name="worksheetid")
457
495
worksheet = Reference(worksheet_id, Worksheet.id)
458
exercise_id = Int(name="problemid")
496
exercise_id = Unicode(name="problemid")
459
497
exercise = Reference(exercise_id, Exercise.id)
460
498
optional = Bool()
477
515
__storm_table__ = "problem_save"
478
516
__storm_primary__ = "exercise_id", "user_id", "date"
480
exercise_id = Int(name="problemid")
518
exercise_id = Unicode(name="problemid")
481
519
exercise = Reference(exercise_id, Exercise.id)
482
520
user_id = Int(name="loginid")
483
521
user = Reference(user_id, User.id)
484
522
date = DateTime()
525
worksheet = Reference(worksheetid, Worksheet.id)
487
527
__init__ = _kwarg_init
511
551
text = Unicode(name="attempt")
512
552
complete = Bool()
555
def get_permissions(self, user):
556
return set(['view']) if user is self.user else set()
558
class TestSuite(Storm):
559
"""A Testsuite acts as a container for the test cases of an exercise."""
560
__storm_table__ = "test_suite"
561
__storm_primary__ = "exercise_id", "suiteid"
564
exercise_id = Unicode(name="problemid")
565
description = Unicode()
569
exercise = Reference(exercise_id, Exercise.id)
570
test_cases = ReferenceSet(suiteid, 'TestCase.suiteid')
571
variables = ReferenceSet(suiteid, 'TestSuiteVar.suiteid')
573
class TestCase(Storm):
574
"""A TestCase is a member of a TestSuite.
576
It contains the data necessary to check if an exercise is correct"""
577
__storm_table__ = "test_case"
578
__storm_primary__ = "testid", "suiteid"
582
suite = Reference(suiteid, "TestSuite.suiteid")
585
test_default = Unicode()
588
parts = ReferenceSet(testid, "TestCasePart.testid")
590
__init__ = _kwarg_init
592
class TestSuiteVar(Storm):
593
"""A container for the arguments of a Test Suite"""
594
__storm_table__ = "suite_variables"
595
__storm_primary__ = "varid"
600
var_value = Unicode()
604
suite = Reference(suiteid, "TestSuite.suiteid")
606
__init__ = _kwarg_init
608
class TestCasePart(Storm):
609
"""A container for the test elements of a Test Case"""
610
__storm_table__ = "test_case_parts"
611
__storm_primary__ = "partid"
616
part_type = Unicode()
617
test_type = Unicode()
621
test = Reference(testid, "TestCase.testid")
623
__init__ = _kwarg_init