Example #1
0
def create_app():
    from fastapi import FastAPI
    from routes import register_routes

    app = FastAPI()

    register_routes(app)

    return app
Example #2
0
    def __init__(self, app_name=__name__):
        load_dotenv()
        self.app = Flask(app_name, instance_relative_config=True)
        self.app.url_map.strict_slashes = False
        CORS(self.app)

        register_routes(self.app)
        register_logging(self.app)
        self._configure_error_handlers()
Example #3
0
def create_app(app_config):
    app = Flask(__name__)
    app.config.from_object(app_config)

    __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
    with open(os.path.join(__location__, 'secrets.json')) as secrets_file:
        secrets = json.load(secrets_file)
        app.secret_key = secrets.get('app_secret')
        app_config.SECRET_KEY = app.secret_key

    login_manager.login_view = 'login.show'

    admin.add_view(AdminModelView(Challenge, db.session))
    admin.add_view(AdminModelView(Game, db.session))
    admin.add_view(AdminModelView(MarathonInfo, db.session))
    admin.add_view(AdminModelView(Prize, db.session))
    admin.add_view(AdminModelView(Interview, db.session))
    admin.add_view(AdminModelView(ScheduleEntry, db.session))

    with open(os.path.join(__location__, 'secrets.json')) as secrets_file:
        secrets = json.load(secrets_file)
        app.config.update(
            MAIL_SERVER='smtp.gmail.com',
            MAIL_PORT=465,
            MAIL_USERNAME='******',
            MAIL_DEFAULT_SENDER='*****@*****.**',
            MAIL_PASSWORD=secrets.get("email_password"),
            MAIL_USE_SSL=True,
            MAIL_USE_TLS=False
        )

    login_manager.init_app(app)
    admin.init_app(app)
    mail.init_app(app)
    register_routes(app)

    @app.errorhandler(404)
    def page_not_found(e):
        return render_template('404.tmpl'), 404

    @login_manager.user_loader
    def load_user(id):
        return db.session.query(User).filter_by(id=id).first()

    @app.context_processor
    def inject_marathon_info():
        marathon_info = getattr(g, "marathon_info", None)
        if not marathon_info:
            marathon_info = g.marathon_info = db.session.query(MarathonInfo).first()
        current_game = db.session.query(Game).filter_by(id=marathon_info.current_game_id).first()
        return dict(marathon_info=marathon_info, current_game=current_game)

    return app
Example #4
0
def create_app():
    cors = CORS(allow_origins_list=settings.ALLOWED_HOSTS)

    middlewares = [
        cors.middleware,
        Marshmallow(),
    ]

    app = falcon.API(middleware=middlewares)
    app.req_options.auto_parse_form_urlencoded = True
    app.add_error_handler(AppError, AppError.handle)
    register_routes(api_routes, app, prefix='api/v1.0')

    return app
Example #5
0
def create_app():
    print("STARTING SIMPLE APPLICATION...")

    app = Flask(__name__, instance_relative_config=True)
    CORS(app, expose_headers=['Content-Type', 'Authorization'])

    _init_config(app)

    # Exception handling
    exception_handling.register_exception_handlers(app)

    # Routes
    routes.register_routes(app)

    return app
Example #6
0
def create_app(env=None):
    from config import config_by_name
    from routes import register_routes
    app = Flask(__name__)
    CORS(app)

    app.config.from_object(config_by_name[env or "test"])
    api = Api(app, title="Radu Nie API", version="1.0")

    register_routes(api, app)
    db.init_app(app)

    @app.route("/health")
    def health():
        return jsonify("healthy")

    return app
Example #7
0
def create_app(env=None):
    from config import config_by_name
    from routes import register_routes

    app = Flask(__name__)
    app.config.from_object(config_by_name[env or "test"])
    api = Api(app, title="User API", version="0.1.0")
    cors = CORS(app, resources={r"/api/*": {"origins": "*"}})

    register_routes(api, app)

    @app.route("/health")
    def health():
        """For the microservice health check"""
        return jsonify("healthy")

    return app
Example #8
0
def create_app():
    print("STARTING APPLICATION ...")

    app = Flask(__name__, instance_relative_config=True)
    app.json_encoder = CustomJSONEncoder
    app.config['JSON_SORT_KEYS'] = False

    _init_config(app)
    _init_logging(app)

    CORS(app,
         expose_headers=['Content-Type', 'Authorization', 'Range'],
         allow_headers=['Content-Type', 'Authorization', 'Range'])

    # Exception handling
    exception_handling.register_exception_handlers(app)

    # Routes
    routes.register_routes(app)

    return app
Example #9
0
def init_routes():
    """Register RESTFul API routes"""
    register_routes()
    register_user_routes()
    register_admin_routes()

    # health page API
    api.add_resource(HealthResource, "/", "/health")

    # system time API
    api.add_resource(CurrentTimeResource, "/api/currenttime")

    # API for admin to query, create or update hackathon
    api.add_resource(AdminHackathonResource, "/api/admin/hackathon")

    # check whether hackathon with specific name exists
    api.add_resource(HackathonCheckNameResource, "/api/admin/hackathon/checkname")

    # get hackathon list that the current user are entitled to manage
    api.add_resource(AdminHackathonListResource, "/api/admin/hackathon/list")

    # manage azure certificates for hackathon
    api.add_resource(AdminAzureResource, '/api/admin/azure')
