Example #1
0
def init(app=None):
    """Define asset files."""
    app = app or Flask(__name__)
    with app.app_context():
        env = Environment(app)
        env.load_path = [Path(__file__).parent / "static"]
        env.auto_build = False
        env.manifest = "file"

        css_font = Bundle("./font/Inter/stylesheet.css",
                          filters="rcssmin",
                          output="css/inter.min.css")
        env.register("css_font", css_font)

        css_site = Bundle("./css/site.css",
                          filters="libsass,rcssmin",
                          output="css/site.min.css")
        env.register("css_site", css_site)

        js_site = Bundle("./js/site.js",
                         filters="jsmin",
                         output="js/site.min.js")
        env.register("js_site", js_site)

        return [css_font, css_site, js_site]
Example #2
0
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
Example #3
0
def init_app(app):
    webassets = Environment(app)
    webassets.register('css_all', css_all)
    webassets.register('js_vendor', js_vendor)
    webassets.manifest = 'cache' if not app.debug else False
    webassets.cache = not app.debug
    webassets.debug = app.debug
Example #4
0
def create_app():
    app = Flask(__name__,\
                static_folder="static/",\
                template_folder="templates/",\
                static_url_path="/static")

    # set config
    #    app_settings = os.getenv('APP_SETTINGS', 'app.config.DevelopmentConfig')
    app.config.from_object('config')

    # set up extensions
    db.init_app(app)

    app.register_blueprint(charts_blueprint)
    app.register_blueprint(webapi)

    # Scss
    assets = Environment(app)
    assets.versions = 'timestamp'
    assets.url_expire = True
    assets.manifest = 'file:/tmp/manifest.to-be-deployed'  # explict filename
    assets.cache = False
    assets.auto_build = True

    assets.url = app.static_url_path
    scss = Bundle('scss/__main__.scss',
                  filters='pyscss',
                  output='css/main.css',
                  depends=['scss/*.scss'])
    assets.register('scss_all', scss)

    assets.debug = False
    app.config['ASSETS_DEBUG'] = False

    return app
Example #5
0
def init_app(app):
    webassets = Environment(app)
    webassets.register('css_all', css_all)
    webassets.register('js_vendor', js_vendor)
    webassets.manifest = 'cache' if not app.debug else False
    webassets.cache = not app.debug
    webassets.debug = app.debug
Example #6
0
def init(app=None):
    app = app or Flask(__name__)
    with app.app_context():
        env = Environment(app)
        env.directory = 'aqandu/static'
        env.load_path = [path.join(path.dirname(__file__), 'aqandu/static')]
        # env.append_path('assets')
        # env.set_directory(env_directory)
        # App Engine doesn't support automatic rebuilding.
        env.auto_build = False
        env.versions = 'hash'
        # This file needs to be shipped with your code.
        env.manifest = 'file'

        all_css = Bundle('css/airu.css',
                         'css/visualization.css',
                         'css/ie10-viewport-bug-workaround.css',
                         filters='cssmin',
                         output='css/all_css.%(version)s.css')
        env.register('css', all_css)

        all_js = Bundle('js/db_data.js',
                        'js/map_reconfigure.js',
                        filters='jsmin',
                        output='js/all_js.%(version)s.js')
        env.register('js', all_js)

        # bundles = [css, js]
        bundles = [all_css, all_js]
        # bundles = [all_css]
        return bundles
Example #7
0
def create_app():
    app = Flask(__name__,\
                static_folder="static/",\
                template_folder="templates/",\
                static_url_path="/static")

    set_config(app)

    # set up extensions
    cache.init_app(app)
    db.init_app(app)
    datepicker(app)
    mail.init_app(app)

    # blueprints
    app.register_blueprint(auth)
    app.register_blueprint(admin_blueprint)
    app.register_blueprint(charts_blueprint)
    app.register_blueprint(webapi)
    app.register_blueprint(monitor_blueprint)

    # login_manager
    login_manager = LoginManager()
    login_manager.login_view = 'charts.now'
    login_manager.init_app(app)

    from .models import User

    @login_manager.user_loader
    def load_user(user_id):
        # since the user_id is just the primary key of our user table, use it in the query for the user
        return User.query.get(int(user_id))

    # form csrf
    csrf.init_app(app)

    # Scss
    assets = Environment(app)
    assets.versions = 'timestamp'
    assets.url_expire = True
    assets.manifest = 'file:/tmp/manifest.to-be-deployed'  # explict filename
    assets.cache = False
    assets.auto_build = True

    assets.url = app.static_url_path
    scss = Bundle('scss/__main__.scss',
                  filters='pyscss',
                  output='css/main.css',
                  depends=['scss/*.scss'])
    assets.register('scss_all', scss)

    assets.debug = False
    app.config['ASSETS_DEBUG'] = False

    with app.app_context():
        init_db_admin_config()

    toolbar = DebugToolbarExtension(app)
    return (app)
