Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
    def install(cls, app):
        """Install the extension into the application."""
        Environment.resolver_class = InvenioResolver
        env = Environment(app)
        env.url = "{0}/{1}/".format(app.static_url_path,
                                    app.config["ASSETS_BUNDLES_DIR"])
        env.directory = os.path.join(app.static_folder,
                                     app.config["ASSETS_BUNDLES_DIR"])
        env.append_path(app.static_folder)
        env.auto_build = app.config.get("ASSETS_AUTO_BUILD", True)

        # The filters less and requirejs don't have the same behaviour by
        # default. Make sure we are respecting that.
        app.config.setdefault("LESS_RUN_IN_DEBUG", True)
        app.config.setdefault("REQUIREJS_RUN_IN_DEBUG", False)
        # Fixing some paths as we forced the output directory with the
        # .directory
        app.config.setdefault("REQUIREJS_BASEURL", app.static_folder)
        requirejs_config = os.path.join(env.directory,
                                        app.config["REQUIREJS_CONFIG"])
        if not os.path.exists(requirejs_config):
            app.config["REQUIREJS_CONFIG"] = os.path.relpath(
                os.path.join(app.static_folder,
                             app.config["REQUIREJS_CONFIG"]),
                env.directory)

        app.jinja_env.add_extension(BundleExtension)
        app.context_processor(BundleExtension.inject)
Пример #4
0
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)

    # 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
Пример #5
0
def init_app(app):
    assets = Environment(app)
    assets.debug = app.config.get('DEBUG', False)
    assets.directory = app.static_folder
    assets.url = app.static_url_path
    assets.directory = app.static_folder
    assets.append_path(assets_directory)
    assets.append_path(app.static_folder)
Пример #6
0
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
Пример #7
0
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)

    # 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)

    # 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")

    return app
Пример #8
0
def init_app(app):
    assets = Environment(app)
    assets.debug = app.config.get('DEBUG', False)
    assets.directory = app.static_folder
    assets.url = app.static_url_path
    assets.directory = app.static_folder
    assets.append_path(assets_directory)
    assets.append_path(app.static_folder)
    assets.register("h5bp_css", h5bp_css)
    assets.register("h5bp_shiv", h5bp_shiv)
    assets.register("h5bp_head_js", h5bp_head_js)
    if assets.debug:
        assets.register("h5bp_body_js", h5bp_body_js_devel)
    else:
        assets.register("h5bp_body_js", h5bp_body_js_production)
Пример #9
0
def register_assets(app, debug=False):
    """We add the app's root path to assets search path. However, the
    output directory is relative to `app.static_folder`.
    """
    assets = Environment(app)
    assets.debug = debug
    assets.auto_build = True
    assets.manifest = 'file'
    assets.append_path(app.root_path)

    site_js = Bundle(
        'static/app.js',
        filters=('uglifyjs',),
        output='js/bundle.js'
    )
    assets.register('site_js', site_js)

    site_css = Bundle(
        'static/style.css',
        filters=('cssmin',),
        output='css/bundle.css'
    )
    assets.register('site_css', site_css)
Пример #10
0
def init_app(app):

    # Initialize webassets, the asset pipeline
    assets = Environment(app)
    assets.debug = app.config['DEBUG']

    cur_path = os.path.dirname(os.path.abspath(__file__))
    assets_load_path = os.path.join(cur_path, 'static')

    if ('WEBASSETS_PATH' in app.config):
        assets_load_path = app.config['WEBASSETS_PATH']
        logger.debug('Using asset directory specified in config.')

    logger.debug('Using asset directory of: {0}.'.format(assets_load_path))

    # Output path for compiled assets
    assets.directory = os.path.join(cur_path, 'static')
    assets.url = '/static/'
    assets.from_yaml(os.path.join(cur_path, 'assets.yml'))
    assets.config['closure_compressor_optimization'] = 'SIMPLE_OPTIMIZATIONS'
    assets.config['closure_extra_args'] = ['--language_in', 'ECMASCRIPT5']
    assets.append_path(assets_load_path)

    return assets
