Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
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()
Ejemplo n.º 6
0
def init_app(app):
    webassets = Environment(app)
    webassets.register('css_vendor', css_vendor)
    webassets.register('css_plugins', css_plugins)
    webassets.register('css_app', css_app)
    webassets.register('js_vendor', js_vendor)
    webassets.register('js_plugins', js_plugins)
    webassets.register('js_main', js_main)
    webassets.manifest = 'cache' if not app.debug else False
    webassets.cache = not app.debug
    webassets.debug = app.debug
def register_assets(app):
    assets = Environment(app)
    assets.debug = app.debug
    assets.auto_build = True
    assets.url = app.static_url_path

    css_all = Bundle(*CSS_ASSETS, filters='cssmin', output='css/bundle.min.css')

    assets.register('css_all', css_all)
    app.logger.info("Registered assets...")
    return assets
Ejemplo n.º 8
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
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
Ejemplo n.º 10
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
Ejemplo n.º 11
0
def initialize_scss(app: Flask):
    """
    https://stackoverflow.com/questions/48402360/cant-generate-all-css-file-from-sass-files-with-flask-assets
    https://github.com/miracle2k/flask-assets
    https://flask-assets.readthedocs.io/en/latest/
    """
    assets = Environment(app)
    assets.url = app.static_url_path
    assets.debug = True

    scsss = Bundle("./scss/site.scss", filters="pyscss", output="gen/all.css")
    assets.register("scss_all", scsss)
Ejemplo n.º 12
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
Ejemplo n.º 13
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'))
Ejemplo n.º 14
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
Ejemplo n.º 15
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
Ejemplo n.º 16
0
def register_assets(app):
    assets = Environment(app)
    assets.debug = app.debug
    assets.auto_build = True
    assets.url = app.static_url_path

    css_blog = Bundle(*BLOG_ASSETS, filters='cssmin', output='css/blog.min.css')
    css_welcome = Bundle(*INDEX_ASSETS, filters='cssmin', output='css/welcome.min.css')

    js_all = Bundle(*JS_ASSETS, filters='rjsmin', output='js/all.min.js')

    assets.register('css_blog', css_blog)
    assets.register('css_welcome', css_welcome)
    assets.register('js_all', js_all)
    app.logger.info("Registered assets...")

    return assets
Ejemplo n.º 17
0
def init_app(app):
    webassets = Environment(app)
    webassets.debug = app.debug
Ejemplo n.º 18
0
oauth.register(
    name="osu",
    client_id=os.getenv("OAUTH_CLIENT_ID"),
    client_secret=os.getenv("OAUTH_CLIENT_SECRET"),
    access_token_url="https://osu.ppy.sh/oauth/token",
    access_token_params=None,
    authorize_url="https://osu.ppy.sh/oauth/authorize",
    authorize_params=None,
    api_base_url="https://osu.ppy.sh/api/v2/",
    client_kwargs={"scope": "identify public"},
)

########## Assets

assets = Environment(app)
assets.debug = True
css = Bundle("src/main.css", output="dist/main.css", filters="postcss")
js = Bundle("src/*.js", output="dist/main.js")
assets.register("css", css)
assets.register("js", js)
css.build()
js.build()

########## Routes


@app.route("/")
def index():
    tournaments = Tournament.query.all()
    return render_template("index.html", tournaments=tournaments)
Ejemplo n.º 19
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(debug_blueprint)
    app.register_blueprint(webapi)
    app.register_blueprint(monitor_blueprint)

    # form csrf
    csrf.init_app(app)

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

    # 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)
Ejemplo n.º 20
0
def create_app(config_filename="config"):
    """Flask application factory.

    This is the flask application factory for this project. It loads the
    other submodules used to runs the collectives website. It also creates
    the blueprins and init apps.

    :param config_filename: name of the application config file.
    :type config_filename: string

    :return: A flask application for collectives
    :rtype: :py:class:`flask.Flask`
    """
    app = Flask(__name__, instance_relative_config=True)
    app.wsgi_app = ReverseProxied(app.wsgi_app)

    # Config options - Make sure you created a 'config.py' file.
    app.config.from_object(config_filename)
    app.config.from_pyfile("config.py")
    # To get one variable, tape app.config['MY_VARIABLE']

    fileConfig(app.config["LOGGING_CONFIGURATION"],
               disable_existing_loggers=False)

    # Initialize plugins
    models.db.init_app(app)
    auth.login_manager.init_app(app)  # app is a Flask object
    api.marshmallow.init_app(app)
    profile.images.init_app(app)
    extranet.api.init_app(app)
    payline.api.init_app(app)

    app.context_processor(jinja.helpers_processor)

    _migrate = Migrate(app, models.db)

    with app.app_context():
        # Initialize asset compilation
        assets = Environment(app)

        filters = "libsass"
        if app.config["ENV"] == "production":
            filters = "libsass, cssmin"
            assets.auto_build = False
            assets.debug = False
        scss = Bundle(
            "css/all.scss",
            filters=filters,
            depends=("/static/css/**/*.scss"),
            output="dist/css/all.css",
        )

        assets.register("scss_all", scss)
        scss.build()

        # Register blueprints
        app.register_blueprint(root.blueprint)
        app.register_blueprint(profile.blueprint)
        app.register_blueprint(api.blueprint)
        app.register_blueprint(administration.blueprint)
        app.register_blueprint(auth.blueprint)
        app.register_blueprint(event.blueprint)
        app.register_blueprint(payment.blueprint)
        app.register_blueprint(technician.blueprint)
        app.register_blueprint(activity_supervison.blueprint)

        # Error handling
        app.register_error_handler(werkzeug.exceptions.NotFound,
                                   error.not_found)
        app.register_error_handler(werkzeug.exceptions.InternalServerError,
                                   error.server_error)

        forms.configure_forms(app)
        forms.csrf.init_app(app)
        # Initialize DB
        # models.db.create_all()

        populate_db(app)

        if app.config["STATISTICS_ENABLED"]:
            Statistics(
                app,
                models.db,
                models.Request,
                access.technician_required_f,
                disable_f=statistics.disable_f,
            )

        return app
