示例#1
0
def init(app):
    """
    Bundle projects assets

    :type app: flask.Flask
    """
    assets = Environment(app)
    assets.auto_build = app.config.get('ASSETS_AUTO_BUILD', True)
    files_to_watch = []

    if 'COLLECT_STATIC_ROOT' in app.config:
        assets.cache = app.config['COLLECT_STATIC_ROOT']
        collect = Collect()
        collect.init_app(app)
        collect.collect()
        app.static_folder = app.config['COLLECT_STATIC_ROOT']

    if 'JS_ASSETS' in app.config and len(app.config['JS_ASSETS']) > 0:
        files_to_watch += [
            os.path.join(app.static_folder, js_file)
            for js_file in app.config['JS_ASSETS']
        ]

        js = Bundle(*app.config['JS_ASSETS'],
                    output=app.config['JS_ASSETS_OUTPUT'],
                    filters=app.config['JS_ASSETS_FILTERS'])
        assets.register('js_all', js)

    if 'CSS_ASSETS' in app.config and len(app.config['CSS_ASSETS']) > 0:
        files_to_watch += [
            os.path.join(app.static_folder, css_file)
            for css_file in app.config['CSS_ASSETS']
        ]

        css = Bundle(*app.config['CSS_ASSETS'],
                     output=app.config['CSS_ASSETS_OUTPUT'],
                     filters=app.config['CSS_ASSETS_FILTERS'])
        assets.register('css_all', css)

    app.assets = assets
    app._base_files_to_watch = files_to_watch
示例#2
0
# -*- coding: utf-8 -*-
from flask.ext.script import Manager
from flask.ext.collect import Collect

from app import app, db, models

manager = Manager(app)
collect = Collect()
collect.init_app(app)
collect.init_script(manager)


@manager.command
def initialize_database():
    "Drop current database and initialize a new one"
    db.drop_all()
    db.create_all()
    admin = models.Admin(app.config['USERNAME'], app.config['PASSWORD'])
    db.session.add(admin)
    db.session.commit()

    print "Database initialized"


@manager.command
def add_test_user():
    user = models.SignUp("Test User", "*****@*****.**", "Aalto-yliopisto TiK", "Vahan.", False, False, True)
    db.session.add(user)
    db.session.commit()

    print "User added"
示例#3
0
 def run(self):
     collect = Collect()
     collect.init_app(application)
     collect.init_script(manager)
     collect.collect(verbose=True)
示例#4
0
# coding: utf-8

import os

from flask import Flask
from flask.ext.collect import Collect

from conf.settings import STATIC_ROOT

project_dir = os.path.normpath(os.path.dirname(os.path.dirname(__file__)))
static_root = os.path.join(project_dir, STATIC_ROOT)
app = Flask(__name__, static_folder=None, static_url_path='static')

# set configuration
app.config.from_object('conf.settings')
app.secret_key = app.config['SECRET_KEY']
app.debug = app.config['DEBUG']
app.project_dir = project_dir

# set collect
manager_static = Collect()
manager_static.init_app(app)