Пример #11
0
class TestUrlAndDirectory(TempEnvironmentHelper):
    """By default, the 'url' and 'directory' settings of webassets are
    not used in Flask-Assets; that is, the values are automatically
    handled based on the configuration of the Flask app and the modules
    used.

    The user can disable the automatic handling by setting these values
    if he needs to for some reason.

    Let's test the different scenarios to ensure everything works.
    """

    def setup(self):
        TempEnvironmentHelper.setup(self)

        self.app = Flask(__name__, static_path='/app_static')
        from tests import test_module
        if not Blueprint:
            self.module = Module(test_module.__name__, name='module',
                                 static_path='/mod_static')
            self.app.register_module(self.module)
        else:
            self.blueprint = Blueprint('module', test_module.__name__,
                                       static_url_path='/mod_static',
                                       static_folder='static')
            self.app.register_blueprint(self.blueprint)
        self.env = Environment(self.app)

    def test_config_values_not_set_by_default(self):
        assert not 'directory' in self.env.config
        assert not 'url' in self.env.config
        assert_raises(KeyError, self.env.config.__getitem__, 'directory')
        assert_raises(KeyError, self.env.config.__getitem__, 'url')

    def test_directory_auto(self):
        """Test how we resolve file references through the Flask static
        system by default (if no custom 'env.directory' etc. values
        have been configured manually).
        """
        assert not 'directory' in self.env.config
        root = self.app.root_path
        assert get_all_bundle_files(Bundle('foo'), self.env) == [root + '/static/foo']
        # Modules prefixes in paths are handled specifically.
        assert get_all_bundle_files(Bundle('module/bar'), self.env) == [root + '/test_module/static/bar']
        # Prefixes that aren't valid module names are just considered
        # subfolders of the main app.
        assert get_all_bundle_files(Bundle('nomodule/bar'), self.env) == [root + '/static/nomodule/bar']
        # In case the name of a app-level subfolder conflicts with a
        # module name, you can always use this hack:
        assert get_all_bundle_files(Bundle('./module/bar'), self.env) == [root + '/static/module/bar']

        # Custom static folder
        self.app.static_folder = '/'
        assert get_all_bundle_files(Bundle('foo'), self.env) == ['/foo']

    def test_url_auto(self):
        """Test how urls are generated via the Flask static system
        by default (if no custom 'env.url' etc. values have been
        configured manually).
        """
        assert not 'url' in self.env.config

        assert Bundle('foo', env=self.env).urls() == ['/app_static/foo']
        # Urls for files that point to a module use that module's url prefix.
        assert Bundle('module/bar', env=self.env).urls() == ['/mod_static/bar']
        # Try with a prefix that's not actually a valid module
        assert Bundle('nomodule/bar', env=self.env).urls() == ['/app_static/nomodule/bar']

        # [Regression] Ensure that any request context we may have added
        # to the stack has been removed.
        from flask import _request_ctx_stack
        assert _request_ctx_stack.top is None

    def test_custom_load_path(self):
        """A custom load_path is configured - this will affect how
        we deal with source files.
        """
        self.env.append_path(self.tempdir, '/custom/')
        self.create_files(['foo', 'module/bar'])
        assert get_all_bundle_files(Bundle('foo'), self.env) == [self.path('foo')]
        # We do not recognize references to modules.
        assert get_all_bundle_files(Bundle('module/bar'), self.env) == [self.path('module/bar')]


        assert Bundle('foo', env=self.env).urls() == ['/custom/foo']
        assert Bundle('module/bar', env=self.env).urls() == ['/custom/module/bar']

        # [Regression] With a load path configured, generating output
        # urls still works, and it still uses the flask system.
        self.env.debug = False
        self.env.url_expire = False
        assert Bundle('foo', output='out', env=self.env).urls() == ['/app_static/out']

    def test_custom_directory_and_url(self):
        """Custom directory/url are configured - this will affect how
        we deal with output files."""
        # Create source source file, make it findable (by default,
        # static_folder) is set to a fixed subfolder of the test dir (why?)
        self.create_files({'a': ''})
        self.app.static_folder = self.tempdir
        # Setup custom directory/url pair for output
        self.env.directory = self.tempdir
        self.env.url = '/custom'
        self.env.debug = False   # Return build urls
        self.env.url_expire = False  # No query strings

        assert Bundle('a', output='foo', env=self.env).urls() == ['/custom/foo']
        # We do not recognize references to modules.
        assert Bundle('a', output='module/bar', env=self.env).urls() == ['/custom/module/bar']

    def test_existing_request_object_used(self):
        """[Regression] Check for a bug where the url generation code of
        Flask-Assets always added a dummy test request to the context stack,
        instead of using the existing one if there is one.

        We test this by making the context define a custom SCRIPT_NAME
        prefix, and then we check if it affects the generated urls, as
        it should.
        """
        with self.app.test_request_context(
                  '/', environ_overrides={'SCRIPT_NAME': '/yourapp'}):
            assert Bundle('foo', env=self.env).urls() == ['/yourapp/app_static/foo']

    def test_glob(self):
        """Make sure url generation works with globs."""
        self.app.static_folder = self.tempdir
        self.create_files({'a.js': 'foo', 'b.js': 'bar'})
        assert list(sorted(self.mkbundle('*.js', env=self.env).urls())) == [
            '/app_static/a.js', '/app_static/b.js']
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
Пример #13
0
            "rename_search": "",
            "rename_replace": ""
        }
    })