Example #8
0
 def init_app(self, app):
     env = Environment(app)
     env.url_expire = True
     env.register('css_app', css_app)
     env.register('js_app', js_app)
     env.manifest = 'cache' if not app.debug else False
     env.cache = not app.debug
     env.debug = app.debug
Example #9
0
def init_app(app):
    assets = Environment(app)
    assets.register("css_vendor", css_vendor)
    assets.register("js_vendor", js_vendor)
    assets.register("css_linkedlist", css_linkedlist)
    assets.manifest = 'cache' if not app.debug else False
    assets.cache = not app.debug
    assets.debug = app.debug
Example #10
0
def init_app(app):
    webassets = Environment(app)
    webassets.register('css_all', css_all)
    # webassets.register('js_quote', js_quote)
    # webassets.register('js_main', js_customer)
    webassets.manifest = 'cache' if not app.debug else False
    webassets.cache = not app.debug
    webassets.debug = app.debug
def init_app(app):
    webassets = Environment(app)
    webassets.url = app.static_url_path
    webassets.register('js_lodjers', js_lodjers)
    webassets.register('js_mixpanel', js_mixpanel)
    webassets.register('css_lodjers', css_lodjers)
    webassets.manifest = 'cache' if not app.debug else False
    webassets.cache = not app.debug
    webassets.debug = app.debug
Example #12
0
def create_app():
    """ Create a HubGrep Flask-app. """
    app = Flask(__name__, static_url_path="/static", static_folder="static")
    assets = Environment(app)

    # disable cache, because that breaks
    # prod build for some reason.
    # maybe add to the flask config?
    assets.cache = False
    assets.manifest = False

    @app.after_request
    def add_gnu_tp_header(response):
        # www.gnuterrypratchett.com
        response.headers.add("X-Clacks-Overhead", "GNU Terry Pratchett")
        return response

    config_mapping = {
        constants.APP_ENV_BUILD: "hubgrep.config.BuildConfig",
        constants.APP_ENV_DEVELOPMENT: "hubgrep.config.DevelopmentConfig",
        constants.APP_ENV_PRODUCTION: "hubgrep.config.ProductionConfig",
        constants.APP_ENV_TESTING: "hubgrep.config.TestingConfig",
    }
    app_env = os.environ.get("APP_ENV", constants.APP_ENV_DEVELOPMENT)
    print(f"starting in {app_env} config")
    app.config.from_object(config_mapping[app_env])

    if app.config['WATCH_SCSS']:
        app.wsgi_app = SassMiddleware(app.wsgi_app, app.config["SASS_MANIFEST"])

    babel = Babel(app)

    init_logging(loglevel=app.config["LOGLEVEL"])

    db.init_app(app)
    migrate.init_app(app, db=db)

    from hubgrep.frontend_blueprint import frontend
    from hubgrep.cli_blueprint import cli_bp

    app.register_blueprint(frontend)
    app.register_blueprint(cli_bp)

    @babel.localeselector
    def get_locale():
        lang = request.accept_languages.best_match(app.config["LANGUAGES"].keys())
        return lang

    app.jinja_env.globals["get_locale"] = get_locale
    app.jinja_env.globals["constants"] = constants
    app.jinja_env.globals["timeago"] = timeago
    app.jinja_env.globals["datetime_now"] = datetime.datetime.now()
    app.jinja_env.trim_blocks = True
    app.jinja_env.lstrip_blocks = True

    return app
def init_app(app):
    """
    Initilize assets.
    :param app:
    """
    webassets = Environment(app)
    webassets.url = app.static_url_path
    webassets.register('css_all', css_all)
    webassets.manifest = 'cache' if not app.debug else False
    webassets.cache = not app.debug
    webassets.debug = app.debug
Example #14
0
def init_app(app):
    webassets = Environment(app)
    webassets.register('css_all', css_all)
    webassets.register('js_angular', js_angular)
    webassets.register('js_foundation', js_foundation)
    webassets.register('js_vendor', js_vendor)
    webassets.register('js_d3', js_d3)
    webassets.register('js_main', js_main)
    webassets.manifest = 'cache' if not app.debug else False
    webassets.cache = not app.debug
    webassets.debug = app.debug
Example #15
0
def prepare(app):
    web_assets = Environment(app)

    web_assets.register('css_all', *prepare_css())
    web_assets.register('js_all', *prepare_js())

    is_debugging = app.debug
    web_assets.manifest = 'cache' if not is_debugging else False
    web_assets.cache = not is_debugging
    web_assets.debug = is_debugging

    return app
Example #16
0
def init_app(app):
    webassets = Environment(app)
    webassets.register('css_cover', css_cover)
    webassets.register('css_auth', css_auth)
    webassets.register('css_fancybox', css_fancybox)
    webassets.register('css_all', css_base)
    webassets.register('js_comment', js_comment)
    webassets.register('js_all', js_base)
    webassets.register('js_fancybox', js_fancybox)
    webassets.manifest = 'cache' if not app.debug else False
    webassets.cache = not app.debug
    webassets.debug = app.debug
