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

« back to all changes in this revision

Viewing changes to ivle/database.py

Expose media on the public site.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
    """
54
54
    Returns the Storm connection string, generated from the conf file.
55
55
    """
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,
58
 
        ivle.conf.db_dbname)
 
56
 
 
57
    clusterstr = ''
 
58
    if ivle.conf.db_user:
 
59
        clusterstr += ivle.conf.db_user
 
60
        if ivle.conf.db_password:
 
61
            clusterstr += ':' + ivle.conf.db_password
 
62
        clusterstr += '@'
 
63
 
 
64
    host = ivle.conf.db_host or 'localhost'
 
65
    port = ivle.conf.db_port or 5432
 
66
 
 
67
    clusterstr += '%s:%d' % (host, port)
 
68
 
 
69
    return "postgres://%s/%s" % (clusterstr, ivle.conf.db_dbname)
59
70
 
60
71
def get_store():
61
72
    """
264
275
                           'User.id')
265
276
    project_sets = ReferenceSet(id, 'ProjectSet.offering_id')
266
277
 
267
 
    worksheets = ReferenceSet(id, 'Worksheet.offering_id')
 
278
    worksheets = ReferenceSet(id, 
 
279
        'Worksheet.offering_id', 
 
280
        order_by="Worksheet.seq_no"
 
281
    )
268
282
 
269
283
    __init__ = _kwarg_init
270
284
 
396
410
# WORKSHEETS AND EXERCISES #
397
411
 
398
412
class Exercise(Storm):
399
 
    # Note: Table "problem" is called "Exercise" in the Object layer, since
400
 
    # it's called that everywhere else.
401
 
    __storm_table__ = "problem"
402
 
#TODO: Add in a field for the user-friendly identifier
 
413
    __storm_table__ = "exercise"
403
414
    id = Unicode(primary=True, name="identifier")
404
415
    name = Unicode()
405
416
    description = Unicode()
426
437
    __storm_table__ = "worksheet"
427
438
 
428
439
    id = Int(primary=True, name="worksheetid")
429
 
    # XXX subject is not linked to a Subject object. This is a property of
430
 
    # the database, and will be refactored.
431
440
    offering_id = Int(name="offeringid")
432
 
    name = Unicode(name="identifier")
 
441
    identifier = Unicode()
 
442
    name = Unicode()
433
443
    assessable = Bool()
434
 
    mtime = DateTime()
 
444
    data = Unicode()
 
445
    seq_no = Int()
 
446
    format = Unicode()
435
447
 
436
448
    attempts = ReferenceSet(id, "ExerciseAttempt.worksheetid")
437
449
    offering = Reference(offering_id, 'Offering.id')
438
450
 
439
 
    exercises = ReferenceSet(id,
440
 
        'WorksheetExercise.worksheet_id',
441
 
        'WorksheetExercise.exercise_id',
442
 
        Exercise.id)
443
451
    # Use worksheet_exercises to get access to the WorksheetExercise objects
444
452
    # binding worksheets to exercises. This is required to access the
445
453
    # "optional" field.
477
485
        return self.offering.get_permissions(user)
478
486
 
479
487
class WorksheetExercise(Storm):
480
 
    __storm_table__ = "worksheet_problem"
481
 
    __storm_primary__ = "worksheet_id", "exercise_id"
 
488
    __storm_table__ = "worksheet_exercise"
 
489
    
 
490
    id = Int(primary=True, name="ws_ex_id")
482
491
 
483
492
    worksheet_id = Int(name="worksheetid")
484
493
    worksheet = Reference(worksheet_id, Worksheet.id)
485
 
    exercise_id = Unicode(name="problemid")
 
494
    exercise_id = Unicode(name="exerciseid")
486
495
    exercise = Reference(exercise_id, Exercise.id)
487
496
    optional = Bool()
 
497
    active = Bool()
 
498
    seq_no = Int()
 
499
    
 
500
    saves = ReferenceSet(id, "ExerciseSave.ws_ex_id")
 
501
    attempts = ReferenceSet(id, "ExerciseAttempt.ws_ex_id")
488
502
 
489
503
    __init__ = _kwarg_init
490
504
 
491
505
    def __repr__(self):
492
506
        return "<%s %s in %s>" % (type(self).__name__, self.exercise.name,
493
 
                                  self.worksheet.name)
 
507
                                  self.worksheet.identifier)
494
508
 
495
509
class ExerciseSave(Storm):
496
510
    """
501
515
    ExerciseSave may be extended with additional semantics (such as
502
516
    ExerciseAttempt).
503
517
    """
504
 
    __storm_table__ = "problem_save"
505
 
    __storm_primary__ = "exercise_id", "user_id", "date"
506
 
 
507
 
    exercise_id = Unicode(name="problemid")
508
 
    exercise = Reference(exercise_id, Exercise.id)
 
518
    __storm_table__ = "exercise_save"
 
519
    __storm_primary__ = "ws_ex_id", "user_id"
 
520
 
 
521
    ws_ex_id = Int(name="ws_ex_id")
 
522
    worksheet_exercise = Reference(ws_ex_id, "WorksheetExercise.id")
 
523
 
509
524
    user_id = Int(name="loginid")
510
525
    user = Reference(user_id, User.id)
511
526
    date = DateTime()
512
527
    text = Unicode()
513
 
    worksheetid = Int()
514
 
    worksheet = Reference(worksheetid, Worksheet.id)
515
528
 
516
529
    __init__ = _kwarg_init
517
530
 
532
545
        they won't count (either as a penalty or success), but will still be
533
546
        stored.
534
547
    """
535
 
    __storm_table__ = "problem_attempt"
536
 
    __storm_primary__ = "exercise_id", "user_id", "date"
 
548
    __storm_table__ = "exercise_attempt"
 
549
    __storm_primary__ = "ws_ex_id", "user_id", "date"
537
550
 
538
551
    # The "text" field is the same but has a different name in the DB table
539
552
    # for some reason.
550
563
    __storm_primary__ = "exercise_id", "suiteid"
551
564
    
552
565
    suiteid = Int()
553
 
    exercise_id = Unicode(name="problemid")
 
566
    exercise_id = Unicode(name="exerciseid")
554
567
    description = Unicode()
555
568
    seq_no = Int()
556
569
    function = Unicode()
580
593
 
581
594
class TestSuiteVar(Storm):
582
595
    """A container for the arguments of a Test Suite"""
583
 
    __storm_table__ = "suite_variables"
 
596
    __storm_table__ = "suite_variable"
584
597
    __storm_primary__ = "varid"
585
598
    
586
599
    varid = Int()
596
609
    
597
610
class TestCasePart(Storm):
598
611
    """A container for the test elements of a Test Case"""
599
 
    __storm_table__ = "test_case_parts"
 
612
    __storm_table__ = "test_case_part"
600
613
    __storm_primary__ = "partid"
601
614
    
602
615
    partid = Int()