app.config["CSRF_SESSION_KEY"] = config["general"]["csrf_session_key"]
app.config["SECRET_KEY"] = config["general"]["secret_key"]

assets = Environment(app)

# use app/static/compiled as output path for webassets' assets
assets.directory = os.path.abspath(app.root_path + os.sep + "static" + os.sep + "compiled")
assets.url = "/static/compiled"

# use app/static as load path for assets
assets.append_path(app.root_path + os.sep + "static", "static")

# load asset definitions from "static/webassets.py"
assets_loader = PythonAssetsLoader(webassets)
bundles = assets_loader.load_bundles()
for bundle in bundles:
    assets.register(bundle, bundles[bundle])

db = SQLAlchemy(app)
babel = Babel(app)
Compress(app)


@babel.localeselector
def get_locale():
    # try to guess the language from the user accept header the browser transmits. We support de/en.
Пример #14
0
from webassets.ext.jinja2 import AssetsExtension
from flask.ext.assets import Environment as FlaskAssetsEnvironment

from conf import *
from devserver import devserver, date_filter
from admin.models import get_news, get_gigs

env.roledefs = {'demo': [DEMO_SERVER], 'local': ['localhost']}
roots = {DEMO_SERVER: DEMO_ROOT}

wa_env = webassets.Environment(BUILD_PATH, '/')
wa_env.append_path('static/css')

fla_env = FlaskAssetsEnvironment(devserver)
fla_env.append_path('static/css')

all_css = ['font-awesome.min.css', 'jquery.mCustomScrollbar.css', 'normalize.css', 'styles.css']
bundle = webassets.Bundle(*all_css, output='static/css/main.css')
b2 = webassets.Bundle(*all_css, output='css/_build.css')
wa_env.register('css', bundle)
fla_env.register('css', b2)


@task
def build_templates():
	jj_env = jinja2.Environment(loader=jinja2.FileSystemLoader(TEMPLATE_PATH),
		extensions=[AssetsExtension])
	jj_env.assets_environment = wa_env
	jj_env.filters['date'] = date_filter
	static_root = os.path.join(BUILD_PATH, 'static')
Пример #15
0
from flask import Flask, url_for
from flask.ext.assets import Environment, Bundle
from flask.ext.sqlalchemy import SQLAlchemy
import os

app = Flask(__name__)
conf = os.environ.get('APP_CONFIG', 'pghtrash.config.DevelopmentConfig')
app.config.from_object(conf)
db = SQLAlchemy(app)

# Set up less compilation
assets = Environment(app)
assets.append_path('assets')
assets.register('css_all',
                '*.css',
                Bundle('pghtrash.less', filters='less'),
                filters='cssmin',
                output='.gen/pghtrash.min.css',
                depends='*.less')

# Load our routes
from pghtrash.routes import setup_routes
setup_routes(app)