Ejemplo n.º 21
0
def create_app(config_name):
    global db
    global login
    global migrate
    global bootstrap
    global socketio
    global mail

    from .main import REDIS_URI

    app = Flask(__name__, instance_relative_config=True)
    app.config.from_object(app_config[config_name])

    db.init_app(app)
    bootstrap.init_app(app)
    migrate.init_app(app, db)
    mail.init_app(app)
    socketio = SocketIO(app, message_queue=REDIS_URI)
    login.init_app(app)
    login.login_view = "home.index"
    login.login_message = {
        'type': 'notice',
        'title': 'Login required',
        'text': 'You must be logged in to access this page.',
        'icon': 'fas fa-sign-in-alt'
    }

    assets = Environment(app)
    assets.url = app.static_url_path
    assets.debug = True

    scss = Bundle('scss/selectable.scss',
                  filters='pyscss',
                  output='css/selectable.css')
    assets.register('scss_all', scss)

    from src import models

    from .home import home as home_blueprint
    app.register_blueprint(home_blueprint)

    from .auth import auth as auth_blueprint
    app.register_blueprint(auth_blueprint)

    from .admin import admin as admin_blueprint
    app.register_blueprint(admin_blueprint)

    from .printer import printer as printer_blueprint
    app.register_blueprint(printer_blueprint)

    from .home.views import add_login_form

    @app.errorhandler(403)
    @add_login_form
    def page_not_found(*args, **kwargs):
        login_form = kwargs['form'] if kwargs['form'] else None
        return render_template('errors/403.html', login_form=login_form), 403

    @app.errorhandler(404)
    @add_login_form
    def page_not_found(*args, **kwargs):
        login_form = kwargs['form'] if kwargs['form'] else None
        return render_template('errors/404.html', login_form=login_form), 404

    @app.errorhandler(500)
    @add_login_form
    def page_not_found(*args, **kwargs):
        login_form = kwargs['form'] if kwargs['form'] else None
        return render_template('errors/500.html', login_form=login_form), 500

    return app
Ejemplo n.º 22
0
from flask_assets import Environment, Bundle
from flask_frozen import Freezer


SITE_ROOT = os.path.dirname(os.path.realpath(__file__))