Example #17
0
def init_app(app, allow_auto_build=True):
    assets = Environment(app)
    # on google app engine put manifest file beside code
    # static folders are stored separately and there is no access to them in production
    folder = os.path.abspath(os.path.dirname(__file__)) if "APPENGINE_RUNTIME" in os.environ else ""
    assets.directory = os.path.join(app.static_folder, "compressed")
    assets.manifest = "json:{}/manifest.json".format(assets.directory)
    assets.url = app.static_url_path + "/compressed"
    compress = not app.debug  # and False
    assets.debug = not compress
    assets.auto_build = compress and allow_auto_build
    assets.register('js', Bundle(*JS, filters='yui_js', output='script.%(version)s.js'))
    assets.register('css', Bundle(*CSS, filters='yui_css', output='style.%(version)s.css'))
Example #18
0
def init_assets(app):
    with app.app_context():
        env = Environment(app)
        env.load_path = [path.join(path.dirname(__file__), '..', 'static')]

        # App Enging doesn't support automatic building
        # so only auto build if in debug mode
        env.auto_build = app.debug
        app.logger.info('auto_build set to {}'.format(
            env.auto_build
        ))

        # Make sure this file is shipped
        env.manifest = 'file'

        bundles = {
        
            'cv_js': Bundle(
                'js/common.js',
                'js/cv.js',
                output='gen/cv.js'),
        
            'cv_css': Bundle(
                'css/bootstrap-extensions.css',
                'css/common.css',
                'css/cv.css',
                output='gen/cv.css'),
        
            'aboutMe_js': Bundle(
                'js/common.js',
                output='gen/aboutMe.js'),
        
            'aboutMe_css': Bundle(
                'css/bootstrap-extensions.css',
                'css/common.css',
                'css/aboutMe.css',
                output='gen/aboutMe.css'),

            'index_js': Bundle(
                'js/common.js',
                output='gen/index.js'),
        
            'index_css': Bundle(
                'css/bootstrap-extensions.css',
                'css/common.css',
                'css/index.css',
                output='gen/index.css'),
        }
         
        env.register(bundles)
        return bundles
Example #19
0
def init_app(app):
    webassets = Environment(app)

    webassets.register('css_bootstrap', css_bootstrap)
    #webassets.register('css_local', css_local)

    #webassets.register('js_local', js_local)
    #webassets.register('js_jquery', js_jquery)
    webassets.register('js_bootstrap', js_bootstrap)
    #webassets.register('js_angular', js_angular)
    #webassets.register('js_coffee', js_coffee)

    webassets.manifest = 'cache' if not app.debug else False
    webassets.cache = not app.debug
    webassets.debug = app.debug
Example #20
0
def init_app(app):
    debug = app.debug
    webassets = Environment(app)
    # add foundation sass files to sass compiler paths
    webassets.config['SASS_LOAD_PATHS'] = ["../bower_components/foundation/scss/",
                                           "."]

    webassets.register('css_kb', css_kb)
    webassets.register('shivs', shivs)
    webassets.register('js_vendor', js_vendor)
    webassets.register('js_main', js_main)


    webassets.manifest = 'cache' if not debug else False
    webassets.cache = not debug
    webassets.debug = debug
Example #21
0
def init(app=None):
    app = app or Flask(__name__)
    bundles = []

    with app.app_context():
        env = Environment(app)
        env.load_path = [ASSETS_DIR]
        env.set_directory(STATIC_DIR)
        # App Engine doesn't support automatic rebuilding.
        env.auto_build = False
        # This file needs to be shipped with your code.
        env.manifest = 'file'
        bundles.extend(_add_base_bundle(env))
        bundles.extend(_add_home_bundle(env))
        bundles.extend(_add_ajaxy_bundle(env))

    return bundles
Example #22
0
def init(app=None):
    app = app or Flask(__name__)

    with app.app_context():
        env = Environment(app)
        env.load_path = [path.join(path.dirname(__file__), 'assets')]
        env.url = app.static_url_path
        env.directory = app.static_folder
        env.auto_build = app.debug
        env.manifest = 'file'

        scss = Bundle('stylesheet.scss',
                      filters='pyscss',
                      output='stylesheet.css')
        env.register('scss_all', scss)

        bundles = [scss]
        return bundles
Example #23
0
def init_app(app):
    """
    Initilize assets.
    :param app:
    """
    if app.debug:
        webassets = Environment(app)
        webassets.url = app.static_url_path
        webassets.register('css_all', css_all)
        webassets.manifest = False
        webassets.cache = False
        webassets.debug = False
        webassets.cache = not app.debug
        webassets.debug = app.debug
        log = logging.getLogger('webassets')
        log.addHandler(logging.StreamHandler())
        log.setLevel(logging.DEBUG)
        cmdenv = CommandLineEnvironment(webassets, log)
        cmdenv.build()
