def save_to_db(item, msg='Saved to db', print_error=True):
 try:
  logging.info(msg)
  db.session.add(item)
  logging.info('added to session')
  db.session.commit()
  return True
 except Exception as e:
  if print_error:
   print e
   traceback.print_exc()
  logging.error(('DB Exception! %s' % e))
  db.session.rollback()
  return False

def save_to_db ( item , msg = 'Saved to db' , print_error = True ) : try : logging . info ( msg ) db . session . add ( item ) logging . info ( 'added to session' ) db . session . commit ( ) return True except Exception as e : if print_error : print e traceback . print_exc ( ) logging . error ( ( 'DB Exception! %s' % e ) ) db . session . rollback ( ) return False
convenience function to wrap a proper db save .