app = Flask(
    import_name=__name__,
    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
assets.debug = True

freezer = Freezer(app)

app.config.update(
    DEBUG=True,
    FREEZER_DESTINATION=os.path.join(SITE_ROOT, '..', '..', 'build')
)


assets.register('js_all', Bundle(
    'js/website.js',
    filters='jsmin',
    output='build/website.js'
))
assets.register('css_all', Bundle(
Ejemplo n.º 23
0
# Migrations for changes to the db.
db = SQLAlchemy(app)
migrate = Migrate(app, db)

# Initiate Flask Login to handle
# authentication and redirects for
# Un logged in users.
login = LoginManager(app)
login.login_view = 'index'

# Flask Assets handles bundling our
# CSS and JavaScript files into a
# single minified file when we are
# not in development mode.
assets = Environment(app)
assets.debug = Config.DEBUG
assets.cache = not Config.DEBUG
assets.url_expire = Config.DEBUG

# Database Models, and Routes must
# be imported after the app object
# is defined.
from app import models, routes

# Define our bundlels for Flask Assets.
# These will be used by our base.html
# template.
routes.make_asset_bundles()

# Run our Flask app when this file is
# invoked directly. This happens when
Ejemplo n.º 24
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.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
Ejemplo n.º 25
0
# set up authentication
bcrypt = Bcrypt(application)

# bundle js and css code
assets = Environment(application)

js = Bundle('js/core/*', filters='rjsmin', output='js/core/mgtrk-core.min.js')
assets.register('core-js', js)

css = Bundle('css/core/*',
             filters='cssmin',
             output='css/core/mgtrk-core.min.css')
assets.register('core-css', css)

# switch off bundling if app is in debug mode
assets.debug = application.config['FLASK_DEBUG']

# set up database
db = SQLAlchemy()
db.init_app(application)

# import blueprint with routes after application is set up
from megatrack.views import megatrack
application.register_blueprint(megatrack, url_prefix='/megatrack')

from megatrack.lesion.views import lesion
application.register_blueprint(lesion, url_prefix='/megatrack')

from megatrack.admin.views import admin
application.register_blueprint(admin, url_prefix='/megatrack')
pages = FlatPages(app)

manager = Manager(app)

# Scss
assets = Environment(app)
assets.url_expire = True
assets.auto_build = True
assets.append_path('sni/assets')
assets.cache = 'sni/assets/.webassets-cache'

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

cache = Cache(app, config={'CACHE_TYPE': 'simple'})

if not app.debug:
    import logging
    from logging.handlers import RotatingFileHandler
    file_handler = RotatingFileHandler('tmp/snilog.csv',
                                       'a',
                                       10 * 1024 * 1024,
                                       100)

    file_handler.setFormatter(logging.Formatter('%(asctime)s, %(levelname)s, %(message)s'))
    app.logger.setLevel(logging.INFO)
    file_handler.setLevel(logging.INFO)
Ejemplo n.º 27
0
from flask import Flask
from flask import render_template
from flask import request
from flask_assets import Environment, Bundle

import analyze
import constants
import teams

app = Flask(__name__)

assets = Environment(app)
assets.debug = False
less = Bundle("styles/styles.less", filters="less", output="gen/styles.css")
assets.register("less_all", less)
js = Bundle("js/index.js", output="gen/scripts.js")
assets.register("js_all", js)


@app.route("/")
def serve():
    teams_by_abbr = teams.teams_by_abbr()
    teams_by_division = {
        "Pacific": [],
        "Central": [],
        "Metropolitan": [],
        "Atlantic": []
    }
    for abbr, team in teams_by_abbr.items():
        teams_by_division[team.division].append(team)
Ejemplo n.º 28
0
js = Bundle('js/helper.js',
            'js/add-products.js',
            'js/lettering.js',
            'js/front-page.js',
            'js/search.js',
            'js/ajax.js',
            'js/setup.js',
            output='gen/main.js')
css = Bundle('css/style.css',
             'css/lettering.css',
             'css/vendor/pagination.css',
             output='gen/style.css')

assets = Environment(application)

assets.debug = CONFIG.ASSET_DEBUG

assets.register('main_js', js)
assets.register('main_css', css)


class User(UserMixin):
    pass


@login_manager.user_loader
def user_loader(username):
    if username not in CONFIG.USERS:
        return
    user = User()
    user.id = username
Ejemplo n.º 29
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
Ejemplo n.º 30
0
                }
            }
        }
    }
    message.extra_headers = {
        'X-SMTPAPI': json.dumps(extra_headers)
    }
    original_send(message)
app.extensions.get('mail').send = send_email_with_sendgrid


# setup assets
from flask_assets import Environment, Bundle
assets = Environment(app)
assets.url_expire = False
assets.debug      = app.debug
# source files
assets.load_path  = ['%s/static' % app.config.root_path]

from webassets.filter.pyscss import PyScss

assets.register('css',
    Bundle(
      'font-awesome-4.7.0/css/font-awesome.min.css',
      'chosen/chosen.min.css',
      Bundle(
        'resources/css/style.scss',
        'resources/css/bill-progress.scss',
        'resources/css/bootstrap-sortable.css',
        filters=PyScss(load_paths=assets.load_path),
        output='stylesheets/styles.%(version)s.css'),
Ejemplo n.º 31
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)
Ejemplo n.º 32
0
from flask import Flask, request, render_template, send_file, jsonify
from flask_assets import Environment, Bundle

from plotter import generate_plot
from statistics_server import paths

app = Flask(__name__)
assets = Environment(app)

js = Bundle('js/main.js', filters="jsmin", output="bundle.js")
css = Bundle('css/main.css', filters="cssmin", output="bundle.css")
assets.register('javascript', js)
assets.register('stylesheets', css)
assets.url_expire = True
assets.debug = app.debug


@app.route("/get_plot")
def get_plot():
    pids = []
    start = None
    end = None

    if request.args.has_key('pid'):
        rawpid = request.args.get('pid')

        if rawpid.find(','):
            pids = rawpid.split(',')
        else:
            pids = [rawpid]
Ejemplo n.º 33
0
 def configure_webassets(self):
     assets = Environment(self.app)
     assets.init_app(self.app)
     assets.debug = self.debug