Example #24
0
def init(app=None):
    app = app or Flask(__name__)
    with app.app_context():
        env = Environment(app)
        env.load_path = [path.join(path.dirname(__file__), 'assets')]
        # env.append_path('assets')
        # env.set_directory(env_directory)
        # App Engine doesn't support automatic rebuilding.
        env.auto_build = False
        # This file needs to be shipped with your code.
        env.manifest = 'file'

        css = Bundle("main.css", filters="cssmin", output="main.css")
        env.register('css', css)

        js = Bundle("main.js", filters="jsmin", output="main.js")
        env.register('js', js)

        bundles = [css, js]
        return bundles
Example #25
0
def init(app=None):
    app = app or Flask(__name__)
    with app.app_context():
        assets = Environment(app)
        assets.auto_build = False
        assets.manifest = 'file'

        css = Bundle(
            'css/style.css',
            'js/libs/prettify/*.css',
            filters='cssmin', output='css/styles.min.css',
        )
        assets.register('css', css)

        js = Bundle(
            'js/app.js',
            'js/libs/prettify/*.js',
            'js/libs/jquery-1.7.1.min.js',
            filters='jsmin', output='js/main.min.js'
        )
        assets.register('js', js)

        bundles = [css, js]
        return bundles
Example #26
0
from spaceship import app
from flask_assets import Environment, Bundle

assets = Environment(app)

if app.config['IN_BUILD']:
    assets.auto_build = False
    assets.cache = False
    assets.manifest = 'file'

js = Bundle(
  'edit.js',
  'copy.js',
  'prevent-invalid-form-submit.js',
  'wip-overlay.js',
  'add_csrf_token.js',
  output='gen/all.%(version)s.js')
assets.register('js_all', js)

css = Bundle('spaceship.css',
             'wip-overlay.css',
             output='gen/all.%(version)s.css')
assets.register('css_all', css)
Example #27
0
def setup_assets(app):
    assets = Environment(app)
    assets.url_expire = True

    assets.cache = False
    assets.manifest = False
    assets.load_path = [
        os.path.join(app.config['PROJECT_ROOT'], 'static'),
        os.path.join(app.config['PROJECT_ROOT'], 'bower_components')
    ]

    css_main = Bundle(
        'bootstrap/dist/css/bootstrap.min.css',
        'bootstrap-toggle/css/bootstrap-toggle.min.css',
        'awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css',
        'datatables/media/css/jquery.dataTables.min.css',
        'datatables/media/css/dataTables.bootstrap.min.css',
        'bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css',
        'clockpicker/dist/bootstrap-clockpicker.min.css',
        'eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css',  # NOQA
        'emojione/assets/css/emojione.min.css',
        'emojionearea/dist/emojionearea.min.css',
        'js/plugins/export/export.css',
        'main.css',
        # inspinia theme files
        'inspinia_v2.7.1/css/style.css',
        'inspinia_v2.7.1/css/animate.css',
        'inspinia_v2.7.1/font-awesome/css/font-awesome.min.css',
    )
    js_main = Bundle(
        'jquery/dist/jquery.min.js',
        'jquery-ui/jquery-ui.min.js',
        'bootstrap/dist/js/bootstrap.min.js',
        'bootstrap-toggle/js/bootstrap-toggle.min.js',
        'datatables/media/js/jquery.dataTables.min.js',
        'datatables/media/js/dataTables.bootstrap.min.js',
        'moment/min/moment-with-locales.min.js',
        'bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js',
        'clockpicker/dist/bootstrap-clockpicker.min.js',
        'eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js',  # NOQA
        'jquery-textcomplete/dist/jquery.textcomplete.min.js',
        'emojione/lib/js/emojione.min.js',
        'emojionearea/dist/emojionearea.min.js',
        # amcharts files
        'js/amcharts.js',
        'js/serial.js',
        'js/pie.js',
        'js/plugins/export/export.min.js',
        'js/themes/light.js',
        # amcharts libs for export
        'js/plugins/export/libs/pdfmake/pdfmake.min.js',
        'js/plugins/export/libs/pdfmake/vfs_fonts.js',
        'js/plugins/export/libs/jszip/jszip.min.js',
        'js/plugins/export/libs/fabric.js/fabric.min.js',
        'js/plugins/export/libs/FileSaver.js/FileSaver.min.js',
        'main.js',
    )

    js_bulletin_edit = Bundle(
        js_main,
        'bulletin-edit.js'
    )

    js_story_edit = Bundle(
        js_main,
        'story-edit.js'
    )

    css_landing = Bundle(
        'landing.css',
        'emojione/assets/css/emojione.min.css',
    )

    js_landing = Bundle(
        'jquery/dist/jquery.min.js',
        'hamburger.menu.js',
        'typed.js/lib/typed.min.js',
    )

    assets.register('css_main', css_main, output='dist/css/main.css')
    assets.register('js_main', js_main, output='dist/js/main.js')

    assets.register('js_bulletin_edit', js_bulletin_edit,
                    output='dist/js/bulletin-edit.js')

    assets.register('js_story_edit', js_story_edit,
                    output='dist/js/story-edit.js')

    assets.register('css_landing', css_landing, output='dist/css/landing.css')
    assets.register('js_landing', js_landing, output='dist/js/landing.js')
