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

« back to all changes in this revision

Viewing changes to ivle/database.py

This commit changes the tutorial service, which now almost exclusively
uses the database to store its data.

Whilst the modifications to tutorial are not yet complete, this commit
should stabilise the database model.

Show diffs side-by-side

added added

removed removed

Lines of Context:
275
275
                           'User.id')
276
276
    project_sets = ReferenceSet(id, 'ProjectSet.offering_id')
277
277
 
278
 
    worksheets = ReferenceSet(id, 'Worksheet.offering_id')
 
278
    worksheets = ReferenceSet(id, 
 
279
        'Worksheet.offering_id', 
 
280
        order_by="Worksheet.seq_no"
 
281
    )
279
282
 
280
283
    __init__ = _kwarg_init
281
284
 
410
413
    # Note: Table "problem" is called "Exercise" in the Object layer, since
411
414
    # it's called that everywhere else.
412
415
    __storm_table__ = "problem"
413
 
#TODO: Add in a field for the user-friendly identifier
414
416
    id = Unicode(primary=True, name="identifier")
415
417
    name = Unicode()
416
418
    description = Unicode()
437
439
    __storm_table__ = "worksheet"
438
440
 
439
441
    id = Int(primary=True, name="worksheetid")
440
 
    # XXX subject is not linked to a Subject object. This is a property of
441
 
    # the database, and will be refactored.
442
442
    offering_id = Int(name="offeringid")
443
 
    name = Unicode(name="identifier")
 
443
    identifier = Unicode()
 
444
    name = Unicode()
444
445
    assessable = Bool()
445
 
    mtime = DateTime()
 
446
    data = Unicode()
 
447
    seq_no = Int()
 
448
    format = Unicode()
446
449
 
447
450
    attempts = ReferenceSet(id, "ExerciseAttempt.worksheetid")
448
451
    offering = Reference(offering_id, 'Offering.id')
449
452
 
450
 
    exercises = ReferenceSet(id,
451
 
        'WorksheetExercise.worksheet_id',
452
 
        'WorksheetExercise.exercise_id',
453
 
        Exercise.id)
454
453
    # Use worksheet_exercises to get access to the WorksheetExercise objects
455
454
    # binding worksheets to exercises. This is required to access the
456
455
    # "optional" field.
489
488
 
490
489
class WorksheetExercise(Storm):
491
490
    __storm_table__ = "worksheet_problem"
492
 
    __storm_primary__ = "worksheet_id", "exercise_id"
 
491
    
 
492
    id = Int(primary=True, name="ws_prob_id")
493
493
 
494
494
    worksheet_id = Int(name="worksheetid")
495
495
    worksheet = Reference(worksheet_id, Worksheet.id)
496
496
    exercise_id = Unicode(name="problemid")
497
497
    exercise = Reference(exercise_id, Exercise.id)
498
498
    optional = Bool()
 
499
    active = Bool()
 
500
    seq_no = Int()
 
501
    
 
502
    saves = ReferenceSet(id, "ExerciseSave.ws_ex_id")
 
503
    attempts = ReferenceSet(id, "ExerciseAttemot.ws_ex_id")
499
504
 
500
505
    __init__ = _kwarg_init
501
506
 
502
507
    def __repr__(self):
503
508
        return "<%s %s in %s>" % (type(self).__name__, self.exercise.name,
504
 
                                  self.worksheet.name)
 
509
                                  self.worksheet.identifier)
505
510
 
506
511
class ExerciseSave(Storm):
507
512
    """
513
518
    ExerciseAttempt).
514
519
    """
515
520
    __storm_table__ = "problem_save"
516
 
    __storm_primary__ = "exercise_id", "user_id", "date"
517
 
 
518
 
    exercise_id = Unicode(name="problemid")
519
 
    exercise = Reference(exercise_id, Exercise.id)
 
521
    __storm_primary__ = "ws_ex_id", "user_id"
 
522
 
 
523
    ws_ex_id = Int(name="ws_prob_id")
 
524
    worksheet_exercise = Reference(ws_ex_id, "WorksheetExercise.id")
 
525
 
520
526
    user_id = Int(name="loginid")
521
527
    user = Reference(user_id, User.id)
522
528
    date = DateTime()
523
529
    text = Unicode()
524
 
    worksheetid = Int()
525
 
    worksheet = Reference(worksheetid, Worksheet.id)
526
530
 
527
531
    __init__ = _kwarg_init
528
532
 
544
548
        stored.
545
549
    """
546
550
    __storm_table__ = "problem_attempt"
547
 
    __storm_primary__ = "exercise_id", "user_id", "date"
 
551
    __storm_primary__ = "ws_ex_id", "user_id", "date"
548
552
 
549
553
    # The "text" field is the same but has a different name in the DB table
550
554
    # for some reason.