def configure(app): # config sqlalchemy global db app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI db = SQLAlchemy(app) # importing and registering blueprints from dashboard.views import blueprint as dashboard_blueprint app.register_blueprint(dashboard_blueprint, url_prefix='/api') # config bower app.config['BOWER_COMPONENTS_ROOT'] = 'bower_components' Bower(app)
import local_conf user_datastore = SQLAlchemyUserDatastore(db, User, Role) lm = LoginManager() security = Security() def create_app(config_object): app = Flask(__name__) app.config.from_object(config_object) app.debug = local_conf.debug db.init_app(app) api.init_app(app) lm.init_app(app) security.init_app(app, user_datastore) app.register_blueprint(tutorial_bp) if app.debug: import logging from logging import FileHandler handler = FileHandler(local_conf.logfile) handler.setLevel(logging.WARNING) app.logger.addHandler(handler) return app app = create_app('local_conf') Bower(app) # lm.login_view = 'login'
def create_app(self): result = tutorial.create_app(self) Bower(result) return result
from loader import * from flask import Flask, render_template, request, jsonify, url_for from flask.ext.bower import Bower from bokeh.protocol import serialize_json import os app = Flask(__name__) app.config['SECRET_KEY'] = 'secret!' bower = Bower(app) workspace = {} @app.route('/') def hello_world(): return render_template('index.html') @app.route('/blaze', methods=['POST']) def blaze_to_data(): global workspace workspace = parse_blaze_manifest_with_loader(request.data.decode('utf-8')) return jsonify(keys=list(workspace.keys()), ) @app.route('/bokeh', methods=['POST']) def bokeh_to_data(): bk_plot = parse_bokeh_manifest_with_loader(request.data.decode('utf-8'))
"""Create the Tower_Metadata application.""" from flask import Flask, render_template from flask.ext.bootstrap import Bootstrap from flask.ext.moment import Moment # from flask.ext.mailgun import Mailgun from flask.ext.wtf import CsrfProtect from flask.ext.bower import Bower from config import config from pymongo import ReadPreference from app.models import db, login_manager # Initialize the flask extensions for this app: # slack = Slacker(os.environ.get('SLACK_TOKEN')) bootstrap = Bootstrap() bower = Bower() moment = Moment() csrf = CsrfProtect() # mail = Mailgun() login_manager.session_protection = 'strong' login_manager.login_view = 'auth.login' login_manager.login_message = \ 'Give your data a pulse by logging in or signing up!' login_manager.login_message_category = "info" def create_app(config_name): """Create the tower_metadata application for deployment.""" # Do the stuff necessary to set up the Flask application app = Flask(__name__) # Let's use the default config for now (set to Development):
adjacency_data_json, flare_tree_as_json_for_asn, live_search, sunburst_ready_json, tree_data_json, tree_ready_json, ) from flask import Flask, render_template, request, url_for, redirect from flask.ext.bower import Bower #from flask_sslify import SSLify from model import connect_to_db app = Flask(__name__) Bower(app) # This provides the /bower url route #sslify = SSLify(app, age=300) # This attaches SSLify to the app #sslify = SSLify(app, permanent=True) @app.route('/') def index(): return render_template("base.html") @app.route('/about') def about(): return render_template("about.html") @app.route('/data/tree/<asn>')
def init(conf=None, debug=0, logfile=None, gunicorn=True, unittest=False): """Initialize the whole application. :param conf: Configuration file to use :type conf: str :param debug: Enable verbose output :type debug: int :param logfile: Store the logs in the given file :type logfile: str :param gunicorn: Enable gunicorn engine instead of flask's default :type gunicorn: bool :returns: A :class:`burpui.server.BUIServer` object """ from flask.ext.login import LoginManager from flask.ext.bower import Bower from .utils import basic_login_from_request from .server import BUIServer as BurpUI from .routes import view from .api import api, apibp if not unittest: from ._compat import patch_json patch_json() if gunicorn: from gevent import monkey monkey.patch_all() # We initialize the core app = BurpUI() app.gunicorn = gunicorn app.config['CFG'] = None app.secret_key = ('VpgOXNXAgcO81xFPyWj07ppN6kExNZeCDRShseNzFKV7ZCgmW2/eLn6x' 'Slt7pYAVBj12zx2Vv9Kw3Q3jd1266A==') app.jinja_env.globals.update( isinstance=isinstance, list=list, version_id='{}-{}'.format(__version__, __release__) ) # The debug argument used to be a boolean so we keep supporting this format if isinstance(debug, bool): if debug: debug = logging.DEBUG else: debug = logging.NOTSET else: levels = [ logging.NOTSET, logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG ] if debug >= len(levels): debug = len(levels) - 1 if not debug: debug = 0 debug = levels[debug] if debug != logging.NOTSET and not gunicorn: # pragma: no cover app.config['DEBUG'] = True and not unittest app.config['TESTING'] = True and not unittest if logfile: from logging import Formatter from logging.handlers import RotatingFileHandler file_handler = RotatingFileHandler( logfile, maxBytes=1024 * 1024 * 100, backupCount=20 ) if debug < logging.INFO: LOG_FORMAT = ( '-' * 80 + '\n' + '%(levelname)s in %(module)s.%(funcName)s ' + '[%(pathname)s:%(lineno)d]:\n' + '%(message)s\n' + '-' * 80 ) else: LOG_FORMAT = ('[%(asctime)s] %(levelname)s in ' '%(module)s.%(funcName)s: %(message)s') file_handler.setLevel(debug) file_handler.setFormatter(Formatter(LOG_FORMAT)) app.logger.addHandler(file_handler) # Still need to test conf file here because the init function can be called # by gunicorn directly app.config['CFG'] = lookup_config(conf) app.setup(app.config['CFG']) if gunicorn: # pragma: no cover from werkzeug.contrib.fixers import ProxyFix if app.storage and app.storage.lower() == 'redis': if app.redis: part = app.redis.split(':') host = part[0] try: port = int(part[1]) except: port = 6379 else: host = 'localhost' port = 6379 try: from redis import Redis from flask.ext.session import Session red = Redis(host=host, port=port) app.config['SESSION_TYPE'] = 'redis' app.config['SESSION_REDIS'] = red ses = Session() ses.init_app(app) except: pass api.cache.init_app( app, config={ 'CACHE_TYPE': 'redis', 'CACHE_REDIS_HOST': host, 'CACHE_REDIS_PORT': port, 'CACHE_REDIS_DB': 1 } ) # clear cache at startup in case we removed or added servers with app.app_context(): api.cache.clear() else: api.cache.init_app(app) app.wsgi_app = ProxyFix(app.wsgi_app) else: api.cache.init_app(app) # Then we load our routes view.init_bui(app) view.__url__ = __url__ view.__doc__ = __doc__ app.register_blueprint(view) # We initialize the API api.init_bui(app) api.version = __version__ api.release = __release__ api.__url__ = __url__ api.__doc__ = __doc__ app.register_blueprint(apibp) # And the login_manager app.login_manager = LoginManager() app.login_manager.login_view = 'view.login' app.login_manager.login_message_category = 'info' app.login_manager.session_protection = 'strong' app.login_manager.init_app(app) app.config.setdefault( 'BOWER_COMPONENTS_ROOT', os.path.join('static', 'vendor') ) app.config.setdefault('BOWER_REPLACE_URL_FOR', True) bower = Bower() bower.init_app(app) @app.login_manager.user_loader def load_user(userid): """User loader callback""" if app.auth != 'none': return app.uhandler.user(userid) return None # pragma: no cover @app.login_manager.request_loader def load_user_from_request(request): """User loader from request callback""" if app.auth != 'none': return basic_login_from_request(request, app) return app