Example #28
0
def init_app(app):
    webassets = Environment(app)
    webassets.register('js_build', js_build)
    webassets.manifest = 'cache' if not app.debug else False
    webassets.cache = not app.debug
    webassets.debug = app.debug
Example #29
0

application = Flask(__name__,\
                    static_folder="platus/static/",\
                     template_folder="platus/templates/",
                    static_url_path="/static")
application.register_blueprint(web)
application.register_blueprint(api)

application.config.update(config.from_yaml("data/config.yaml"))

# Scss
assets = Environment(application)
assets.versions = 'timestamp'
assets.url_expire = True
assets.manifest = 'file:/tmp/manifest.to-be-deployed'  # explict filename
assets.cache = False
assets.auto_build = True

assets.url = application.static_url_path
scss = Bundle('scss/00_main.scss',
              filters='pyscss',
              output='css/main.css',
              depends=['scss/*.scss'])
assets.register('scss_all', scss)

assets.debug = False
application.config['ASSETS_DEBUG'] = False

# Set Logger
log_levels = {
FLATPAGES_AUTO_RELOAD = DEBUG
FLATPAGES_EXTENSION = '.md'
# LESS_BIN = os.path.join(SCRIPT_ROOT, '..', 'node_modules', 'less', 'bin', 'lessc')
LESS_LINE_NUMBERS = 'mediaquery'
FREEZER_DESTINATION = os.path.join(SITE_ROOT, '..', '..', 'build')
FLATPAGES_ROOT = os.path.join(SITE_ROOT, '..', '..', 'pages')

app = Flask(
    import_name='codingnotes',
    static_folder=os.path.join(SITE_ROOT, '..', '..', 'static'),
    template_folder=os.path.join(SITE_ROOT, '..', '..', 'templates'),
)

assets = Environment(app)
assets.debug = DEBUG
assets.manifest = None
assets.cache = None
freezer = Freezer(app)
pages_on_disk = FlatPages(app)

app.config.from_object(__name__)


def is_published(post_date):
    return utc.localize(datetime.utcnow()) >= utc.localize(datetime.combine(post_date, time(0, 0, 0)))
published_pages = sorted([p for p in pages_on_disk if is_published(p.meta.get('date', '2099-12-31'))], key=lambda p: p.meta['date'])


def get_latest_pages(limit=10):
    pages = published_pages if not request.args.get('preview') else pages_on_disk
    # Articles are pages with a publication date
Example #31
0
def compile_assets(app):
    assets = Environment(app)

    js = Bundle(
        'js/*.js',  # 'home_bp/js/*.js', 'admin_bp/js/*.js',
        filters='jsmin',
        output='gen/packed.js')
    css = Bundle('css/*.css',
                 'css/dash/*.css',
                 'home_bp/css/*.css',
                 'admin_bp/css/*.css',
                 'auth_bp/css/*.css',
                 'shopping_add_bp/css/*.css',
                 'shopping_view_bp/css/*.css',
                 filters='cssmin',
                 output='gen/packed.css')
    jquery = Bundle('js/jquery/jquery.min.js',
                    filters='jsmin',
                    output='gen/jquery.js')
    chosen_css = Bundle('css/chosen/chosen.min.css',
                        filters='cssmin',
                        output='gen/chosen.css')
    chosen_js = Bundle('js/chosen/chosen.jquery.js',
                       filters='jsmin',
                       output='gen/chosen.js')
    jrange_css = Bundle('css/jrange/jquery.range.css',
                        filters='cssmin',
                        output='gen/jrange.css')
    jrange_js = Bundle('js/jrange/jquery.range.js',
                       filters='jsmin',
                       output='gen/jrange.js')
    datatables_css = Bundle('css/datatables/jquery.dataTables.css',
                            'css/datatables/jquery.dataTables_OVERRIDES.css',
                            filters='cssmin',
                            output='gen/datatables.css')
    datatables_js = Bundle('js/datatables/jquery.dataTables.js',
                           filters='jsmin',
                           output='gen/datatables.js')
    daterangepicker_css = Bundle('css/daterangepicker/daterangepicker.css',
                                 filters='cssmin',
                                 output='gen/daterangepicker.css')
    daterangepicker_js = Bundle('js/daterangepicker/moment.min.js',
                                'js/daterangepicker/daterangepicker.js',
                                filters='jsmin',
                                output='gen/daterangepicker.js')
    flexdatalist_css = Bundle('css/flexdatalist/jquery.flexdatalist.css',
                              filters='cssmin',
                              output='gen/flexdatalist.css')
    flexdatalist_js = Bundle('js/flexdatalist/jquery.flexdatalist.js',
                             filters='jsmin',
                             output='gen/flexdatalist.js')
    jquerymodal_css = Bundle('css/jquerymodal/jquery.modal.min.css',
                             filters='cssmin',
                             output='gen/jquerymodal.css')
    jquerymodal_js = Bundle('js/jquerymodal/jquery.modal.min.js',
                            filters='jsmin',
                            output='gen/jquerymodal.js')

    plotly_js = Bundle('js/plotly/plotly.basic.js',
                       filters='jsmin',
                       output='gen/plotly.js')

    bundles = {
        'js_all': js,
        'css_all': css,
        'chosen_css': chosen_css,
        'chosen_js': chosen_js,
        'jrange_css': jrange_css,
        'jrange_js': jrange_js,
        'jquery': jquery,
        'datatables_js': datatables_js,
        'datatables_css': datatables_css,
        'daterangepicker_js': daterangepicker_js,
        'daterangepicker_css': daterangepicker_css,
        'flexdatalist_js': flexdatalist_js,
        'flexdatalist_css': flexdatalist_css,
        'jquerymodal_js': jquerymodal_js,
        'jquerymodal_css': jquerymodal_css,
        'plotly_js': plotly_js,
    }

    # selinux prevents flask-assets to dynamically build/access cached files
    if app.config['DISABLE_CACHE']:
        assets.cache = False
        assets.manifest = False

    assets.register(bundles)
    # assets.register('css_all', css)
    return assets
Example #32
0
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
FLATPAGES_AUTO_RELOAD = DEBUG
FLATPAGES_EXTENSION = '.md'
# LESS_BIN = os.path.join(SCRIPT_ROOT, '..', 'node_modules', 'less', 'bin', 'lessc')
LESS_LINE_NUMBERS = 'mediaquery'
FREEZER_DESTINATION = os.path.join(SITE_ROOT, '..', '..', 'build')
FLATPAGES_ROOT = os.path.join(SITE_ROOT, '..', '..', 'pages')

app = Flask(
    import_name='codingnotes',
    static_folder=os.path.join(SITE_ROOT, '..', '..', 'static'),
    template_folder=os.path.join(SITE_ROOT, '..', '..', 'templates'),
)

assets = Environment(app)
assets.manifest = False
assets.cache = False
if DEBUG:
    assets.manifest = False
    assets.cache = None
freezer = Freezer(app)
pages_on_disk = FlatPages(app)

app.config.from_object(__name__)


def is_published(post_date):
    return utc.localize(datetime.utcnow()) >= utc.localize(datetime.combine(post_date, time(0, 0, 0)))
published_pages = sorted([p for p in pages_on_disk if is_published(p.meta.get('date', '2099-12-31'))], key=lambda p: p.meta['date'])

Example #33
0
    app.config["FLASK_ASSETS_USE_S3"] = False
    app.config["ASSETS_DEBUG"] = True
    app.config["FLASKS3_ACTIVE"] = False

s3 = FlaskS3(app)

css_assets = Bundle(
    "normalize.css",
    "skeleton.css",
    "custom.css",
    filters="cssmin",
    output="packed.min.%(version)s.css",
)

assets = Environment(app)
assets.manifest = "json"
assets.register("css_all", css_assets)

if not app.config["ASSETS_DEBUG"]:
    css = FileHunk(css_assets.resolve_output())
    app.jinja_env.globals["css_assets_built"] = css.data()

db_client = DynamoDBClient(app.config.get("DYNAMODB_TABLE"))


def initialise_sentry():
    global sentry_initialised
    if os.environ.get("SENTRY_DSN", "") and not sentry_initialised:
        sentry_sdk.init(
            os.environ.get("SENTRY_DSN"),
            integrations=[
Example #34
0
import os
from flask_assets import Bundle, Environment
from . import app

# Assets
webassets = Environment(app)
webassets.load_path = [
    os.path.join(os.path.dirname(__file__), "static"),
    os.path.join(os.path.dirname(__file__), "bower_components")
]
webassets.manifest = 'cache' if not app.debug else False
webassets.cache = not app.debug
webassets.debug = True  # app.debug

js_main = Bundle("js/src/main.js", output="js/main.js")

css_main = Bundle("css/src/styles.css", output="css/main.css")

js_libs = Bundle("jquery/dist/jquery.min.js",
                 "semantic-ui/dist/semantic.min.js",
                 output="js/libs.js")

css_libs = Bundle("font-awesome/web-fonts-with-css/css/fontawesome.min.css",
                  "semantic-ui/dist/semantic.min.css",
                  output="css/libs.css")

webassets.register('js_main', js_main)
webassets.register('js_libs', js_libs)
webassets.register('css_main', css_main)
webassets.register('css_libs', css_libs)
Example #35
0
"""Asset creation pipeline"""

from slm_histviz import app
from flask_assets import Environment, Bundle
from webassets.filter import get_filter, register_filter

from webassets_react import React
register_filter(React)

# app.config.update(
#     BABEL_BIN='./node_modules/.bin/babel'
# )

assets = Environment(app)
assets.manifest = None
assets.cache = False

# babel filtering
# from webassets_babel import BabelFilter
# register_filter(BabelFilter)

babel = get_filter('babel', presets='es2015')

# explicitly-declared imports from bower, as there's stuff in there that we definitely don't want or need
# these files are just normal js; they don't need transpiling
bower_js_paths = [
    "bower_components/d3/d3.min.js",
    "bower_components/d3-timeline/src/d3-timeline.js",
    "bower_components/d3pie/d3pie/d3pie.min.js",
    "bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js",
    "bower_components/moment/min/moment-with-locales.min.js",
def create_app(config_name=None):
    csp_policy = copy.deepcopy(CSP_POLICY)
    app = Flask(__name__)

    app_config = f'config.{config_name or os.environ.get("APP_SETTINGS", "Config")}'
    app.config.from_object(app_config)

    if Config.WTF_CSRF_ENABLED:
        Talisman(
            app,
            content_security_policy=csp_policy,
            content_security_policy_nonce_in=['script-src'],
            force_https=False,  # this is handled at the load balancer
            legacy_content_security_policy_header=True,
            strict_transport_security=True,
            strict_transport_security_max_age=ONE_YEAR_IN_SECONDS,
            referrer_policy=DEFAULT_REFERRER_POLICY,
            frame_options='SAMEORIGIN',
            frame_options_allow_from=None,
            session_cookie_secure=True,
            session_cookie_http_only=True)
    app.name = "response_operations_ui"

    CSRFProtect(app)

    # Load css and js assets
    assets = Environment(app)

    if app.config['DEBUG'] or app.config['TESTING']:
        assets.cache = False
        assets.manifest = None

    if not app.config['DEBUG']:
        app.wsgi_app = GCPLoadBalancer(app.wsgi_app)

    assets.url = app.static_url_path

    app.jinja_env.add_extension('jinja2.ext.do')

    app.register_blueprint(filter_blueprint)

    app.url_map.strict_slashes = False
    app.secret_key = app.config['RESPONSE_OPERATIONS_UI_SECRET']

    logger_initial_config(service_name='response-operations-ui', log_level=app.config['LOGGING_LEVEL'])
    logger = wrap_logger(logging.getLogger(__name__))
    logger.info('Logger created', log_level=app.config['LOGGING_LEVEL'])

    login_manager = LoginManager(app)
    login_manager.init_app(app)
    login_manager.login_view = "sign_in_bp.sign_in"

    @app.context_processor
    def inject_availability_message():

        redis_avail_msg = app.config['SESSION_REDIS']

        if len(redis_avail_msg.keys('AVAILABILITY_MESSAGE_RES_OPS')) == 1:
            return {
                "availability_message": redis_avail_msg.get('AVAILABILITY_MESSAGE_RES_OPS').decode('utf-8')
            }
        return {}

    @login_manager.user_loader
    def user_loader(user_id):
        username = session.get('username')
        return User(user_id, username)

    # wrap in the flask server side session manager and back it by redis
    app.config['SESSION_REDIS'] = redis.StrictRedis(host=app.config['REDIS_HOST'],
                                                    port=app.config['REDIS_PORT'],
                                                    db=app.config['REDIS_DB'])

    app.jinja_environment.lstrip_blocks = True

    if app.config['DEBUG'] or os.environ.get('JINJA_RELOAD'):
        app.jinja_env.auto_reload = True

    Session(app)

    setup_blueprints(app)

    return app
Example #37
0
def create_app(config_name=None):
    app = Flask(__name__)
    app.name = "response_operations_ui"

    app_config = f'config.{config_name or os.environ.get("APP_SETTINGS", "Config")}'
    app.config.from_object(app_config)

    # Load css and js assets
    assets = Environment(app)

    if app.config['DEBUG'] or app.config['TESTING']:
        assets.cache = False
        assets.manifest = None

    assets.url = app.static_url_path

    app.jinja_env.add_extension('jinja2.ext.do')

    app.register_blueprint(filter_blueprint)

    app.url_map.strict_slashes = False
    app.secret_key = app.config['RESPONSE_OPERATIONS_UI_SECRET']

    # Zipkin
    zipkin = Zipkin(app=app, sample_rate=app.config.get("ZIPKIN_SAMPLE_RATE"))
    requestsdefaulter.default_headers(zipkin.create_http_headers_for_new_span)

    logger_initial_config(service_name='response-operations-ui',
                          log_level=app.config['LOGGING_LEVEL'])
    logger = wrap_logger(logging.getLogger(__name__))
    logger.info('Logger created', log_level=app.config['LOGGING_LEVEL'])

    login_manager = LoginManager(app)
    login_manager.init_app(app)
    login_manager.login_view = "sign_in_bp.sign_in"

    @app.context_processor
    def inject_availability_message():

        redis_avail_msg = app.config['SESSION_REDIS']

        if len(redis_avail_msg.keys('AVAILABILITY_MESSAGE_RES_OPS')) == 1:
            return {
                "availability_message":
                redis_avail_msg.get('AVAILABILITY_MESSAGE_RES_OPS').decode(
                    'utf-8')
            }
        return {}

    @login_manager.user_loader
    def user_loader(user_id):
        return User(user_id)

    if cf.detected:
        with app.app_context():
            # If deploying in cloudfoundry set config to use cf redis instance
            logger.info(
                'Cloudfoundry detected, setting service configurations')
            service = cf.redis
            app.config['REDIS_HOST'] = service.credentials['host']
            app.config['REDIS_PORT'] = service.credentials['port']

    # wrap in the flask server side session manager and back it by redis
    app.config['SESSION_REDIS'] = redis.StrictRedis(
        host=app.config['REDIS_HOST'],
        port=app.config['REDIS_PORT'],
        db=app.config['REDIS_DB'])

    app.jinja_environment.lstrip_blocks = True

    if app.config['DEBUG'] or os.environ.get('JINJA_RELOAD'):
        app.jinja_env.auto_reload = True

    Session(app)

    setup_blueprints(app)

    return app
Example #38
0
def create_app(config_name=None):
    csp_policy = copy.deepcopy(CSP_POLICY)
    app = Flask(__name__)

    app_config = f'config.{config_name or os.environ.get("APP_SETTINGS", "Config")}'
    app.config.from_object(app_config)

    if Config.WTF_CSRF_ENABLED:
        Talisman(
            app,
            content_security_policy=csp_policy,
            content_security_policy_nonce_in=["script-src"],
            force_https=False,  # this is handled at the load balancer
            strict_transport_security=True,
            strict_transport_security_max_age=ONE_YEAR_IN_SECONDS,
            referrer_policy=DEFAULT_REFERRER_POLICY,
            frame_options="SAMEORIGIN",
            frame_options_allow_from=None,
            session_cookie_secure=True,
            session_cookie_http_only=True,
        )
    app.name = "response_operations_ui"

    csrf = CSRFProtect(app)

    # Load css and js assets
    assets = Environment(app)

    if app.config["DEBUG"] or app.config["TESTING"]:
        assets.cache = False
        assets.manifest = None

    if not app.config["DEBUG"]:
        app.wsgi_app = GCPLoadBalancer(app.wsgi_app)

    assets.url = app.static_url_path

    app.jinja_env.add_extension("jinja2.ext.do")
    app.jinja_env.globals["hasPermission"] = user_has_permission

    app.register_blueprint(filter_blueprint)

    app.url_map.strict_slashes = False
    app.secret_key = app.config["RESPONSE_OPERATIONS_UI_SECRET"]

    logger_initial_config(service_name="response-operations-ui",
                          log_level=app.config["LOGGING_LEVEL"])
    logger = wrap_logger(logging.getLogger(__name__))
    logger.info("Logger created", log_level=app.config["LOGGING_LEVEL"])

    login_manager = LoginManager(app)
    login_manager.init_app(app)
    login_manager.login_view = "sign_in_bp.sign_in"

    @app.errorhandler(CSRFError)
    def handle_csrf_error(e):
        flash("Your session timed out", category="info")
        return redirect(url_for("logout_bp.logout"))

    @app.before_request
    def before_request():

        session.permanent = True  # set session to use PERMANENT_SESSION_LIFETIME
        session.modified = True  # reset the session timer on every request
        try:
            csrf.protect()

        except Exception as e:
            if e.code == 400:
                logger.warning(e.description)
            logger.warning(e)

    @app.context_processor
    def inject_availability_message():

        redis_avail_msg = app.config["SESSION_REDIS"]

        if len(redis_avail_msg.keys("AVAILABILITY_MESSAGE_RES_OPS")) == 1:
            return {
                "availability_message":
                redis_avail_msg.get("AVAILABILITY_MESSAGE_RES_OPS").decode(
                    "utf-8")
            }
        return {}

    @login_manager.user_loader
    def user_loader(user_id):
        username = session.get("username")
        return User(user_id, username)

    # wrap in the flask server side session manager and back it by redis
    app.config["SESSION_REDIS"] = redis.StrictRedis(
        host=app.config["REDIS_HOST"],
        port=app.config["REDIS_PORT"],
        db=app.config["REDIS_DB"])

    app.jinja_environment.lstrip_blocks = True

    if app.config["DEBUG"] or os.environ.get("JINJA_RELOAD"):
        app.jinja_env.auto_reload = True

    Session(app)

    setup_blueprints(app)

    return app