def get_app(config): app = Flask(__name__) app.config.from_object(config) mail.init_app(app) RQ(app) csrf = CsrfProtect(app) csrf.exempt(api_1_0_blueprint) stream_handler = logging.StreamHandler() if app.debug: stream_handler.setLevel(logging.INFO) else: stream_handler.setLevel(logging.WARN) app.logger.addHandler(stream_handler) db.init_app(app) bootstrap = Bootstrap(app) security = Security(app, user_datastore) user_registered.connect(user_registered_sighandler) app.register_blueprint(ratings_blueprint) app.register_blueprint(api_1_0_blueprint, url_prefix='/api/v1') app.register_blueprint(verify_blueprint, url_prefix='/v') return app
def create_app(config_object=None, db_name=None): # pragma: no cover app_settings = os.getenv('APP_SETTINGS') from dotenv import load_dotenv if app_settings: load_dotenv(app_settings) else: load_dotenv('development.env') app = Flask(__name__, static_url_path=os.environ.get("STATIC_URL")) if config_object is None: app.config.from_object('config.BaseConfiguration') else: app.config.from_object(config_object) if not app.logger.handlers: stream_handler = StreamHandler() app.logger.addHandler(stream_handler) if app.debug: app.logger.setLevel("DEBUG") app.config["DEBUG_TB_INTERCEPT_REDIRECTS"] = False app.config["DEBUG_TB_PROFILER_ENABLED"] = \ os.environ.get("PROFILER", "False") == 'True' app.config['RQ_DEFAULT_URL'] = os.environ.get("REDIS_URL") else: app.logger.setLevel("INFO") RQ(app) Bootstrap(app) DebugToolbarExtension(app) from multivac.views import multivac_bp app.register_blueprint(multivac_bp) return app
def init_rqify(app): """Auto-configure an appropriate Redis service for your Flask application. :param app app: Your Flask application. """ # Look for RedisGreen. if any([k.startswith('REDISGREEN_') for k in environ]): app.config.setdefault('RQ_DEFAULT_URL', environ.get('REDISGREEN_URL')) # Look for MyRedis. elif any([k.startswith('MYREDIS_') for k in environ]): app.config.setdefault('RQ_DEFAULT_URL', environ.get('MYREDIS_URL')) # Look for Redis Cloud. elif any([k.startswith('REDISCLOUD_') for k in environ]): app.config.setdefault('RQ_DEFAULT_URL', environ.get('REDISCLOUD_URL')) # Look for Redis To Go. elif any([k.startswith('REDISTOGO_') for k in environ]): app.config.setdefault('RQ_DEFAULT_URL', environ.get('REDISTOGO_URL')) # Look for openredis. elif any([k.startswith('OPENREDIS_') for k in environ]): app.config.setdefault('RQ_DEFAULT_URL', environ.get('OPENREDIS_URL')) RQ(app)
def init_for(env): coaster.app.init_app(app, env) db.init_app(app) db.app = app # To make it work without an app context RQ(app) # Pick up RQ configuration from the app baseframe.init_app(app, requires=['lastuser-oauth'], ext_requires=['baseframe-bs3', 'fontawesome>=4.0.0', 'jquery.cookie', 'timezone']) lastuser_oauth.mailclient.mail.init_app(app) lastuser_oauth.views.login.oid.init_app(app) # Register some login providers if app.config.get('OAUTH_TWITTER_KEY') and app.config.get('OAUTH_TWITTER_SECRET'): login_registry['twitter'] = providers.TwitterProvider('twitter', 'Twitter', at_login=True, priority=True, key=app.config['OAUTH_TWITTER_KEY'], secret=app.config['OAUTH_TWITTER_SECRET'], access_key=app.config.get('OAUTH_TWITTER_ACCESS_KEY'), access_secret=app.config.get('OAUTH_TWITTER_ACCESS_SECRET')) login_registry['google'] = providers.GoogleProvider('google', 'Google', at_login=True, priority=True) if app.config.get('OAUTH_LINKEDIN_KEY') and app.config.get('OAUTH_LINKEDIN_SECRET'): login_registry['linkedin'] = providers.LinkedInProvider('linkedin', 'LinkedIn', at_login=True, priority=False, key=app.config['OAUTH_LINKEDIN_KEY'], secret=app.config['OAUTH_LINKEDIN_SECRET']) if app.config.get('OAUTH_GITHUB_KEY') and app.config.get('OAUTH_GITHUB_SECRET'): login_registry['github'] = providers.GitHubProvider('github', 'GitHub', at_login=True, priority=False, key=app.config['OAUTH_GITHUB_KEY'], secret=app.config['OAUTH_GITHUB_SECRET']) login_registry['openid'] = providers.OpenIdProvider('openid', 'OpenID', at_login=True, priority=False)
def get_app(config): app = Flask(__name__) app.config.from_object(config) mail.init_app(app) RQ(app) csrf = CsrfProtect(app) csrf.exempt(api_1_0_blueprint) stream_handler = logging.StreamHandler() app.logger.setLevel(logging.DEBUG) app.logger.addHandler(stream_handler) db.init_app(app) Migrate(app, db) bootstrap = Bootstrap(app) security = Security(app, user_datastore) user_registered.connect(user_registered_sighandler) app.register_blueprint(ratings_blueprint) app.register_blueprint(api_1_0_blueprint, url_prefix='/api/v1') app.register_blueprint(verify_blueprint, url_prefix='/v') app.register_blueprint(tournament_blueprint, url_prefix='/tournament') app.register_error_handler(500, email_exception) return app
def init_for(env): coaster.app.init_app(app, env) RQ(app) baseframe.init_app(app, requires=['hasjob'], ext_requires=[ 'baseframe-bs3', ('jquery.textarea-expander', 'jquery.cookie', 'jquery.sparkline', 'jquery.nouislider'), ('firasans', 'baseframe-firasans'), 'fontawesome>=4.0.0' ]) # TinyMCE has to be loaded by itself, unminified, or it won't be able to find its assets app.assets.register( 'js_tinymce', assets.require('!jquery.js', 'tinymce.js>=4.0.0', 'jquery.tinymce.js>=4.0.0')) app.assets.register( 'css_editor', Bundle('css/editor.css', filters=['cssrewrite', 'cssmin'], output='css/editor.packed.css')) from hasjob.uploads import configure as uploads_configure from hasjob.search import configure as search_configure uploads_configure() search_configure() mail.init_app(app) lastuser.init_app(app) lastuser.init_usermanager(UserManager(db, models.User))
def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) config[config_name].init_app(app) # Set up extensions mail.init_app(app) db.init_app(app) login_manager.init_app(app) csrf.init_app(app) compress.init_app(app) RQ(app) # Register Jinja template functions from utils import register_template_utils register_template_utils(app) app.jinja_env.globals.update(format_price=format_price) # Set up asset pipeline assets_env = Environment(app) dirs = ['assets/styles', 'assets/scripts'] for path in dirs: assets_env.append_path(os.path.join(basedir, path)) assets_env.url_expire = True assets_env.config['sass_line_comments'] = False assets_env.config['sass_debug_info'] = False assets_env.register('vendor_css', vendor_css) assets_env.register('vendor_js', vendor_js) assets_env.register('guiders_js', guiders_js) assets_env.register('images_png', images_png) assets_env.register('app_css', app_css) assets_env.register('app_js', app_js) # Configure SSL if platform supports it if not app.debug and not app.testing and not app.config['SSL_DISABLE']: from flask.ext.sslify import SSLify SSLify(app) # Create app blueprints from main import main as main_blueprint app.register_blueprint(main_blueprint) from account import account as account_blueprint app.register_blueprint(account_blueprint, url_prefix='/account') from admin import admin as admin_blueprint app.register_blueprint(admin_blueprint, url_prefix='/admin') from merchant import merchant as merchant_blueprint app.register_blueprint(merchant_blueprint, url_prefix='/merchant') from vendor import vendor as vendor_blueprint app.register_blueprint(vendor_blueprint, url_prefix='/vendor') return app
def CreateApp(configfile=None): from flask import Flask from flask.ext.appconfig import AppConfig from rq_dashboard import RQDashboard from flask_debug import Debug from flask.ext.rq import RQ result = Flask(__name__) AppConfig(result, default_settings="gir.config", configfile=configfile) result.config['RQ_DEFAULT_URL'] = result.config['REDIS_URL'] RQDashboard(result) Debug(result) RQ(result) return result
def init_for(env): coaster.app.init_app(app, env) db.init_app(app) db.app = app app.geoip = None if 'GEOIP_PATH' in app.config: geoip_database_path = os.path.join(app.config['GEOIP_PATH'], 'GeoLite2-City.mmdb') if not os.path.exists(geoip_database_path): app.logger.warn("GeoIP database missing at " + geoip_database_path) else: app.geoip = geoip2.database.Reader(geoip_database_path) RQ(app) baseframe.init_app(app, requires=['hasjob'], ext_requires=[ 'baseframe-bs3', ('jquery.autosize', 'jquery.sparkline', 'jquery.liblink', 'jquery.wnumb', 'jquery.nouislider'), 'baseframe-firasans', 'fontawesome>=4.3.0', 'bootstrap-multiselect', 'nprogress', 'ractive', 'jquery.appear', 'hammer' ], enable_csrf=True) # TinyMCE has to be loaded by itself, unminified, or it won't be able to find its assets app.assets.register( 'js_tinymce', assets.require('!jquery.js', 'tinymce.js>=4.0.0', 'jquery.tinymce.js>=4.0.0')) app.assets.register( 'css_editor', Bundle('css/editor.css', filters=['cssrewrite', 'cssmin'], output='css/editor.packed.css')) from hasjob.uploads import configure as uploads_configure uploads_configure() mail.init_app(app) redis_store.init_app(app) lastuser.init_app(app) lastuser.init_usermanager(UserManager(db, models.User))
def create_app(**config): app = Flask('iatilib.frontend') app.config.update(config) Heroku(app) if "REDISTOGO_URL" in os.environ: app.config.update({ 'RQ_DEFAULT_HOST': app.config["REDIS_HOST"], 'RQ_DEFAULT_PORT': app.config["REDIS_PORT"], 'RQ_DEFAULT_PASSWORD': app.config['REDIS_PASSWORD'] }) db.app = app # don't understand why I need to this db.init_app(app) redis.init_app(app) RQ(app) Markdown(app, extensions=['tables']) @app.route('/') def homepage(): from flask import render_template with app.open_resource('docs/index.md') as f: contents = f.read() return render_template('doc.html', doc=contents) @app.route('/error') def error(): from flask import render_template with app.open_resource('docs/error.md') as f: contents = f.read() return render_template('doc.html', doc=contents) from .api1 import api app.register_blueprint(api, url_prefix="/api/1") return app
def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) config[config_name].init_app(app) # Set up extensions mail.init_app(app) db.init_app(app) login_manager.init_app(app) csrf.init_app(app) compress.init_app(app) RQ(app) # Register Jinja template functions from utils import register_template_utils register_template_utils(app) # Set up asset pipeline assets_env = Environment(app) dirs = ['assets/styles', 'assets/scripts'] for path in dirs: assets_env.append_path(os.path.join(basedir, path)) assets_env.url_expire = True assets_env.register('app_css', app_css) assets_env.register('app_js', app_js) assets_env.register('vendor_css', vendor_css) assets_env.register('vendor_js', vendor_js) assets_env.register('asylum_css', asylum_css) assets_env.register('asylum_scss', asylum_scss) assets_env.register('asylum_js', asylum_js) # Configure SSL if platform supports it if not app.debug and not app.testing and not app.config['SSL_DISABLE']: from flask.ext.sslify import SSLify SSLify(app) # Create app blueprints from main import main as main_blueprint app.register_blueprint(main_blueprint) from account import account as account_blueprint app.register_blueprint(account_blueprint, url_prefix='/account') from admin import admin as admin_blueprint app.register_blueprint(admin_blueprint, url_prefix='/admin') from bulk_resource import bulk_resource as bulk_resource_blueprint app.register_blueprint(bulk_resource_blueprint, url_prefix='/bulk-resource') from descriptor import descriptor as descriptor_blueprint app.register_blueprint(descriptor_blueprint, url_prefix='/descriptor') from single_resource import single_resource as single_resource_blueprint app.register_blueprint(single_resource_blueprint, url_prefix='/single-resource') from suggestion import suggestion as suggestion_blueprint app.register_blueprint(suggestion_blueprint, url_prefix='/suggestion') return app
from flask.ext.admin import Admin from flask.ext.admin.contrib.sqla import ModelView from flask.ext.login import LoginManager, current_user from flask.ext.rq import RQ from flask.ext.sqlalchemy import SQLAlchemy from key import get_secret_key app = Flask(__name__) app.config.from_object('config') # CSRF & stuff key_file = os.path.join(app.instance_path, 'secret.key') app.config['SECRET_KEY'] = get_secret_key(key_file) # RQ RQ(app) # SQLAlchemy uri = 'postgresql+psycopg2://pod@/pod?host=/tmp' app.config['SQLALCHEMY_DATABASE_URI'] = uri db = SQLAlchemy(app) # login lm = LoginManager() lm.init_app(app) @app.before_request def set_g_user(): g.user = current_user
from flask.ext.login import LoginManager from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.bootstrap import Bootstrap from flask.ext.mail import Mail from flask.ext.rq import RQ from flask.ext.principal import Principal from flask.ext.admin import Admin from flask.ext.cdn import CDN from flask_debugtoolbar import DebugToolbarExtension from config import config from .permission import config_identity bootstrap = Bootstrap() db = SQLAlchemy() mail = Mail() rq = RQ() principal = Principal() login_manager = LoginManager() debug_tool_bar = DebugToolbarExtension() login_manager.session_protection = 'strong' login_manager.login_view = 'main.login' admin = Admin() cdn = CDN() def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) bootstrap.init_app(app) db.init_app(app)
from rauth.service import OAuth2Service github = OAuth2Service( name='github', base_url='https://api.github.com/', access_token_url='https://github.com/login/oauth/access_token', authorize_url='https://github.com/login/oauth/authorize', client_id=app.config['GITHUB_CONSUMER_KEY'], client_secret=app.config['GITHUB_CONSUMER_SECRET']) from flask_flatpages import FlatPages pages = FlatPages(app) from flask.ext.rq import RQ rq = RQ(app) from flask.ext.babel import Babel babel = Babel(app) class SMTPHandler(logging.handlers.SMTPHandler): def emit(self, record): if not app.config.get('MANDRILL_KEY'): return from flask import request message = render_template('exception.txt', request=request, stacktrace=self.format(record), current_user=g.user) send_mail(self.getSubject(record), message)
def rq(self): from flask.ext.rq import RQ from flask import current_app return RQ(current_app)