def create_app(**config_overrides): """This is normal setup code for a Flask app, but we give the option to provide override configurations so that in testing, a different database can be used. """ from app.routes.base import register_error_handlers # we want to modify the global app, not a local copy global app global assets app = Flask(__name__) # Load config then apply overrides app.config.from_object('config.flask_config') app.config.update(config_overrides) # Initialize assets assets = Environment(app) register_scss() # Setup the database. db.init_app(app) # Attach Blueprints (routing) to the app register_blueprints(app) # Attache error handling functions to the app register_error_handlers(app) # Register the logger. register_logger(app) return app
def register_web_ui(mgr): global manager, assets manager = mgr assets_cache = os.path.join(manager.config_base, '.webassets-cache') if not os.path.isdir(assets_cache): os.mkdir(assets_cache) assets = Environment(webui_app) assets.directory = assets_cache for p in _get_plugin_paths(): assets.append_path(p, url="%s/plugin" % webui_app.url_path) assets.cache = assets_cache assets.url = '%s/cache' % webui_app.url_path if 'debug' in manager.args: assets.debug = True load_assets() load_ui_plugins() register_app(webui_app.url_path, webui_app) register_home('%s/' % webui_app.url_path)
def configure_assets(app): assets = Environment(app) css = Bundle( 'bootstrap/bootstrap.min.css', 'dist/css/flat-ui.min.css', 'bootstrap-datetimepicker/css/bootstrap-datetimepicker.css', # 'bootstrap/bootstrap-theme.min.css', # 'others/select2/select2.min.css', # 'others/smartwizard/smart_wizard.css', # 'fonts/font-awesome.min.css', 'main.css', filters="cssmin", output='temp/common_packed.css') js = Bundle( 'dist/js/vendor/jquery.min.js', 'jquery/jquery.form.js', 'dist/js/vendor/video.js', 'dist/js/flat-ui.min.js', 'bootstrap-datetimepicker/js/bootstrap-datetimepicker.js', 'bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js', 'message.js', # 'others/particles/particles.js', # 'others/select2/select2.full.min.js', # 'others/jquery.sortable.min.js', # 'others/smartwizard/jquery.smartWizard.js', 'main.js', filters='jsmin', output='temp/common_packed.js') assets.register('css_common', css) assets.register('js_common', js)
def create_app(): app = Flask(__name__, instance_relative_config=True, static_folder='../static/', static_url_path='/static', template_folder='pages') app.config.from_pyfile('settings.py') assets = Environment(app) db.init_app(app) #Compress All Assets js = Bundle('javascripts/vendor/jquery-1.9.1.min.js', 'javascripts/main.js', 'javascripts/plugins.js', 'javascripts/vendor/modernizr-2.6.2.min.js', 'javascripts/vendor/Underscore-1.5.1.js', 'javascripts/vendor/backbone-min.js', filters='jsmin', output='gen/packedjs.js') assets.register('js_all', js) css = Bundle('stylesheets/css/boilerplate_main.css', 'stylesheets/css/normalize.css', 'stylesheets/css/page.css', filters='cssmin', output='gen/packedcss.css') assets.register('css_all', css) return app
def create_app(config=None): app = Flask(__name__, instance_relative_config=True) app.config.from_object('settings') app.config.from_pyfile('settings_local.py', silent=True) app.json_encoder = AppJSONEncoder app.config.setdefault('SQLALCHEMY_DATABASE_URI', 'postgresql+psycopg2://cidadeiluminada:cidadeiluminada@localhost/cidadeiluminada') if config: app.config.update(config) Environment(app) base.init_app(app) auth.init_app(app) protocolos.init_app(app) @app.route('/') def index(): return redirect(url_for('protocolos.index')) @app.context_processor def menu_items(): return { 'menu_items': [ (u'Protocolos', 'protocolos.index'), (u'(ALPHA) Novo protocolo', 'protocolos.novo_pagina'), (u'Gerenciar usuários', 'auth.gerenciar') ] } return app
def init_app(app): webassets = Environment(app) webassets.register('apollo_css', apollo_css) webassets.register('apollo_js', apollo_js) webassets.manifest = 'cache' if not app.debug else False webassets.cache = not app.debug webassets.debug = app.debug
def init_webassets(flask_app, config): """ Initialize Flask-Assets extension. """ assets = Environment(flask_app) assets.debug = flask_app.debug dart_root = 'dart/web' if flask_app.debug else 'dart/build/web' assets.register("less", Bundle( "less/bootstrap/bootstrap.less", "less/font-awesome/font-awesome.less", filters="less", output="combined/bootstrap.css", depends="less/*.less" )) assets.register('dart', Bundle( dart_root + '/main.dart' )) assets.register("javascript", Bundle( 'js/d3.js', 'js/markdown.js', dart_root + '/packages/web_components/dart_support.js', dart_root + '/packages/browser/dart.js', output='combined/combined.js' ))
def create_app(mode="development"): """Create webapp instance.""" app = Flask(__name__) #Initilise DB from bluespot.extensions import db db.init_app(app) # Load the default configuration app.config.from_object('config.default') #Load user specified config app.config.from_yaml(os.path.join(app.root_path, '..', 'config.yaml')) #initlize assets assets = Environment(app) assets.register(bundles) # simple load all blueprint settings, enabled in config load_blueprint_settings(app, blueprint_path='bluespot') # simple load all blueprints, enabled in config load_blueprints(app, blueprint_path='bluespot') # Enable DebugToolbar on debug # Enable error handler on productive mode if app.config['DEBUG']: from flask_debugtoolbar import DebugToolbarExtension DebugToolbarExtension(app) app.logger.error("DEV") else: # add errorhandler #error_handler(app) app.logger.error("PROD") @app.route("/") def home(): return "OK" return app
def init_app(app): Environment(app) Babel(app) Sentry(app) db.init_app(app) Migrate(app, db) mail.init_app(app)
def configure_assets(app): assets = Environment(app) js = Bundle(*BUNDLE_JS, filters='jsmin', output='output/packed.js') css_rewrite = get_filter('cssrewrite', replace={'/static/': '../'}) css = Bundle(*BUNDLE_CSS, filters=(css_rewrite, 'cssmin'), output='output/packed.css') ie7_css = Bundle(*BUNDLE_IE7_CSS, filters='cssmin', output='output/packed_ie7.css') ie8_css = Bundle(*BUNDLE_IE8_CSS, filters='cssmin', output='output/packed_ie8.css') ie9_css = Bundle(*BUNDLE_IE9_CSS, filters='cssmin', output='output/packed_ie9.css') print_css = Bundle(*BUNDLE_PRINT_CSS, filters='cssmin', output='output/packed_print.css') assets.register('packed_js', js) assets.register('packed_css', css) assets.register('packed_ie7_css', ie7_css) assets.register('packed_ie8_css', ie8_css) assets.register('packed_ie9_css', ie9_css) assets.register('packed_print_css', print_css)
def run_server(options): api_listener = Api() gevent.spawn(api_listener.run) # # Setup flask app static_url_path = "/changed-so-it-doesnt-conflict-with-blueprint-static-path" app = Flask(__name__, static_url_path=static_url_path) app.config.from_pyfile(options["config"].name) app.register_blueprint(FrontendBlueprint()) # # JS/CSS & HTML minification in production if not app.config.get('DEBUG'): from .misc.jinja2htmlcompress import HTMLCompress app.jinja_env.add_extension(HTMLCompress) assets = Environment() assets.init_app(app) # # Run server http = WSGIServer((options['http_host'], options['http_port']), app) LOGGER.info('Listening on %s:%s', options['http_host'], options['http_port']) try: http.serve_forever() return 0 except KeyboardInterrupt: http.stop() api_listener.stop() LOGGER.info('Application Terminated') return 0
def test_no_override(self): """Ensure that the webassets defaults do not override existing Flask config values. """ app = Flask(__name__) app.config['ASSETS_UPDATER'] = 'MOO' env = Environment(app) assert env.updater == 'MOO' assert app.config['ASSETS_UPDATER'] == 'MOO' # Neither do the defaults that flask-assets set. app = Flask(__name__) app.config['ASSETS_URL'] = 'MOO' env = Environment(app) assert env.url == 'MOO' assert app.config['ASSETS_URL'] == 'MOO'
def create_app(**config_overrides): from app.routes.base import register_error_handlers # we want to modify the global app, not a local copy global app global assets app = Flask(__name__) # Load config then apply overrides app.config.from_object('config.flask_config') app.config.update(config_overrides) # Initialize assets assets = Environment(app) register_scss() # Setup the database. db.init_app(app) # Attach Blueprints (routing) to the app register_blueprints(app) # Attache error handling functions to the app register_error_handlers(app) # Register the logger. register_logger(app) return app
def bundle_assets(app, minify=True): js_filters = ['yui_js'] if minify else None css_filters = ['yui_css'] if minify else None js = Bundle( 'js/google_maps.js', 'js/ajax.js', filters=js_filters, output='gen/packed.js', ) css = Bundle( 'css/style.css', 'css/responsive.css', 'css/fonts.css', filters=css_filters, output='gen/packed.css', ) assets = Environment() assets.register('js', js) assets.register('css', css) app.config['ASSETS_DEBUG'] = not minify assets.init_app(app)
def assets_env(app): env = Environment(app) env.url = "/static" # App Engine doesn't support automatic rebuilding. env.auto_build = False # This file needs to be shipped with your code. env.manifest = ('file:' + os.path.join(root_dir, 'webassets.manifest')) env.versions = 'hash:32' # create static bundles env.register('new_js', 'js/hiro.js', filters='yui_js', output="javascript/hiro.%(version)s.js") env.register('hoc_js', 'js/hoc.js', filters='yui_js', output="javascript/hoc.%(version)s.js") env.register('new_css', 'css/hiro.css', filters='cssmin', output="stylesheets/hiro.%(version)s.css") env.register('hoc_css', 'css/hoc.css', filters='cssmin', output="stylesheets/hoc.%(version)s.css") env.debug = app.config['DEBUG'] return env
def compile_assets(app, bundle_config=bundles_config): if not bundle_config: raise ConfigNotFoundError('Bundles config is empty') assets = Environment(app) for name, settings in bundle_config.iteritems(): bundle = check_and_compile_bundle(name, settings) assets.register(name, bundle)
def create_app(instance_path=None, debug=False, test=False): use_instances = False if instance_path is not None: use_instances = True app = Flask(__name__, instance_relative_config=use_instances, instance_path=instance_path, template_folder="views", static_path='/static', static_url_path='/static') app.debug = debug app.jinja_env.add_extension('pyjade.ext.jinja.PyJadeExtension') app.config.from_object('app.config') app.config.from_pyfile('config.py') if not test: CsrfProtect(app) assets = Environment(app) css_bundle = Bundle('less/main.less', output='css/main.css', filters='less') assets.register('css', css_bundle) js_bundle = Bundle('js/main.js', output="main.min.js", filters="rjsmin") assets.register('js', js_bundle) email = FlaskMailgunMessage(app) @app.route('/', methods=['GET', 'POST']) def index(): form = ApplicationForm() if form.validate_on_submit(): if form.squirrel.data: # ANTI SPAM YO app.logger.info('SECRET SQUIRREL') return redirect(url_for('index')) form_data = "name: {}\nemail: {}\nphone: {}\n\n".format( form.name.data, form.email.data, form.phone.data) app.logger.info(form_data) # send the email email.send(form_data) flash(app.config['THANKS_FLASH']) return redirect(url_for('index')) return render_template('index.jade', form=form) return app
def assets(self): if self._assets is not None: return self._assets else: if (not hasattr(self.app.jinja_env, 'assets_environment') or not self.app.jinja_env.assets_environment): self._assets = Environment(self.app) self._assets = self.app.jinja_env.assets_environment return self._assets
def setup(self): self.app = Flask(__name__) self.env = Environment(self.app) self.env.debug = True self.app.config.update({ 'ASSETS_DIRECTORY': '', 'ASSETS_URL': '/foo', }) self.env.register('test', 'file1', 'file2')
def create_app(config=None): app = Flask(__name__, instance_relative_config=True) Environment(app) app.config.from_object('settings') app.config.from_pyfile('settings_local.py', silent=True) app.json_encoder = AppJSONEncoder app.secret_key = app.config.get('SECRET_KEY') cidadeiluminada.init_app(app) return app
def create_app(config='dev'): """ Flask application factory :param str config: type of app to build, either "prod" or "dev" """ # Create flask application app = Flask(__name__) app.config.from_object('settings') app.config['ENV'] = config app.jinja_env.trim_blocks = True # Debug toolbar (when debug=true) debug_toolbar = DebugToolbarExtension(app) app.config['DEBUG_TB_PROFILER_ENABLED'] = True app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False # Register Blueprints app.register_blueprint(views_base.base) app.register_blueprint(views_blog.blog) # Flask-Assets; bundles all css/js files in minifed file assets = Environment(app) css_all = Bundle('css/bootstrap-flatly.min.css', 'css/highlightjs.min.css', 'css/font-awesome.css', 'css/main.css', filters='cssmin', output='gen/style.css') js_all = Bundle('js/vendor/jquery.min.js', 'js/vendor/bootstrap.min.js', 'js/vendor/showdown-gfm.min.js', 'js/vendor/highlight.min.js', 'js/main.js', filters='jsmin', output='gen/libs.js') assets.register('css_all', css_all) assets.register('js_all', js_all) if app.config['DEBUG']: assets.debug = True app.config['ASSETS_DEBUG'] = True # Set up Flask-User babel = Babel(app) db_adapter = SQLAlchemyAdapter(db, User) user_manager = UserManager(db_adapter, app) # Init Flask-User and bind to app # Init the cache cache.init_app(app) Moment(app) # moment.js Misaka(app, autolink=True, # Misaka Markdown fenced_code=True, lax_html=True, strikethrough=True, superscript=True, tables=True, wrap=True) # Init Admin page admin = Admin(app, index_view=AdminMain(endpoint='admin')) admin.add_view(PostAdminView()) admin.add_view(NewPostView()) admin.add_view(ModelView(Comment, db.session)) static_path = os.path.join(BASE_DIR, 'app', 'static') admin.add_view(FileAdminView(static_path, '/static/', name='Static Files')) # Initialize DB db.init_app(app) 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) 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 create_app(package_name, js_assets=None, css_assets=None, settings_override=None): """Flask app factory.""" app = Flask(package_name, instance_relative_config=True) app.config.from_pyfile('settings.cfg', silent=False) app.config.from_object(settings_override) assets = Environment(app) assets.url = '../static' common_css_assets = [ 'css/bootstrap.min.css', 'css/animations.css', 'css/superfish.css', 'css/prettyPhoto.css', 'css/style.css', 'css/colors/blue.css', 'css/theme-responsive.css', ] common_js_assets = [ 'js/jquery.min.js', 'js/bootstrap.min.js', 'js/handlebars.js', 'js/ember.js', 'js/jquery.cookie.js', 'js/jquery.ba-bbq.min.js', ] if js_assets is not None: js_assets = common_js_assets + js_assets else: js_assets = common_js_assets js_bundle = Bundle( *js_assets, filters='jsmin', output='gen/' + package_name + '.js' ) assets.register('js_all', js_bundle) if css_assets is not None: css_assets = common_css_assets + css_assets else: css_assets = common_css_assets css_bundle = Bundle( *css_assets, filters='cssmin', output='gen/' + package_name + '.css' ) assets.register('css_all', css_bundle) assets.init_app(app) return app
def init_assets(app): app.assets = Environment(app) app.assets.auto_build = False app.assets.directory = os.path.join(DIR, 'assets') app.assets.manifest = 'file' app.assets.url = '/static' manifest = YAMLLoader(os.path.join(DIR, 'assets', 'manifest.yaml')) manifest = manifest.load_bundles() [app.assets.register(n, manifest[n]) for n in manifest]
def create_app(**config_overrides): """This is normal setup code for a Flask app, but we give the option to provide override configurations so that in testing, a different database can be used. """ # we want to modify the global app, not a local copy global app global adi global assets global gcal_client app = Flask(__name__) # Load config then apply overrides app.config.update(config_overrides) from config import flask_config app.config.update(**flask_config.config) app.config.update(config_overrides) # load ADI specific configurations (ignore built-in methods) for attr in (x for x in dir(adi_config) if x[:2] != "__"): adi[attr] = getattr(adi_config, attr) # Initialize assets assets = Environment(app) register_scss() # Setup the database. db.init_app(app) # Initialize the Google Calendar API Client, but only if the api # credentials have been generated first. try: from app.lib.google_calendar import GoogleCalendarAPIClient gcal_client = GoogleCalendarAPIClient() except IOError: gae_environ = 'TRUE' if app.config['GOOGLE_AUTH_ENABLED'] else 'FALSE' raise Exception('Failed to find the Google Calendar credentials file ' 'at `{}`, please create it by running:\n\n' ' $ python manage.py --authorize\n' 'The environment variable GOOGLE_AUTH_ENABLED is ' 'currently set to `{}`. If set to FALSE, Google ' 'Calendar calls will fail silently.'.format( app.config['INSTALLED_APP_CREDENTIALS_PATH'], gae_environ)) exit(1) register_delete_rules() register_blueprints() from app.routes.base import register_error_handlers register_error_handlers(app) register_logger() return app
def initialise_app(app, configclass): # Load the default configuration app.config.from_object(configclass) # Load the configuration from the instance folder try: app.config.from_pyfile('config.py') except: print 'No instance config file' if app.config['USE_PROXY']: app.wsgi_app = ProxyFix(app.wsgi_app) toolbar = DebugToolbarExtension(app) db.init_app(app) mail.init_app(app) assets = Environment(app) assets.register(bundles) from .models import User, Feed, Entry, Author, Role user_datastore = SQLAlchemyUserDatastore(db, User, Role) app.security = Security(app, user_datastore) wtf.add_helpers(app) admin = Admin(app, 'Admin', index_view=SecuredAdminIndexView()) admin.add_view(SecuredModelView(User, db.session)) admin.add_view(SecuredModelView(Feed, db.session)) admin.add_view(SecuredModelView(Entry, db.session)) admin.add_view(SecuredModelView(Author, db.session)) app.register_blueprint(frontend_blueprint) identity_loaded.connect_via(app)(on_identity_loaded) add_errorhandlers(app) Principal(app) if not app.debug: import logging from .utils.loggers import add_logger_filehandler, add_logger_external add_logger_filehandler(app) if app.config['LOG_ADDRESS']: add_logger_external(app) app.logger.setLevel(logging.INFO) app.logger.info(u'{0} startup'.format(app.config['PROJECT_NAME'])) return app
def create_app(settings_override=None): """Returns the dashboard application instance""" app = factory.create_app(__name__, __path__, settings_override) Environment(app) # Register custom error handlers if not app.debug: for e in [500, 404]: app.errorhandler(e)(handle_error) return app
def init(app): assets = Environment(app) js = Bundle(*app.config['JS_ASSETS'], output=app.config['JS_ASSETS_OUTPUT'], filters=app.config['JS_ASSETS_FILTERS']) css = Bundle(*app.config['CSS_ASSETS'], output=app.config['CSS_ASSETS_OUTPUT'], filters=app.config['CSS_ASSETS_FILTERS']) assets.register('js_all', js) assets.register('css_all', css)
def register_assets(app): app.jinja_env.filters['formatDollars'] = formatDollars assets = Environment(app) css = Bundle('css/normalize.css', 'css/skeleton.css', 'css/custom.css', filters='cssmin', output='gen/packed.css') assets.register('css_all', css) return app
def _create_environment(self, **kwargs): if FLASK_VERSION < '0.7': # Older Flask versions do not support the # static_folder argument, which we need to use # a temporary folder for static files, without # having to do sys.path hacking. raise SkipTest() if not hasattr(self, 'app'): self.app = Flask(__name__, static_folder=self.tempdir, **kwargs) self.env = Environment(self.app) return self.env