~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:20:16 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: matt.giuca@gmail.com-20090119112016-b1n3y6vhh9s0rq16
ivle.database: Exercise.get_by_name, now auto-inserts and returns a new
    Exercise if it was not found in the DB.
    This may be a bad idea, but it's consistent with the existing behaviour of
    ivle.db.get_problem_problemid, so a lot of things depend on it (nothing
    explicitly creates an Exercise).

Show diffs side-by-side

added added

removed removed

Lines of Context:
352
352
    def get_by_name(cls, store, name):
353
353
        """
354
354
        Get the Exercise from the db associated with a given store and name.
 
355
        If the exercise is not in the database, creates it and inserts it
 
356
        automatically.
355
357
        """
356
 
        return store.find(cls, cls.name == unicode(name)).one()
 
358
        ex = store.find(cls, cls.name == unicode(name)).one()
 
359
        if ex is not None:
 
360
            return ex
 
361
        ex = Exercise(name=unicode(name))
 
362
        store.add(ex)
 
363
        store.commit()
 
364
        return ex
357
365
 
358
366
class Worksheet(Storm):
359
367
    __storm_table__ = "worksheet"