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):
54
54
Returns the Storm connection string, generated from the conf file.
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)
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,
141
130
fieldval = self.acct_exp
142
131
return fieldval is not None and datetime.datetime.now() > fieldval
146
return self.state == 'enabled' and not self.account_expired
148
133
def _get_enrolments(self, justactive):
149
134
return Store.of(self).find(Enrolment,
150
135
Enrolment.user_id == self.id,
212
197
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'])
220
199
# SUBJECTS AND ENROLMENTS #
222
201
class Subject(Storm):
235
214
def __repr__(self):
236
215
return "<%s '%s'>" % (type(self).__name__, self.short_name)
238
def get_permissions(self, user):
242
if user.rolenm == 'admin':
246
217
class Semester(Storm):
247
218
__storm_table__ = "semester"
295
264
e = Enrolment(user=user, offering=self, active=True)
296
265
self.enrolments.add(e)
298
def get_permissions(self, user):
302
if user.rolenm == 'admin':
306
267
class Enrolment(Storm):
307
268
__storm_table__ = "enrolment"
308
269
__storm_primary__ = "user_id", "offering_id"
410
371
# Note: Table "problem" is called "Exercise" in the Object layer, since
411
372
# it's called that everywhere else.
412
373
__storm_table__ = "problem"
413
#TODO: Add in a field for the user-friendly identifier
414
id = Unicode(primary=True, name="identifier")
416
description = Unicode()
375
id = Int(primary=True, name="problemid")
376
name = Unicode(name="identifier")
422
379
worksheets = ReferenceSet(id,
423
380
'WorksheetExercise.exercise_id',
424
381
'WorksheetExercise.worksheet_id',
428
test_suites = ReferenceSet(id, 'TestSuite.exercise_id')
430
385
__init__ = _kwarg_init
432
387
def __repr__(self):
433
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))
436
405
class Worksheet(Storm):
437
406
__storm_table__ = "worksheet"
439
408
id = Int(primary=True, name="worksheetid")
440
409
# XXX subject is not linked to a Subject object. This is a property of
441
410
# the database, and will be refactored.
442
offering_id = Int(name="offeringid")
443
412
name = Unicode(name="identifier")
444
413
assessable = Bool()
445
414
mtime = DateTime()
447
attempts = ReferenceSet(id, "ExerciseAttempt.worksheetid")
448
offering = Reference(offering_id, 'Offering.id')
450
416
exercises = ReferenceSet(id,
451
417
'WorksheetExercise.worksheet_id',
452
418
'WorksheetExercise.exercise_id',
484
449
store.find(WorksheetExercise,
485
450
WorksheetExercise.worksheet == self).remove()
487
def get_permissions(self, user):
488
return self.offering.get_permissions(user)
490
452
class WorksheetExercise(Storm):
491
453
__storm_table__ = "worksheet_problem"
494
456
worksheet_id = Int(name="worksheetid")
495
457
worksheet = Reference(worksheet_id, Worksheet.id)
496
exercise_id = Unicode(name="problemid")
458
exercise_id = Int(name="problemid")
497
459
exercise = Reference(exercise_id, Exercise.id)
498
460
optional = Bool()
515
477
__storm_table__ = "problem_save"
516
478
__storm_primary__ = "exercise_id", "user_id", "date"
518
exercise_id = Unicode(name="problemid")
480
exercise_id = Int(name="problemid")
519
481
exercise = Reference(exercise_id, Exercise.id)
520
482
user_id = Int(name="loginid")
521
483
user = Reference(user_id, User.id)
522
484
date = DateTime()
525
worksheet = Reference(worksheetid, Worksheet.id)
527
487
__init__ = _kwarg_init
551
511
text = Unicode(name="attempt")
552
512
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