~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 11:09:50 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: matt.giuca@gmail.com-20090119110950-a40040jv6clxrvej
tutorial: Replaced call to ivle.db.create_worksheet with local code (roughly
    the same algorithm) which uses Worksheet and Exercise.
    This expands the code a lot, but it's all relevant to the tutorial system,
    so it belongs here, and still shorter than db.create_worksheet.
ivle.database: Added new supporting methods for Worksheet and Exercise.
ivle.db: Removed create_worksheet.

Show diffs side-by-side

added added

removed removed

Lines of Context:
348
348
    def __repr__(self):
349
349
        return "<%s %s>" % (type(self).__name__, self.name)
350
350
 
 
351
    @classmethod
 
352
    def get_by_name(cls, store, name):
 
353
        """
 
354
        Get the Exercise from the db associated with a given store and name.
 
355
        """
 
356
        return store.find(cls, cls.name == unicode(name)).one()
 
357
 
351
358
class Worksheet(Storm):
352
359
    __storm_table__ = "worksheet"
353
360
 
386
393
        return store.find(cls, cls.subject == unicode(subjectname),
387
394
            cls.name == unicode(worksheetname)).one()
388
395
 
 
396
    def remove_all_exercises(self, store):
 
397
        """
 
398
        Remove all exercises from this worksheet.
 
399
        This does not delete the exercises themselves. It just removes them
 
400
        from the worksheet.
 
401
        """
 
402
        store.find(WorksheetExercise,
 
403
            WorksheetExercise.worksheet == self).remove()
 
404
 
389
405
class WorksheetExercise(Storm):
390
406
    __storm_table__ = "worksheet_problem"
391
407
    __storm_primary__ = "worksheet_id", "exercise_id"