def set_database(function):
 def wrapper(*args, **kwargs):
  language = kwargs.get('language', 'en')
  path = kwargs.pop('database_path', None)
  if (not path):
   path = CONTENT_DATABASE_PATH.format(channel=kwargs.get('channel', CHANNEL), language=language)
  db = SqliteDatabase(path, pragmas=settings.CONTENT_DB_SQLITE_PRAGMAS)
  kwargs['db'] = db
  db.connect()
  with Using(db, [Item, AssessmentItem]):
   try:
    output = function(*args, **kwargs)
   except DoesNotExist:
    output = None
   except OperationalError:
    logging.error('No content database file found')
    raise
  db.close()
  return output
 return wrapper

def set_database ( function ) : def wrapper ( * args , ** kwargs ) : language = kwargs . get ( 'language' , 'en' ) path = kwargs . pop ( 'database_path' , None ) if ( not path ) : path = CONTENT_DATABASE_PATH . format ( channel = kwargs . get ( 'channel' , CHANNEL ) , language = language ) db = SqliteDatabase ( path , pragmas = settings . CONTENT_DB_SQLITE_PRAGMAS ) kwargs [ 'db' ] = db db . connect ( ) with Using ( db , [ Item , AssessmentItem ] ) : try : output = function ( * args , ** kwargs ) except DoesNotExist : output = None except OperationalError : logging . error ( 'No content database file found' ) raise db . close ( ) return output return wrapper
sets the appropriate database for the ensuing model interactions .