# Insure models are loaded
from pghtrash import models
Пример #16
0
class TestUrlAndDirectory(TempEnvironmentHelper):
    """By default, the 'url' and 'directory' settings of webassets are
    not used in Flask-Assets; that is, the values are automatically
    handled based on the configuration of the Flask app and the modules
    used.

    The user can disable the automatic handling by setting these values
    if he needs to for some reason.

    Let's test the different scenarios to ensure everything works.
    """
    def setup(self):
        TempEnvironmentHelper.setup(self)

        self.app = Flask(__name__, static_path='/app_static')
        import test_module
        if not Blueprint:
            self.module = Module(test_module.__name__,
                                 name='module',
                                 static_path='/mod_static')
            self.app.register_module(self.module)
        else:
            self.blueprint = Blueprint('module',
                                       test_module.__name__,
                                       static_url_path='/mod_static',
                                       static_folder='static')
            self.app.register_blueprint(self.blueprint)
        self.env = Environment(self.app)

    def test_config_values_not_set_by_default(self):
        assert not 'directory' in self.env.config
        assert not 'url' in self.env.config
        assert_raises(KeyError, self.env.config.__getitem__, 'directory')
        assert_raises(KeyError, self.env.config.__getitem__, 'url')

    def test_directory_auto(self):
        """Test how we resolve file references through the Flask static
        system by default (if no custom 'env.directory' etc. values
        have been configured manually).
        """
        assert not 'directory' in self.env.config
        root = self.app.root_path
        assert get_all_bundle_files(Bundle('foo'),
                                    self.env) == [root + '/static/foo']
        # Modules prefixes in paths are handled specifically.
        assert get_all_bundle_files(Bundle('module/bar'), self.env) == [
            root + '/test_module/static/bar'
        ]
        # Prefixes that aren't valid module names are just considered
        # subfolders of the main app.
        assert get_all_bundle_files(Bundle('nomodule/bar'), self.env) == [
            root + '/static/nomodule/bar'
        ]
        # In case the name of a app-level subfolder conflicts with a
        # module name, you can always use this hack:
        assert get_all_bundle_files(Bundle('./module/bar'),
                                    self.env) == [root + '/static/module/bar']

        # Custom static folder
        self.app.static_folder = '/'
        assert get_all_bundle_files(Bundle('foo'), self.env) == ['/foo']

    def test_url_auto(self):
        """Test how urls are generated via the Flask static system
        by default (if no custom 'env.url' etc. values have been
        configured manually).
        """
        assert not 'url' in self.env.config

        assert Bundle('foo').urls(self.env) == ['/app_static/foo']
        # Urls for files that point to a module use that module's url prefix.
        assert Bundle('module/bar').urls(self.env) == ['/mod_static/bar']
        # Try with a prefix that's not actually a valid module
        assert Bundle('nomodule/bar').urls(
            self.env) == ['/app_static/nomodule/bar']

        # [Regression] Ensure that any request context we may have added
        # to the stack has been removed.
        from flask import _request_ctx_stack
        assert _request_ctx_stack.top is None

    def test_custom_load_path(self):
        """A custom load_path is configured - this will affect how
        we deal with source files.
        """
        self.env.append_path(self.tempdir, '/custom/')
        self.create_files(['foo', 'module/bar'])
        assert get_all_bundle_files(Bundle('foo'),
                                    self.env) == [self.path('foo')]
        # We do not recognize references to modules.
        assert get_all_bundle_files(Bundle('module/bar'),
                                    self.env) == [self.path('module/bar')]

        assert Bundle('foo').urls(self.env) == ['/custom/foo']
        assert Bundle('module/bar').urls(self.env) == ['/custom/module/bar']

        # [Regression] With a load path configured, generating output
        # urls still works, and it still uses the flask system.
        self.env.debug = False
        self.env.url_expire = False
        assert Bundle('foo',
                      output='out').urls(self.env) == ['/app_static/out']

    def test_custom_directory_and_url(self):
        """Custom directory/url are configured - this will affect how
        we deal with output files."""
        # Create source source file, make it findable (by default,
        # static_folder) is set to a fixed subfolder of the test dir (why?)
        self.create_files({'a': ''})
        self.app.static_folder = self.tempdir
        # Setup custom directory/url pair for output
        self.env.directory = self.tempdir
        self.env.url = '/custom'
        self.env.debug = False  # Return build urls
        self.env.url_expire = False  # No query strings

        assert Bundle('a', output='foo').urls(self.env) == ['/custom/foo']
        # We do not recognize references to modules.
        assert Bundle('a', output='module/bar').urls(
            self.env) == ['/custom/module/bar']

    def test_existing_request_object_used(self):
        """[Regression] Check for a bug where the url generation code of
        Flask-Assets always added a dummy test request to the context stack,
        instead of using the existing one if there is one.

        We test this by making the context define a custom SCRIPT_NAME
        prefix, and then we check if it affects the generated urls, as
        it should.
        """
        with self.app.test_request_context(
                '/', environ_overrides={'SCRIPT_NAME': '/yourapp'}):
            assert Bundle('foo').urls(self.env) == ['/yourapp/app_static/foo']

    def test_glob(self):
        """Make sure url generation works with globs."""
        self.app.static_folder = self.tempdir
        self.create_files({'a.js': 'foo', 'b.js': 'bar'})
        assert list(sorted(self.mkbundle('*.js').urls(
            self.env))) == ['/app_static/a.js', '/app_static/b.js']
Пример #17
0
            "rename_replace": ""
        }
    })

app.config["CSRF_SESSION_KEY"] = config["general"]["csrf_session_key"]
app.config["SECRET_KEY"] = config["general"]["secret_key"]

assets = Environment(app)

# use app/static/compiled as output path for webassets' assets
assets.directory = os.path.abspath(app.root_path + os.sep + "static" + os.sep +
                                   "compiled")
assets.url = "/static/compiled"

# use app/static as load path for assets
assets.append_path(app.root_path + os.sep + "static", "static")

# load asset definitions from "static/webassets.py"
assets_loader = PythonAssetsLoader(webassets)
bundles = assets_loader.load_bundles()
for bundle in bundles:
    assets.register(bundle, bundles[bundle])

db = SQLAlchemy(app)
babel = Babel(app)
Compress(app)


@babel.localeselector
def get_locale():
    # try to guess the language from the user accept header the browser transmits. We support de/en.