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

« back to all changes in this revision

Viewing changes to ivle/database.py

Merge from new-dispatch.

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'
 
42
            'AlreadyEnrolledError', 'TestCase', 'TestSuite'
43
43
        ]
44
44
 
45
45
def _kwarg_init(self, **kwargs):
260
260
                           'User.id')
261
261
    project_sets = ReferenceSet(id, 'ProjectSet.offering_id')
262
262
 
 
263
    worksheets = ReferenceSet(id, 'Worksheet.offering_id')
 
264
 
263
265
    __init__ = _kwarg_init
264
266
 
265
267
    def __repr__(self):
385
387
    # Note: Table "problem" is called "Exercise" in the Object layer, since
386
388
    # it's called that everywhere else.
387
389
    __storm_table__ = "problem"
388
 
 
389
 
    id = Int(primary=True, name="problemid")
390
 
    name = Unicode(name="identifier")
391
 
    spec = Unicode()
 
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()
392
398
 
393
399
    worksheets = ReferenceSet(id,
394
400
        'WorksheetExercise.exercise_id',
395
401
        'WorksheetExercise.worksheet_id',
396
402
        'Worksheet.id'
397
403
    )
 
404
    
 
405
    test_suites = ReferenceSet(id, 'TestSuite.exercise_id')
398
406
 
399
407
    __init__ = _kwarg_init
400
408
 
423
431
    # XXX subject is not linked to a Subject object. This is a property of
424
432
    # the database, and will be refactored.
425
433
    subject = Unicode()
 
434
    offering_id = Int(name="offeringid")
426
435
    name = Unicode(name="identifier")
427
436
    assessable = Bool()
428
437
    mtime = DateTime()
429
438
 
 
439
    offering = Reference (offeringid, 'Offering.id')
 
440
 
430
441
    exercises = ReferenceSet(id,
431
442
        'WorksheetExercise.worksheet_id',
432
443
        'WorksheetExercise.exercise_id',
436
447
    # "optional" field.
437
448
    worksheet_exercises = ReferenceSet(id,
438
449
        'WorksheetExercise.worksheet_id')
 
450
        
439
451
 
440
452
    __init__ = _kwarg_init
441
453
 
469
481
 
470
482
    worksheet_id = Int(name="worksheetid")
471
483
    worksheet = Reference(worksheet_id, Worksheet.id)
472
 
    exercise_id = Int(name="problemid")
 
484
    exercise_id = Unicode(name="problemid")
473
485
    exercise = Reference(exercise_id, Exercise.id)
474
486
    optional = Bool()
475
487
 
491
503
    __storm_table__ = "problem_save"
492
504
    __storm_primary__ = "exercise_id", "user_id", "date"
493
505
 
494
 
    exercise_id = Int(name="problemid")
 
506
    exercise_id = Unicode(name="problemid")
495
507
    exercise = Reference(exercise_id, Exercise.id)
496
508
    user_id = Int(name="loginid")
497
509
    user = Reference(user_id, User.id)
498
510
    date = DateTime()
499
511
    text = Unicode()
 
512
    worksheetid = Int()
 
513
    worksheet = Reference(worksheetid, Worksheet.id)
500
514
 
501
515
    __init__ = _kwarg_init
502
516
 
525
539
    text = Unicode(name="attempt")
526
540
    complete = Bool()
527
541
    active = Bool()
528
 
 
 
542
    
529
543
    def get_permissions(self, user):
530
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