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

« back to all changes in this revision

Viewing changes to ivle/database.py

  • Committer: Matt Giuca
  • Date: 2009-01-19 10:48:01 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: matt.giuca@gmail.com-20090119104801-kkc5mjnzkpt8gb81
ivle.database: Added WorksheetExercise (relates worksheets to exercises), and
    added ReferenceSets to Worksheet and Exercise classes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
337
337
    name = Unicode(name="identifier")
338
338
    spec = Unicode()
339
339
 
 
340
    worksheets = ReferenceSet(id,
 
341
        'WorksheetExercise.exercise_id',
 
342
        'WorksheetExercise.worksheet_id',
 
343
        'Worksheet.id'
 
344
    )
 
345
 
340
346
    __init__ = _kwarg_init
341
347
 
342
348
    def __repr__(self):
353
359
    assessable = Bool()
354
360
    mtime = DateTime()
355
361
 
 
362
    exercises = ReferenceSet(id,
 
363
        'WorksheetExercise.worksheet_id',
 
364
        'WorksheetExercise.exercise_id',
 
365
        Exercise.id)
 
366
    # Use worksheet_exercises to get access to the WorksheetExercise objects
 
367
    # binding worksheets to exercises. This is required to access the
 
368
    # "optional" field.
 
369
    worksheet_exercises = ReferenceSet(id,
 
370
        'WorksheetExercise.worksheet_id')
 
371
 
356
372
    __init__ = _kwarg_init
357
373
 
358
374
    def __repr__(self):
369
385
        """
370
386
        return store.find(cls, cls.subject == unicode(subjectname),
371
387
            cls.name == unicode(worksheetname)).one()
 
388
 
 
389
class WorksheetExercise(Storm):
 
390
    __storm_table__ = "worksheet_problem"
 
391
    __storm_primary__ = "worksheet_id", "exercise_id"
 
392
 
 
393
    worksheet_id = Int(name="worksheetid")
 
394
    worksheet = Reference(worksheet_id, Worksheet.id)
 
395
    exercise_id = Int(name="problemid")
 
396
    exercise = Reference(exercise_id, Exercise.id)
 
397
    optional = Bool()
 
398
 
 
399
    __init__ = _kwarg_init
 
400
 
 
401
    def __repr__(self):
 
402
        return "<%s %s in %s>" % (type(self).__name__, self.exercise.name,
 
403
                                  self.worksheet.name)