def load_user(userid): """The call back the login manager uses to actually load the user object. This essentially must take the unicode userid and return a User object which represents that user. """ g.db = datastore.connect_db() cur = g.db.execute("select name from users where ident=?", [userid]) users = cur.fetchall() if not users: return flasklogin.AnonymousUser() user_tuple = users[0] user = User(userid) user.name = user_tuple[0] return user
def run(): """ The simple main method""" # script_name = sys.argv[0] command_name = sys.argv[1] timeout = int(sys.argv[2]) arguments = sys.argv[3:] # This kind of assumes that all of these commands will execute # something on the database, which is probably true, for those that # don't we can probably have a completely separate module for this. database = datastore.connect_db() # This could be done like this but I prefer explicitly writing it out. # globals()[command_name](timeout, database, arguments) if command_name == "convert_to_sbml": convert_to_sbml(timeout, database, arguments) elif command_name == "convert_to_latex": convert_to_latex(timeout, database, arguments) else: print ("Command unknown: " + command_name) database.close()
def before_request(): """Occurs before every request, we make a connection to the database""" g.db = datastore.connect_db()