~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/database.py

  • Committer: William Grant
  • Date: 2009-01-22 04:47:42 UTC
  • mfrom: (1080.1.93 storm)
  • Revision ID: grantw@unimelb.edu.au-20090122044742-sa8gnww0ma2bm2rv
Merge Storm branch. ivle.db is dead. Watch out for the schema change.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
            'ProjectSet', 'Project', 'ProjectGroup', 'ProjectGroupMembership',
40
40
            'Exercise', 'Worksheet', 'WorksheetExercise',
41
41
            'ExerciseSave', 'ExerciseAttempt',
42
 
            'AlreadyEnrolledError', 'TestCase', 'TestSuite'
 
42
            'AlreadyEnrolledError'
43
43
        ]
44
44
 
45
45
def _kwarg_init(self, **kwargs):
196
196
        """
197
197
        return store.find(cls, cls.login == unicode(login)).one()
198
198
 
199
 
    def get_permissions(self, user):
200
 
        if user and user.rolenm == 'admin' or user is self:
201
 
            return set(['view', 'edit'])
202
 
        else:
203
 
            return set()
204
 
 
205
199
# SUBJECTS AND ENROLMENTS #
206
200
 
207
201
class Subject(Storm):
220
214
    def __repr__(self):
221
215
        return "<%s '%s'>" % (type(self).__name__, self.short_name)
222
216
 
223
 
    def get_permissions(self, user):
224
 
        perms = set()
225
 
        if user is not None:
226
 
            perms.add('view')
227
 
        if user.rolenm == 'admin':
228
 
            perms.add('edit')
229
 
        return perms
230
 
 
231
217
class Semester(Storm):
232
218
    __storm_table__ = "semester"
233
219
 
260
246
                           'User.id')
261
247
    project_sets = ReferenceSet(id, 'ProjectSet.offering_id')
262
248
 
263
 
    worksheets = ReferenceSet(id, 'Worksheet.offering_id')
264
 
 
265
249
    __init__ = _kwarg_init
266
250
 
267
251
    def __repr__(self):
387
371
    # Note: Table "problem" is called "Exercise" in the Object layer, since
388
372
    # it's called that everywhere else.
389
373
    __storm_table__ = "problem"
390
 
#TODO: Add in a field for the user-friendly identifier
391
 
    id = Unicode(primary=True, name="identifier")
392
 
    name = Unicode()
393
 
    description = Unicode()
394
 
    partial = Unicode()
395
 
    solution = Unicode()
396
 
    include = Unicode()
397
 
    num_rows = Int()
 
374
 
 
375
    id = Int(primary=True, name="problemid")
 
376
    name = Unicode(name="identifier")
 
377
    spec = Unicode()
398
378
 
399
379
    worksheets = ReferenceSet(id,
400
380
        'WorksheetExercise.exercise_id',
401
381
        'WorksheetExercise.worksheet_id',
402
382
        'Worksheet.id'
403
383
    )
404
 
    
405
 
    test_suites = ReferenceSet(id, 'TestSuite.exercise_id')
406
384
 
407
385
    __init__ = _kwarg_init
408
386
 
431
409
    # XXX subject is not linked to a Subject object. This is a property of
432
410
    # the database, and will be refactored.
433
411
    subject = Unicode()
434
 
    offering_id = Int(name="offeringid")
435
412
    name = Unicode(name="identifier")
436
413
    assessable = Bool()
437
414
    mtime = DateTime()
438
415
 
439
 
    offering = Reference (offeringid, 'Offering.id')
440
 
 
441
416
    exercises = ReferenceSet(id,
442
417
        'WorksheetExercise.worksheet_id',
443
418
        'WorksheetExercise.exercise_id',
447
422
    # "optional" field.
448
423
    worksheet_exercises = ReferenceSet(id,
449
424
        'WorksheetExercise.worksheet_id')
450
 
        
451
425
 
452
426
    __init__ = _kwarg_init
453
427
 
481
455
 
482
456
    worksheet_id = Int(name="worksheetid")
483
457
    worksheet = Reference(worksheet_id, Worksheet.id)
484
 
    exercise_id = Unicode(name="problemid")
 
458
    exercise_id = Int(name="problemid")
485
459
    exercise = Reference(exercise_id, Exercise.id)
486
460
    optional = Bool()
487
461
 
503
477
    __storm_table__ = "problem_save"
504
478
    __storm_primary__ = "exercise_id", "user_id", "date"
505
479
 
506
 
    exercise_id = Unicode(name="problemid")
 
480
    exercise_id = Int(name="problemid")
507
481
    exercise = Reference(exercise_id, Exercise.id)
508
482
    user_id = Int(name="loginid")
509
483
    user = Reference(user_id, User.id)
510
484
    date = DateTime()
511
485
    text = Unicode()
512
 
    worksheetid = Int()
513
 
    worksheet = Reference(worksheetid, Worksheet.id)
514
486
 
515
487
    __init__ = _kwarg_init
516
488
 
539
511
    text = Unicode(name="attempt")
540
512
    complete = Bool()
541
513
    active = Bool()
542
 
    
543
 
    def get_permissions(self, user):
544
 
        return set(['view']) if user is self.user else set()
545
 
  
546
 
class TestSuite(Storm):
547
 
    """A Testsuite acts as a container for the test cases of an exercise."""
548
 
    __storm_table__ = "test_suite"
549
 
    __storm_primary__ = "exercise_id", "suiteid"
550
 
    
551
 
    suiteid = Int()
552
 
    exercise_id = Unicode(name="problemid")
553
 
    exercise = Reference(exercise_id, Exercise.id)
554
 
    test_cases = ReferenceSet(suiteid, 'TestCase.suiteid')
555
 
    description = Unicode()
556
 
    seq_no = Int()
557
 
 
558
 
class TestCase(Storm):
559
 
    """A TestCase is a member of a TestSuite.
560
 
    
561
 
    It contains the data necessary to check if an exercise is correct"""
562
 
    __storm_table__ = "test_case"
563
 
    __storm_primary__ = "testid", "suiteid"
564
 
    
565
 
    testid = Int()
566
 
    suiteid = Int()
567
 
    suite = Reference(suiteid, TestSuite.suiteid)
568
 
    passmsg = Unicode()
569
 
    failmsg = Unicode()
570
 
    init = Unicode()
571
 
    code_type = Unicode()
572
 
    code = Unicode()
573
 
    testtype = Unicode()
574
 
    seq_no = Int()
575
 
    
576
 
    __init__ = _kwarg_init