Example #10
0
    def _create_app(self):
        app = Flask(__name__)

        self._load_config(app)
        self._register_path(app)

        # use template pug(jade)
        app.jinja_env.add_extension('pyjade.ext.jinja.PyJadeExtension')

        # use webpack
        webpack = Webpack()
        webpack.init_app(app)

        # routing
        register_routes(app)

        # init db
        init_db(app)

        toolbar = DebugToolbarExtension()
        toolbar.init_app(app)

        return app
Example #11
0
def init_routes():
    """Register RESTFul API routes"""
    register_routes()
    register_user_routes()
    register_admin_routes()

    # health page API
    api.add_resource(HealthResource, "/", "/health")

    # system time API
    api.add_resource(CurrentTimeResource, "/api/currenttime")

    # API for admin to query, create or update hackathon
    api.add_resource(AdminHackathonResource, "/api/admin/hackathon")

    # check whether hackathon with specific name exists
    api.add_resource(HackathonCheckNameResource,
                     "/api/admin/hackathon/checkname")

    # get hackathon list that the current user are entitled to manage
    api.add_resource(AdminHackathonListResource, "/api/admin/hackathon/list")

    # manage azure certificates for hackathon
    api.add_resource(AdminAzureResource, '/api/admin/azure')
Example #12
0
load_dotenv()

# Server config
app = dash.Dash(__name__)
server = app.server
app.config.suppress_callback_exceptions = True

# Main layout
app.title = 'Example Dashboards'
app.layout = html.Div([
    dcc.Location(id='url', refresh=False),
    html.Div(id='page-content', className='container')
])

# Routing
register_routes(app)

# Callbacks
register_callbacks(app)

# External styles
with open('src/styles/external/urls.json') as external_urls:
    urls = json.load(external_urls)
for external_url in urls['external_urls']:
    app.css.append_css({'external_url': external_url})

