Example #1
0
def base_app():
    global app
    app = Flask('backend')
    app.config.overrides = {}

    logging.info('Connecting to database...')
    engine = create_engine(backend.settings.db_connection)
    app.engine = engine
    base = automap_base()
    base.prepare(engine, reflect=True)

    session = Session(engine)
    app.base = base
    app.session = session
    app.Decl_Base = declarative_base()
    
    from backend.models import Members
    app.Decl_Base.metadata.create_all(app.engine)

    # Create the Flask-Restless API manager.
    app.api_manager = flask.ext.restless.APIManager(app, session=app.session)
    app.api_manager.create_api(Members, methods=['GET', 'POST', 'PATCH', 'DELETE'], collection_name='members')

    return app

    @app.route("/shutdown", methods=["POST"])   # pragma: no cover
    def shutdown():  # pragma: no cover
        logging.info('shutting down server')
        shutdown_server()
        return "server shutting down"
Example #2
0
from flask import Flask, render_template, redirect
import re

app = Flask(__name__)
app.session = None


def commify(number):
    number = str(number)
    processing = 1
    regex = re.compile(r"^(-?\d+)(\d{3})")
    while processing:
        (number, processing) = regex.subn(r"\1,\2", number)
    return number


@app.route("/togglepause")
def pause():
    # Flip our state
    app.session.is_paused = not app.session.is_paused
    return redirect('/')


@app.route('/view_crash/<int:crash_id>')
def view_crash(crash_id):
    return render_template("view_crash.html", crashinfo=app.session.procmon_results[crash_id])


@app.route("/")
def index():
    crashes = []
Example #3
0
File: cc.py Project: nephlm/verodin
OK = 'okay'

app = Flask(__name__, static_url_path='')
app.debug = True
app.config.from_object('config')
app.ccConfig = {}
app.ccState = {}
app.state = {'ip': ccLib.getMyIPAddress()}

app.aws = ccLib.AWS()
app.aws.createKeypairs()
app.aws.pushSecurityGroups('worker')

app.queue = ccLib.Job

app.session = ccLib.initDB()

@app.route('/')
def index():
    """ Return the main html page. """
    # return 'hello'
    return app.send_static_file('index.html')


#===================================
# Workers/Nodes/AWS

@app.route('/api/regions')
def regions():
    """
    Get the list of regions
    using_gevent = True
else:
    using_gevent = False


app = Flask(__name__)

app.config.from_object('ooi_status.default_settings')
if 'OOISTATUS_SETTINGS' in os.environ:
    app.config.from_envvar('OOISTATUS_SETTINGS')
app.json_encoder = StatusJsonEncoder


app.engine = create_engine(app.config['MONITOR_URL'])
app.metadata_engine = create_engine(app.config['METADATA_URL'])

app.sessionmaker = sessionmaker(bind=app.engine)
app.session = scoped_session(app.sessionmaker)
app.metadata_sessionmaker = sessionmaker(bind=app.metadata_engine)
app.metadata_session = scoped_session(app.metadata_sessionmaker)

MetadataBase.query = app.session.query_property()
MonitorBase.query = app.session.query_property()

if using_gevent:
    app.engine.pool._use_threadlocal = True


import ooi_status.api.views
from sqlalchemy.orm import sessionmaker

from models import Base, User, Restaurant, MenuItem

app = Flask(__name__)

import modules.views
import modules.api
import modules.signin

engine = create_engine('sqlite:///app.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()

app.session = session

###############################################
# HELPER FUNCTIONS
##############################################
def createUser(login_session):
    newUser = User(name=login_session['username'],
                   email=login_session['email'],
                   picture=login_session['picture'])
    session.add(newUser)
    session.commit()
    return session.query(User)\
        .filter_by(email=login_session['email'])\
        .first()
app.createUser = createUser