def create_app(config_filename=None): app = Flask(__name__) app.request_class = Request app.url_map.converters['re'] = RegexConverter if config_filename is None: HerokuConfig(app) else: AppConfig(app, config_filename) from_envvars(app.config, prefix='') app.debug = app.config.get('DEBUG') # TODO: these variables probably aren't unjsonnable anymore # push all variables into the environment unjsonnable = (datetime, timedelta) data = {k: json.dumps(v) for k, v in app.config.items() if not isinstance(v, unjsonnable)} os.environ.update(data) # app.logger.info('App is running on port %s', os.environ.get('PORT')) if app.config['DEBUG'] is not True: log_level = app.config.get('LOG_LEVEL', 'DEBUG') app.logger.setLevel(getattr(logging, log_level.upper())) import bauble.db as db if 'LOG_SQL' in os.environ: logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) db.init_app(app) # register flask extensionsa SSLify(app, permanent=True) app.login_manager = LoginManager(app) app.login_manager.login_view = "auth.login" app.mail = Mail(app) app.babel = Babel(app) from .assets import init_app init_app(app) # TODO: just import everything controllers for controller in ['auth', 'index', 'batch']: module = import_module('bauble.controllers.{}'.format(controller)) app.register_blueprint(module.blueprint) from bauble.resource import Resource controllers = ['search', 'family', 'genus', 'taxon', 'accession', 'plant', 'location', 'vernacular_name'] for controller in controllers: module = import_module('bauble.controllers.{}'.format(controller)) for attr_name in dir(module): attr = getattr(module, attr_name) # find all the blueprints in the files if isinstance(attr, Blueprint): app.register_blueprint(attr) # if isclass(attr) and issubclass(attr, Blueprint) and attr != Resource: # app.register_blueprint(attr()) from bauble.error import init_errorhandlers init_errorhandlers(app) app.json_encoder = JSONEncoder return app
# -*- conding: utf-8 -*- """ application app food by [email protected] """ from flask import Flask, redirect, session from flask_appconfig.env import from_envvars app = Flask('coreadmin') from_envvars(app.config, prefix='FLASK_') from applications.register.views import app as register_views app.register_blueprint(register_views)
import os from werkzeug import exceptions from scoreboard import logger from flask_appconfig.env import from_envvars app = flask.Flask( 'scoreboard', static_folder='../static', template_folder='../templates', ) app.config.from_object('scoreboard.config_defaults.Defaults') app.config.from_object('config') # Load from config.py from_envvars(app.config, prefix=app.name.upper() + '_') def on_appengine(): """Returns true if we're running on AppEngine.""" runtime = os.environ.get('SERVER_SOFTWARE', '') return (runtime.startswith('Development/') or runtime.startswith('Google App Engine/')) log_formatter = logger.Formatter( '%(asctime)s %(levelname)8s [%(filename)s:%(lineno)d] %(client)s %(message)s') # log to files unless on AppEngine if not on_appengine(): # Main logger if not app.debug and not app.config.get("LOG_TO_STDOUT", False): handler = logging.FileHandler( app.config.get('LOGFILE', '/tmp/scoreboard.wsgi.log'))
from flask_appconfig.env import from_envvars #from flask.ext.heroku import Heroku app = Flask(__name__) #heroku = Heroku(app) if os.environ.get('HEROKU') is not None: import logging stream_handler = logging.StreamHandler() app.logger.addHandler(stream_handler) app.logger.setLevel(logging.INFO) app.logger.info('flask-and-social startup') # this will read in variables from config.py from_envvars(app.config, prefix='MY_') # ==================================================================================== # setup and teardown for each HTTP request # ==================================================================================== # the @ sign here means that app.before_request is a "decorator" for the function # defined in the next line. http://legacy.python.org/dev/peps/pep-0318/#current-syntax # but you don't have to understand that to use it # # in a flask app, putting @app.before_request before a function means # that this function will be called before a request is routed, and app.teardown_request # is called after everything is finished. # So this is a good place to connect/disconnect to the database @app.before_request def before_request():
from flask_sslify import SSLify from sqlalchemy.dialects import postgresql from . import tansit app = Flask(__name__) app.config['PORT'] = 5000 app.config['SQLALCHEMY_DATABASE_URI'] = \ "postgresql+pg8000://brak-web@/brak_dev" app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['TANSIT_ENDPOINT'] = "ipc:///tmp/tansit.zmq" app.config['PREFERRED_URL_SCHEME'] = 'http' app.config['HTTPS'] = True app.secret_key = os.urandom(128) # maybe do this better sometime from_envvars(app.config, prefix="BRAK_") if app.config.get('HTTPS'): SSLify(app, skips=['_health_check']) if app.config.get('SECRET_KEY_BASE64'): app.secret_key = base64.b64decode(app.config['SECRET_KEY_BASE64']) db = SQLAlchemy(app) db_metadata = db.MetaData() newest_packages = db.Table( 'newest_packages', db_metadata, db.Column('id', db.Integer), db.Column('name', db.String),
def create_app(config_filename=None): app = Flask(__name__) app.request_class = Request app.url_map.converters['re'] = RegexConverter if config_filename is None: HerokuConfig(app) else: AppConfig(app, config_filename) from_envvars(app.config, prefix='') app.debug = app.config.get('DEBUG') # TODO: these variables probably aren't unjsonnable anymore # push all variables into the environment unjsonnable = (datetime, timedelta) data = { k: json.dumps(v) for k, v in app.config.items() if not isinstance(v, unjsonnable) } os.environ.update(data) # app.logger.info('App is running on port %s', os.environ.get('PORT')) if app.config['DEBUG'] is not True: log_level = app.config.get('LOG_LEVEL', 'DEBUG') app.logger.setLevel(getattr(logging, log_level.upper())) import bauble.db as db if 'LOG_SQL' in os.environ: logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) db.init_app(app) # register flask extensionsa SSLify(app, permanent=True) app.login_manager = LoginManager(app) app.login_manager.login_view = "auth.login" app.mail = Mail(app) app.babel = Babel(app) from .assets import init_app init_app(app) # TODO: just import everything controllers for controller in ['auth', 'index', 'batch']: module = import_module('bauble.controllers.{}'.format(controller)) app.register_blueprint(module.blueprint) from bauble.resource import Resource controllers = [ 'search', 'family', 'genus', 'taxon', 'accession', 'plant', 'location', 'vernacular_name' ] for controller in controllers: module = import_module('bauble.controllers.{}'.format(controller)) for attr_name in dir(module): attr = getattr(module, attr_name) # find all the blueprints in the files if isinstance(attr, Blueprint): app.register_blueprint(attr) # if isclass(attr) and issubclass(attr, Blueprint) and attr != Resource: # app.register_blueprint(attr()) from bauble.error import init_errorhandlers init_errorhandlers(app) app.json_encoder = JSONEncoder return app