# Launch with python
if __name__ == '__main__':
    debug = os.environ.get('DEBUG') if (os.environ.get('DEBUG')
                                        is not None) else False
    app.run_server(debug=debug,
Example #13
0
from flask import Flask

import routes

# import config if present
try:
    import config
except:
    pass

app = Flask(__name__, static_folder='public/', template_folder='templates')

app.config.update(dict(DEBUG=False, ))

routes.register_routes(app)
Example #14
0
def create_app(app_config):
    app = Flask(__name__)
    app.config.from_object(app_config)

    # create a fake MarathonInfo if one doesn't exist
    # just enough to bootstrap
    info = db.session.query(MarathonInfo).first()
    if not info:
        now = datetime.datetime.now()
        half_an_hour_earlier = now - datetime.timedelta(minutes=30)
        half_an_hour_later = now + datetime.timedelta(minutes=30)

        test_game = Game.create(name='Test Game', developer='Test Dev')

        test_play = ScheduleEntry.create(
            title='Play The Test Game',
            game_id=test_game.id,
            start=half_an_hour_earlier,
            end=half_an_hour_later
        )

        MarathonInfo.create(
            start=(now - datetime.timedelta(hours=10)),
            hours=31,
            total=12345.67,
            current_game_id=test_game.id,
            next_game_id=test_game.id,
            current_schedule_entry=test_play.id
        )

    __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
    try: # dev
        with open(os.path.join(__location__, 'secrets.json')) as secrets_file:
            secrets = json.load(secrets_file)
            app.secret_key = secrets.get('app_secret')
            app_config.SECRET_KEY = app.secret_key

            app.config.update(
                MAIL_SERVER='smtp.gmail.com',
                MAIL_PORT=465,
                MAIL_USERNAME='******',
                MAIL_DEFAULT_SENDER='*****@*****.**',
                MAIL_PASSWORD=secrets.get("email_password"),
                MAIL_USE_SSL=True,
                MAIL_USE_TLS=False
            )
    except IOError: # prod
        app.secret_key = os.environ.get('IGG_APP_SECRET')
        app_config.SECRET_KEY = app.secret_key

        app.config.update(
            MAIL_SERVER='smtp.gmail.com',
            MAIL_PORT=465,
            MAIL_USERNAME='******',
            MAIL_DEFAULT_SENDER='*****@*****.**',
            MAIL_PASSWORD=os.environ.get("IGG_EMAIL_PASSWORD"),
            MAIL_USE_SSL=True,
            MAIL_USE_TLS=False
        )

    login_manager.login_view = 'login.show'

    admin.add_view(AdminModelView(Challenge, db.session, endpoint='challengeadmin'))
    admin.add_view(AdminModelView(Game, db.session))
    admin.add_view(AdminModelView(MarathonInfo, db.session))
    admin.add_view(AdminModelView(Prize, db.session))
    admin.add_view(AdminModelView(Interview, db.session))
    admin.add_view(AdminModelView(ScheduleEntry, db.session))
    admin.add_view(AdminModelView(User, db.session))
    admin.add_view(AdminModelView(Crew, db.session))
    
    admin.add_view(ImageView(Image, db.session))

    login_manager.init_app(app)
    admin.init_app(app)
    mail.init_app(app)
    register_routes(app)

    @app.errorhandler(404)
    def page_not_found(e):
        return render_template('404.tmpl'), 404

    @login_manager.user_loader
    def load_user(id):
        return db.session.query(User).filter_by(id=id).first()

    @app.context_processor
    def inject_marathon_info():
        marathon_info = getattr(g, "marathon_info", None)
        if not marathon_info:
            marathon_info = g.marathon_info = db.session.query(MarathonInfo).first()
        current_game = db.session.query(Game).filter_by(id=marathon_info.current_game_id).first()
        return dict(marathon_info=marathon_info, current_game=current_game)

    return app
Example #15
0
File: main.py Project: mvader/dyces
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import webapp2
from routes import register_routes

app = webapp2.WSGIApplication(debug=True)
register_routes(app)
Example #16
0
def create_app(db_url='sqlite:///flaskart.sqlite'):
    app = Flask(__name__, static_url_path='')
    db.connect(db_url)
    register_routes(app)

    return app
Example #17
0
def create_app(app_config):
    app = Flask(__name__)
    app.config.from_object(app_config)

    # create a fake MarathonInfo if one doesn't exist
    # just enough to bootstrap
    info = db.session.query(MarathonInfo).first()
    if not info:
        now = datetime.datetime.now()
        half_an_hour_earlier = now - datetime.timedelta(minutes=30)
        half_an_hour_later = now + datetime.timedelta(minutes=30)

        test_game = Game.create(name='Test Game', developer='Test Dev')

        test_play = ScheduleEntry.create(title='Play The Test Game',
                                         game_id=test_game.id,
                                         start=half_an_hour_earlier,
                                         end=half_an_hour_later)

        MarathonInfo.create(start=(now - datetime.timedelta(hours=10)),
                            hours=31,
                            total=12345.67,
                            current_game_id=test_game.id,
                            next_game_id=test_game.id,
                            current_schedule_entry=test_play.id)

    __location__ = os.path.realpath(
        os.path.join(os.getcwd(), os.path.dirname(__file__)))
    try:  # dev
        with open(os.path.join(__location__, 'secrets.json')) as secrets_file:
            secrets = json.load(secrets_file)
            app.secret_key = secrets.get('app_secret')
            app_config.SECRET_KEY = app.secret_key

            app.config.update(MAIL_SERVER='smtp.gmail.com',
                              MAIL_PORT=465,
                              MAIL_USERNAME='******',
                              MAIL_DEFAULT_SENDER='*****@*****.**',
                              MAIL_PASSWORD=secrets.get("email_password"),
                              MAIL_USE_SSL=True,
                              MAIL_USE_TLS=False)
    except IOError:  # prod
        app.secret_key = os.environ.get('IGG_APP_SECRET')
        app_config.SECRET_KEY = app.secret_key

        app.config.update(MAIL_SERVER='smtp.gmail.com',
                          MAIL_PORT=465,
                          MAIL_USERNAME='******',
                          MAIL_DEFAULT_SENDER='*****@*****.**',
                          MAIL_PASSWORD=os.environ.get("IGG_EMAIL_PASSWORD"),
                          MAIL_USE_SSL=True,
                          MAIL_USE_TLS=False)

    login_manager.login_view = 'login.show'

    admin.add_view(
        AdminModelView(Challenge, db.session, endpoint='challengeadmin'))
    admin.add_view(AdminModelView(Game, db.session))
    admin.add_view(AdminModelView(MarathonInfo, db.session))
    admin.add_view(AdminModelView(Prize, db.session))
    admin.add_view(AdminModelView(Interview, db.session))
    admin.add_view(AdminModelView(ScheduleEntry, db.session))
    admin.add_view(AdminModelView(User, db.session))
    admin.add_view(AdminModelView(Crew, db.session))

    admin.add_view(ImageView(Image, db.session))

    login_manager.init_app(app)
    admin.init_app(app)
    mail.init_app(app)
    register_routes(app)

    @app.errorhandler(404)
    def page_not_found(e):
        return render_template('404.tmpl'), 404

    @login_manager.user_loader
    def load_user(id):
        return db.session.query(User).filter_by(id=id).first()

    @app.context_processor
    def inject_marathon_info():
        marathon_info = getattr(g, "marathon_info", None)
        if not marathon_info:
            marathon_info = g.marathon_info = db.session.query(
                MarathonInfo).first()
        current_game = db.session.query(Game).filter_by(
            id=marathon_info.current_game_id).first()
        return dict(marathon_info=marathon_info, current_game=current_game)

    return app