Example #1
0
def create_app(options):
    app = Flask(__name__)

    app.secret_key = "ed788cab1d449175885623bf5fad28101898b059380a263f"

    config = ConfigParser.ConfigParser()
    config.readfp(open(options.config))

    app.mopts = misc.MagicOptions(
        config_defaults, dict(config.items(options.section)), vars(options), dict(section=options.section)
    )
    app.users = dict(config.items("users_" + options.section))
    engine = create_engine(app.mopts.uri)
    adjust_schemas(staging=app.mopts.staging_schema, model=app.mopts.model_schema)
    Session = sessionmaker(bind=engine)  # autocommit=True)

    auth.init_login_manager(app)
    jinja_local.jinja_filters.init_app(app)
    misc.menu.init_app(app)

    app.register_blueprint(auth.auth)
    #    app.register_blueprint(errors.errors)
    app.register_blueprint(home.homebp, url_prefix="/home")
    app.register_blueprint(crn.crnbp, url_prefix="/crn")

    #    @app.route('/')
    #    def root():
    #        return redirect(url_for('binterface.ctl_jobs', filter='php_only'))

    @app.after_request
    def session_commit(response):
        session = getattr(g, "session", None)
        if session is not None:
            g.session.commit()
        return response

    @app.before_request
    def before_request():
        g.session = Session()

    @app.teardown_request
    def teardown_request(exception):
        session = getattr(g, "session", None)
        if session is not None:
            session.close()

    return app
Example #2
0
import random
import itertools
import string
from flask import Flask, jsonify, redirect, render_template, request, session, url_for

app = Flask(__name__)
# This key is a random string that is used for session cookie management
app.secret_key = "8edca468f5f7bb849e5d8bedb" + str(random.randint(0, 100000))
# Store all games in this map (global variable)
# maps game_id (str) -> Game
app.games = {}
# Store all users in this map
# maps user_id (str) -> User
app.users = {}

ASSETS = {
    "bootstrap_css": "css/bootstrap.min.css",
    "bootstrap_js": "js/bootstrap.min.js",
    "d3_js": "js/d3.v3.min.js",
    "favicon_ico": "favicon.ico",
    "front_page_js": "js/front_page.js",
    "game_css": "css/game.css",
    "game_page_js": "js/game_page.js",
    "jquery_js": "js/jquery-2.0.3.min.js",
    "lib_js": "js/lib.js",
}


def get_id():
    """Returns a random 10 character string, which can be used to identify objects."""
    characters = string.ascii_uppercase + string.ascii_lowercase + string.digits