Exemplo n.º 1
1
def init_app(app):
    db.init_app(app)
    cache.init_app(app)
    debug_toolbar.init_app(app)
    app.template_folder = os.path.join(os.path.dirname(__file__), 'templates/')

    migrate = Migrate(app, db)

    # Import and register the different asset bundles
    assets_env = Environment(app)
    assets_env.load_path = [os.path.join(os.path.dirname(__file__), 'static')]
    assets_env.directory = os.path.join(os.path.dirname(__file__), 'static')
    assets_env.url = '/admin/static/'
    # assets_env.register('js_all', js)
    print("directory ", assets_env.directory, os.path.join(os.path.dirname(__file__), 'static/'))
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in list(assets_loader.load_bundles().items()):
        assets_env.register(name, bundle)

    # Setup user handling
    from silverflask.models import User

    user_adapter = SQLAlchemyAdapter(db, User)
    user_manager = UserManager(user_adapter)
    user_manager.init_app(app)

    ###
    #  SILVERFLASK
    ###

    upload_path = os.path.join(app.instance_path, app.config["SILVERFLASK_UPLOAD_PATH"])
    app.config["SILVERFLASK_ABSOLUTE_UPLOAD_PATH"] = upload_path
    app.storage_backend = LocalFileStorageBackend(upload_path)


    from silverflask.controllers.page_controller import SiteTreeController
    app.register_blueprint(SiteTreeController.create_blueprint(app))

    from silverflask.core.dev_controller import DevController
    app.register_blueprint(DevController.create_blueprint(app))

    from silverflask.controllers.cms_controller import CMSController, PagesCMSController, FilesCMSController, \
        DataObjectCMSController

    app.register_blueprint(CMSController.create_blueprint(app))
    app.register_blueprint(DataObjectCMSController.create_blueprint(app))
    app.register_blueprint(PagesCMSController.create_blueprint(app))
    app.register_blueprint(FilesCMSController.create_blueprint(app))
    from silverflask.controllers.security_controller import SecurityController
    app.register_blueprint(SecurityController.create_blueprint(app))


    from silverflask.core.theme import init_themes
    init_themes(app)

    from silverflask.controllers.main import setup_processors, init_blueprint
    from silverflask.controllers.cms import bp as cms_bp

    setup_processors(app)
    main = init_blueprint(app)
    app.register_blueprint(main)
    app.register_blueprint(cms_bp, url_prefix='/admin')


    # for rule in app.url_map.iter_rules():
    #     print(rule)

    return app
def load_assets(app):
    Bower(app)
    env = Environment(app)
    app.config['COMPASS_CONFIG'] = {'sourcemap': True}
    env.load_path = [
        os.path.join(os.path.dirname(__file__), 'bower_components'),
        os.path.join(os.path.dirname(__file__), 'styles'),
    ]
    # env.cache = False
    # env.manifest = False

    env.register(
        'js_all',
        Bundle(
            'jquery/dist/jquery.min.js',
            'bootstrap-sass/assets/javascripts/bootstrap.min.js',
            output='js_all.js'
        )
    )

    env.register(
        'css_all',
        Bundle(
            'all.scss',
            depends='*.scss',
            filters='compass',
            output='css_all.css'
        )
    )
Exemplo n.º 3
0
    def __init__(self, *args, **kwargs):
        super(Application, self).__init__(__name__)
        self.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
        self.config['DEBUG'] = True

        # self.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
        self.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
        db.init_app(self)
        self.register_blueprint(api)
        self.register_blueprint(user)
        self.register_blueprint(others)

        assets = Environment(self)
        assets.load_path = [
            os.path.join(os.path.dirname(__file__), 'bower_components'),
            os.path.join(os.path.dirname(__file__), 'static/js'),
            # os.path.join(os.path.dirname(__file__), 'bower_components'),
        ]
        assets.register(
            'js_all',
            Bundle(
                '**/**.min.js',
                'js/**.min.js',
                output='js_all.js'
            )
        )
Exemplo n.º 4
0
def create_v2_blueprint(app, app_static_root):
    blueprint = Blueprint(
        'webapp_v2',
        __name__,
        template_folder=os.path.join(PROJECT_ROOT, 'webapp/html')
    )

    from changes.web.index import IndexView
    from changes.web.static import StaticView

    static_root = os.path.join(PROJECT_ROOT, 'webapp')
    revision_facts = changes.get_revision_info() or {}
    revision = revision_facts.get('hash', '0') if not app.debug else '0'

    # all of these urls are automatically prefixed with v2
    # (see the register_blueprint call above)

    # static file paths contain the current revision so that users
    # don't hit outdated static resources
    blueprint.add_url_rule(
        '/static/' + revision + '/<path:filename>',
        view_func=StaticView.as_view(
            'static',
            root=static_root,
            hacky_vendor_root=app_static_root)
    )

    # no need to set up our own login/logout urls

    blueprint.add_url_rule('/<path:path>',
      view_func=IndexView.as_view('index-path', use_v2=True))
    blueprint.add_url_rule('/', view_func=IndexView.as_view('index', use_v2=True))

    # serve custom images if we have a custom content file
    if app.config['WEBAPP_CUSTOM_JS']:
        custom_dir = os.path.dirname(app.config['WEBAPP_CUSTOM_JS'])
        blueprint.add_url_rule(
            '/custom_image/<path:filename>',
            view_func=StaticView.as_view(
                'custom_image',
                root=custom_dir)
        )

    # One last thing...v2 uses CSS bundling via flask-assets, so set that up on
    # the main app object
    assets = Environment(app)
    assets.config['directory'] = os.path.join(PROJECT_ROOT, 'webapp')
    assets.config['url'] = '/v2/static/' + revision + '/'
    # path to the lessc binary.
    assets.config['LESS_BIN'] = os.path.join(PROJECT_ROOT, 'node_modules/.bin/lessc')

    assets.config['LESS_EXTRA_ARGS'] = (['--global-var=custom_css="%s"' % app.config['WEBAPP_CUSTOM_CSS']]
        if app.config['WEBAPP_CUSTOM_CSS']
        else [])

    assets.load_path = [
        os.path.join(PROJECT_ROOT, 'webapp')
    ]

    return blueprint
Exemplo n.º 5
0
def configure_bundle(app):
    bundles = {
        'js_all': Bundle(
            'jquery/dist/jquery.min.js',
            'js/libs/underscore-min.js',
            'js/libs/backbone-min.js',
            'foundation-sites/dist/foundation.min.js',
            'js/libs/foundation-datepicker.min.js',
            'js/libs/moment-with-locales.min.js',
            'js/*.js',
            output='gen/all.js',
            filters='jsmin'),
        'css_all': Bundle(
            'css/libs/*.css',
            'css/*.css',
            Bundle('main.scss',
                    filters='scss',
                    depends='**/*.scss'),
            filters='cssmin',
            output='gen/all.css')
    }

    assets = Environment(app)
    assets.load_path = [
        os.path.join(os.path.dirname(__file__), 'static'),
        os.path.join(os.path.dirname(__file__), 'bower_components'),
    ]
    assets.register(bundles)
Exemplo n.º 6
0
def configure_extensions(app):
  # Flask-PyMongo
  mongo.init_app(app)

  # Flask-OAuthlib
  oauth.init_app(app)

  # Flask-Login
  @login_manager.user_loader
  def load_user(user_id):
    """Returns the currently active user as an object.

    Since this app doesn't handle passwords etc. there isn't as much
    incentive to keep pinging the database for every request protected
    by 'login_required'.

    Instead I set the expiration for the session cookie to expire at
    regular intervals.
    """
    # 1. Retrive user data from the session
    # 2. Create new User object based of that (potential) data
    data = {
      'user_id': session.get('user_id'),
      'name': session.get('name'),
      'email': session.get('email')
    }

    if data.get('email'):
      user = User(**data)
    else:
      user = None

    return user

  login_manager.init_app(app)

  # Flask-Assets
  # Doing setup here to avoid RuntimeError: assets instance not bound...
  assets = Environment(app)
  assets.auto_build = app.config.get('DEBUG')
  assets.load_path = [
    os.path.join(os.path.dirname(__file__), 'scss'),
    os.path.join(os.path.dirname(__file__), 'coffee'),
    os.path.join(os.path.dirname(__file__), 'handlebars'),
    os.path.join(os.path.dirname(__file__), 'vendor'),
  ]
  assets.url = app.static_url_path

  assets.register('js_all', js)
  assets.register('js_app', js_app)
  assets.register('ember_templates', ember_templates)
  assets.register('scss_all', scss)

  # New Relic Python Agent
  newrelic.agent.initialize('newrelic.ini')
Exemplo n.º 7
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    env = Environment(app)

    if not app.debug and not app.testing and not app.config['SSL_DISABLE']:
        from flask.ext.sslify import SSLify
        sslify = SSLify(app)

    #TODO: implement config_from_pyfile / instance configs
    #app.config.from_pyfile('config.py')
    env.init_app(app)
    bootstrap.init_app(app)
    db.init_app(app)

    # tell flask-assets where to look
    env.load_path = [
        os.path.join(os.path.dirname(__file__), 'bower_components'),
        os.path.join(os.path.dirname(__file__), 'styles'),
        os.path.join(os.path.dirname(__file__), 'js')
    ]

    env.register(
        'style',
        Bundle(
            'style.scss',
            'player.scss',
            'team.scss',
            filters='scss',
            output='style.css'
        )
    )

    env.register(
        'app',
        Bundle(
            'home.js',
            output='app.js'
        )
    )

    @app.template_filter('datetime')
    def format_gametime(value):
        return value.strftime('%m.%d.%Y %H:%M%p')

    from main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    return app
Exemplo n.º 8
0
def configure_default(app):
    from changes.web.index import IndexView
    from changes.web.static import StaticView

    static_root = os.path.join(PROJECT_ROOT, 'webapp')
    revision_facts = changes.get_revision_info() or {}
    revision = revision_facts.get('hash', '0') if not app.debug else '0'

    # static file paths contain the current revision so that users
    # don't hit outdated static resources
    hacky_vendor_root = os.path.join(PROJECT_ROOT, 'static')
    app.add_url_rule(
        '/static/' + revision + '/<path:filename>',
        view_func=StaticView.as_view(
            'static',
            root=static_root,
            hacky_vendor_root=hacky_vendor_root)
    )

    app.add_url_rule('/<path:path>',
      view_func=IndexView.as_view('index-path', use_v2=True))
    app.add_url_rule('/', view_func=IndexView.as_view('index', use_v2=True))

    # serve custom images if we have a custom content file
    if app.config['WEBAPP_CUSTOM_JS']:
        custom_dir = os.path.dirname(app.config['WEBAPP_CUSTOM_JS'])
        app.add_url_rule(
            '/custom_image/<path:filename>',
            view_func=StaticView.as_view(
                'custom_image',
                root=custom_dir)
        )

    # One last thing...we use CSS bundling via flask-assets, so set that up on
    # the main app object
    assets = Environment(app)
    assets.config['directory'] = os.path.join(PROJECT_ROOT, 'webapp')
    assets.config['url'] = '/static/' + revision + '/'
    # path to the lessc binary.
    assets.config['LESS_BIN'] = os.path.join(PROJECT_ROOT, 'node_modules/.bin/lessc')

    assets.config['LESS_EXTRA_ARGS'] = (['--global-var=custom_css="%s"' % app.config['WEBAPP_CUSTOM_CSS']]
        if app.config['WEBAPP_CUSTOM_CSS']
        else [])

    assets.load_path = [
        os.path.join(PROJECT_ROOT, 'webapp')
    ]
Exemplo n.º 9
0
def configure_assets(app):
    revision_facts = changes.get_revision_info() or {}
    revision = revision_facts.get('hash', '0') if not app.debug else '0'
    assets = Environment(app)
    assets.config['directory'] = os.path.join(PROJECT_ROOT, 'webapp')
    assets.config['url'] = '/static/' + revision + '/'
    # path to the lessc binary.
    assets.config['LESS_BIN'] = os.path.join(PROJECT_ROOT,
                                             'node_modules/.bin/lessc')

    assets.config['LESS_EXTRA_ARGS'] = ([
        '--global-var=custom_css="%s"' % app.config['WEBAPP_CUSTOM_CSS']
    ] if app.config['WEBAPP_CUSTOM_CSS'] else [])

    assets.load_path = [os.path.join(PROJECT_ROOT, 'webapp')]
    return assets
Exemplo n.º 10
0
def create_app(testing=False):
    app = Flask(__name__)

    try:
        app.config.from_object('config')
    except:
        app.config.from_object('configdist')
    if testing:
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False

    app.json_encoder = ExtensibleJSONEncoder
    app.secret_key = app.config['SECRET_KEY']
    app.register_blueprint(user_bp)

    csrf = CsrfProtect()
    csrf.init_app(app)

    # Initialize login manager
    login_manager.init_app(app)

    # Assets bundles: js, jsx, css
    env = Environment(app)
    root = os.path.dirname(os.path.abspath(__file__)) + '/../'
    env.load_path = [
        root + 'node_modules',
        root + 'client/style'
    ]
    env.register('css', css)

    @app.teardown_appcontext
    def shutdown_session(response):
        database.session.remove()

    @app.route('/')
    @app.route('/<path:path>')
    def index(path=None):
        """Main route for the single page app"""
        data = dict(
            user=anonymous_user_data,
            alerts=[]
        )
        if current_user.is_authenticated():
            data['user'] = current_user
        return render_template('index.html', app_data=dumps(data))

    return app
Exemplo n.º 11
0
def configure_assets(app):
    revision_facts = changes.get_revision_info() or {}
    revision = revision_facts.get('hash', '0') if not app.debug else '0'
    assets = Environment(app)
    assets.config['directory'] = os.path.join(PROJECT_ROOT, 'webapp')
    assets.config['url'] = '/static/' + revision + '/'
    # path to the lessc binary.
    assets.config['LESS_BIN'] = os.path.join(PROJECT_ROOT, 'node_modules/.bin/lessc')

    assets.config['LESS_EXTRA_ARGS'] = (['--global-var=custom_css="%s"' % app.config['WEBAPP_CUSTOM_CSS']]
        if app.config['WEBAPP_CUSTOM_CSS']
        else [])

    assets.load_path = [
        os.path.join(PROJECT_ROOT, 'webapp')
    ]
    return assets
Exemplo n.º 12
0
def create_app():
    app = Flask(__name__,
        static_url_path='',
        static_folder='../public',
        template_folder='../views')
    app.config.update(config['flask'])
    CsrfProtect(app)

    mail.init_app(app)

    ViewFilters.register(app)

    assets = Environment(app)
    assets.load_path = [
        app.static_folder,
        approot('bower_components')
    ]
    assets.url = app.static_url_path

    if app.debug:
        css_filters = 'sass,cssmin'
        js_filters = 'jsmin'
    else:
        css_filters = 'sass'
        js_filters = None

    css_bundle = Bundle('style.sass', filters=css_filters, output='bundle.min.css')
    assets.register('css_all', css_bundle)
    js_bundle = Bundle('jquery/dist/jquery.js', 'sjcl/sjcl.js', 'jquery-qrcode/jquery.qrcode.min.js', 'js/*.js', filters=js_filters, output='bundle.min.js')
    assets.register('js_all', js_bundle)

    app.register_blueprint(Blueprint(
        'bower', __name__, static_url_path='/bower', static_folder=approot('bower_components')))

    blueprint.register(app)

    for paste in db_session.query(Paste.key).filter_by(legacy=True).all():
        route = u'/' + paste.key
        app.add_url_rule(route, 'legacy_show_'+paste.key, partial(redirect, '/paste/' + paste.key))

    if config['paste.spam_ml']:
        spam_ml.load()

    return app
Exemplo n.º 13
0
def create_v2_blueprint(app, app_static_root):
    blueprint = Blueprint(
        'webapp_v2',
        __name__,
        template_folder=os.path.join(PROJECT_ROOT, 'webapp/html')
    )

    from changes.web.index import IndexView
    from changes.web.static import StaticView

    static_root = os.path.join(PROJECT_ROOT, 'webapp')
    revision_facts = changes.get_revision_info() or {}
    revision = revision_facts.get('hash', '0') if not app.debug else '0'

    # all of these urls are automatically prefixed with v2
    # (see the register_blueprint call above)

    # static file paths contain the current revision so that users
    # don't hit outdated static resources
    blueprint.add_url_rule(
        '/static/' + revision + '/<path:filename>',
        view_func=StaticView.as_view(
            'static',
            root=static_root,
            hacky_vendor_root=app_static_root)
    )

    # no need to set up our own login/logout urls

    blueprint.add_url_rule('/<path:path>',
      view_func=IndexView.as_view('index-path', use_v2=True))
    blueprint.add_url_rule('/', view_func=IndexView.as_view('index', use_v2=True))

    # One last thing...v2 uses CSS bundling via flask-assets, so set that up on
    # the main app object
    assets = Environment(app)
    assets.config['directory'] = os.path.join(PROJECT_ROOT, 'webapp')
    assets.config['url'] = '/v2/static/' + revision + '/'
    assets.load_path = [
        os.path.join(PROJECT_ROOT, 'webapp')
    ]

    return blueprint
Exemplo n.º 14
0
def init_assets(application):
    assets = Environment(application)
    assets.config['SASS_BIN'] = "/usr/local/bin/sass"
    assets.load_path = ["assets/"]
    assets.url = "/static"

    css_main = Bundle('sass/app.scss',
                      filters=('pyscss,cssmin'),
                      depends=('sass/*.scss', 'sass/**/*.scss', 'sass/**/**/*.scss'),
                      output='css/gen/app.%(version)s.css')
    assets.register('css_main', css_main)

    js_base = Bundle('js/vendor/excanvas.js',
                     'js/vendor/jquery-1.11.1.js',
                     'js/vendor/jquery.minecraftskin.js')
    js_main = Bundle(js_base,
                     filters='rjsmin',
                     output='js/gen/app.%(version)s.js')
    assets.register('js_main', js_main)
Exemplo n.º 15
0
def create_v2_blueprint(app, app_static_root):
    blueprint = Blueprint('webapp_v2',
                          __name__,
                          template_folder=os.path.join(PROJECT_ROOT,
                                                       'webapp/html'))

    from changes.web.index import IndexView
    from changes.web.static import StaticView

    static_root = os.path.join(PROJECT_ROOT, 'webapp')
    revision_facts = changes.get_revision_info() or {}
    revision = revision_facts.get('hash', '0') if not app.debug else '0'

    # all of these urls are automatically prefixed with v2
    # (see the register_blueprint call above)

    # static file paths contain the current revision so that users
    # don't hit outdated static resources
    blueprint.add_url_rule('/static/' + revision + '/<path:filename>',
                           view_func=StaticView.as_view(
                               'static',
                               root=static_root,
                               hacky_vendor_root=app_static_root))

    # no need to set up our own login/logout urls

    blueprint.add_url_rule('/<path:path>',
                           view_func=IndexView.as_view('index-path',
                                                       use_v2=True))
    blueprint.add_url_rule('/',
                           view_func=IndexView.as_view('index', use_v2=True))

    # One last thing...v2 uses CSS bundling via flask-assets, so set that up on
    # the main app object
    assets = Environment(app)
    assets.config['directory'] = os.path.join(PROJECT_ROOT, 'webapp')
    assets.config['url'] = '/v2/static/' + revision + '/'
    assets.load_path = [os.path.join(PROJECT_ROOT, 'webapp')]

    return blueprint
Exemplo n.º 16
0
from dexter.app import app

# setup assets
from flask.ext.assets import Environment, Bundle
assets = Environment(app)
assets.url_expire = False
assets.debug      = app.config['ENV'] == 'development'
assets.directory  = '%s/public' % app.config.root_path
assets.load_path  = ['assets']
assets.url        = '/public'

assets.register('css',
    Bundle(
      'css/bootstrap-3.2.0.min.css',
      'css/bootstrap-theme-3.2.0.min.css',
      'css/font-awesome-4.3.0.min.css',
      'css/datepicker3.css',
      'css/bootstrap-datetimepicker.min.css',
      'css/daterangepicker-bs3.css',
      'css/select2-3.4.8.css',
      'css/select2-bootstrap-3.4.8.css',
      'css/dropzone-3.10.2.css',
      Bundle(
        'css/*.scss',
        filters='pyscss',
        output='css/app.%(version)s.css'),
      output='css/all.%(version)s.css'))

assets.register('mine-css',
    Bundle(
      'css/bootstrap-3.2.0.min.css',
Exemplo n.º 17
0
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)

# add commands to manage chart cache
from whiskyton.managers.charts import ChartsCommand
manager.add_command('charts', ChartsCommand)

# add command to save analytics data via FTP
from whiskyton.managers.anaytics import AnalyticsCommand
manager.add_command('analytics', AnalyticsCommand)

# enable gzip compression
Compress(app)

# scss
assets = Environment(app)
assets.load_path = [app.config['BASEDIR'].child('whiskyton')]
assets.from_yaml(app.config['BASEDIR'].child('whiskyton', 'assets.yaml'))

# register blueprints
from whiskyton.blueprints.site import site
from whiskyton.blueprints.files import files
app.register_blueprint(site)
app.register_blueprint(files)

# log errors
log_handler = StreamHandler()
app.logger.setLevel(logging.DEBUG)
app.logger.addHandler(log_handler)
Exemplo n.º 18
0
from flask import Flask
from flask.ext.assets import Environment, Bundle

app = Flask(__name__, instance_relative_config=True, static_url_path='/static')
app.config.from_object('config')
try:
    # Configuration from instance folder
    app.config.from_pyfile('config.py')
except EnvironmentError:
    pass

assets = Environment(app)

assets.load_path = [
    os.path.join(os.path.dirname(__file__), 'static/sass'),
    os.path.join(os.path.dirname(__file__), 'static/js'),
    os.path.join(os.path.dirname(__file__), 'static/bower_components'),
    os.path.join(os.path.dirname(__file__), 'static/gen'),
]

assets.register(
    'js_all',
    Bundle('jquery/dist/jquery.min.js',
           'bootstrap/dist/js/bootstrap.min.js',
           'all.js',
           filters='jsmin',
           output='gen/packed.js'))
assets.register(
    'scss_all',
    Bundle('bootstrap/dist/css/bootstrap.css',
           'all.scss',
           filters='pyscss,cssmin',
Exemplo n.º 19
0
        output='../static/css/multiple-select.css'
    ),

    # JAVASCRIPT
    'main_js': Bundle(
        'lib/multiple-select/jquery.multiple.select.js',
        'js/main.js',
        filters='jsmin',
        output='../static/js/main.js'
    ),
    'download_js': Bundle(
        'js/download.js',
        output='../static/js/download.js',
        filters='jsmin'
    ),
    'edit_js': Bundle(
        'js/edit.js',
        output='../static/js/edit.js',
        filters='jsmin'
    ),
    'search_js': Bundle(
        'js/search.js',
        output='../static/js/search.js',
        filters='jsmin'
    )
}

assets = Environment(app)
assets.load_path = [abspath(join(app.root_path, 'assets'))]
assets.cache = abspath(join(app.root_path, 'assets/cache'))
assets.register(bundles)
Exemplo n.º 20
0
# init the login manager
lm = LoginManager()
lm.init_app(app)
lm.login_view = '/login'
lm.login_message = {'type': 'info', 'text': lm.login_message}

# enable gzip compression
Compress(app)

# assets
site_path = app.config['BASEDIR'].child('findaconf', 'blueprints', 'site')
bower_path = app.config['BASEDIR'].child('findaconf', 'bower')
assets = Environment(app)
assets.config['PYSCSS_LOAD_PATHS'] = [bower_path.child('foundation', 'scss')]
assets.load_path = [site_path, bower_path]
assets.from_yaml(app.config['BASEDIR'].child('findaconf', 'assets.yml'))

# manage errors
if not app.config['DEBUG']:
    import logging
    from logging.handlers import RotatingFileHandler
    filepath = app.config['BASEDIR'].child('errors.log')
    handler = RotatingFileHandler(filepath, 'a', 1 * 1024 * 1024, 10)
    row = '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'
    formatter = logging.Formatter(row)
    handler.setFormatter(formatter)
    handler.setLevel(logging.INFO)
    app.logger.setLevel(logging.INFO)
    app.logger.addHandler(handler)
    app.logger.info('{} started successfully.'.format(app.config['TITLE']))
Exemplo n.º 21
0
from __future__ import division, print_function, absolute_import, unicode_literals
from flask import Flask
from flask_wtf.csrf import CsrfProtect
from flask.ext.assets import Environment, Bundle
from flask.ext.mail import Mail
from celery import Celery
from webassets.filter import get_filter
from .util import root, config, DictAssetLoader

#: Flask application instance
app = Flask('zg', **config('app'))
app.config.update(config('flask'))

#: Celery instance
celery = Celery('zg-celery')
celery.conf.update(config('celery'))

#: Flask mail instance
mail = Mail()

CsrfProtect(app)

assets = Environment(app)
assets.url = ''
assets.directory = root('./public')
assets.load_path = [app.static_folder, root('./bower_components')]
assets.register(DictAssetLoader(config('assets')).load_bundles(assets))

import zg.routes

from flask import Flask
from flask import render_template
from flask.ext.assets import Bundle
from flask.ext.assets import Environment

DEBUG = True

app = Flask(__name__)
app.debug = DEBUG

assets = Environment(app)
assets.debug = DEBUG

assets.load_path = [
    os.path.join(os.path.dirname(__file__), 'sass'),
    os.path.join(os.path.dirname(__file__), 'coffee'),
    os.path.join(os.path.dirname(__file__), 'bower_components'),
]

assets.register(
    'css',
    Bundle(
        '**/*.css',
        Bundle(
            '*.sass',
            filters="sass",
            output="sass.css"
        ),
        filters="cssmin",
        output="style.css"
    )
Exemplo n.º 23
0
app.config['ENV'] = env

# Function to easily find your assets
# In your template use <link rel=stylesheet href="{{ static('filename') }}">
app.jinja_env.globals['static'] = (
    lambda filename: url_for('static', filename = filename)
)

# setup assets
from flask.ext.assets import Environment, Bundle
from .app import app

assets = Environment(app)
assets.url_expire = False
assets.debug      = app.config['ENV'] == 'development'
assets.load_path  = ['%s/assets' % app.config.root_path]

assets.register('css',
    Bundle(
      'stylesheets/**/*.css',
      Bundle(
        'stylesheets/*.scss',
        filters='pyscss',
        output='stylesheets/app.%(version)s.css'),
      output='stylesheets/all.%(version)s.css'))

assets.register('js', Bundle(
    'js/**/*.js',
    output='js/app.%(version)s.js'))

from . import views
Exemplo n.º 24
0
def build_app():
    '''
    Method for creating and configuring a flask app instance
    '''
    app = Flask(__name__, instance_relative_config=True)
    app.register_blueprint(build_admin_bp(), url_prefix='/admin')

    # Load the default configuration
    app.config.from_object('nscmr.config.default')

    # Load the configuration from the instance folder
    app.config.from_pyfile('config.py')

    # Load the configuration specified by the APP_CONFIG_FILE environment var
    app.config.from_envvar('APP_CONFIG_FILE')

    # config extensions

    ###############
    # Flask-Login #
    ###############

    login_manager = LoginManager()
    login_manager.init_app(app)

    @login_manager.user_loader
    def load_user(user_id):
        return User.get_by_id(user_id, to_obj=True)

    ###################
    # Flask-Principal #
    ###################

    Principal(app)

    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        identity.user = current_user

        if hasattr(current_user, 'id'):
            identity.provides.add(UserNeed(current_user.id))

        if hasattr(current_user, 'roles') and \
                getattr(current_user, 'roles') is not None:
            for role in current_user.roles:
                identity.provides.add(RoleNeed(role))

    #############
    # Flask-WTF #
    #############

    CsrfProtect(app)

    #################
    # Flask-Uploads #
    #################

    configure_uploads(app, (category_images, product_images))

    ################
    # Flask-Assets #
    ################

    assets = Environment(app)
    assets.load_path = [
        os.path.join(app.root_path, 'static/sass'),
        os.path.join(app.root_path, 'static/js'),
        os.path.join(app.root_path, 'bower_components'),
    ]

    assets.register(
        'js_base',
        Bundle(
            'jquery/dist/jquery.min.js',
            'bootstrap/dist/js/bootstrap.min.js',
            'duvet.js'),
        output='js/base.js')

    assets.register(
        'angular',
        Bundle(
            'angular/angular.js',
            'angular-i18n/angular-locale_pt-br.js',
            'angular-ui-mask/dist/mask.js'),
        output='js/angular-bundle.js')

    assets.register(
        'css_all',
        Bundle(
            'bootstrap/dist/css/bootstrap.min.css',
            'font-awesome/css/font-awesome.min.css',
            Bundle(
                'style.scss',
                filters='scss',
                output='css/style.css')),
        output='css/all.css')

    #################
    # Flask session #
    #################

    Session(app)

    # end config extensions

    return app
Exemplo n.º 25
0
from flask.ext.assets import Environment, Bundle


app = Flask(__name__, instance_relative_config=True, static_url_path='/static')
app.config.from_object('config')
try:
    # Configuration from instance folder
    app.config.from_pyfile('config.py')
except EnvironmentError:
    pass

assets = Environment(app)

assets.load_path = [
    os.path.join(os.path.dirname(__file__), 'static/sass'),
    os.path.join(os.path.dirname(__file__), 'static/js'),
    os.path.join(os.path.dirname(__file__), 'static/bower_components'),
    os.path.join(os.path.dirname(__file__), 'static/gen'),
]

assets.register(
    'js_all',
    Bundle(
        'jquery/dist/jquery.min.js',
        'bootstrap/dist/js/bootstrap.min.js',
        'all.js',
        filters='jsmin',
        output='gen/packed.js'
    )
)
assets.register(
    'scss_all',
import datetime
import dateutil.parser
from pytz import timezone
from flask import Flask, render_template, jsonify, request, url_for
from flask.ext.assets import Environment, Bundle

app = Flask(__name__)

assets = Environment(app)

# just for development on Windows
assets.cache = False
assets.manifest = False

assets.load_path = [
    os.path.join(os.path.dirname(__file__), 'less'),
    os.path.join(os.path.dirname(__file__), 'coffee')
]

# JavaScript scrollable widget
js_scrollable = Bundle('common.coffee',
                       'common_models.coffee',
                       'common_bindings.coffee',
                       'schedule-scrollable/bindings.coffee',
                       'schedule-scrollable/application.coffee',
                       filters='coffeescript',
                       output='js/schedule-scrollable.js')
assets.register('js_scrollable', js_scrollable)

# JavaScript block widget
js_block = Bundle('common.coffee',
                  'common_models.coffee',
Exemplo n.º 27
0
import json
from pprint import pprint

from flask import Flask, render_template, request, redirect, url_for
from flask.ext.assets import Environment, Bundle
import unirest

import settings

app = Flask(__name__)
app.debug = True

assets = Environment(app)
assets.load_path = [
    os.path.join(os.path.dirname(__file__), 'less'),
    os.path.join(os.path.dirname(__file__), 'js'),
    os.path.join(os.path.dirname(__file__), 'lib'),
]

css = Bundle('main.less', filters='less', output='gen/main.css', depends='bootstrap/less/*.less')
assets.register('css', css)

js = Bundle('jquery/jquery.js', 'jquery/jquery.optionTree.js', 'bootstrap/js/bootstrap.js', filters='rjsmin', output='gen/main.js')
assets.register('js', js)

#create add user helper function
def get_user(uid):
    response = unirest.get(settings.API_URL + 'user/' + uid, headers={'Content-Type':'application/json'})
    user = response.body
    return user
Exemplo n.º 28
0
from flask.ext.assets import Environment, Bundle
from flask.ext.socketio import SocketIO, emit, join_room, leave_room

from . import canvas

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

socketio = SocketIO(app)

project_path = os.path.dirname(os.path.dirname(__file__))

# Tell flask-assets where to look for our files.
assets.load_path = [
    os.path.join(project_path, 'bower_components'),
    os.path.join(project_path, 'node_modules'),
    os.path.join(os.path.dirname(__file__), 'js'),
    os.path.join(os.path.dirname(__file__), 'css'),
]

assets.register(
    'js_all',
    Bundle(
        'jquery/dist/jquery.min.js',
        'drawingboard.js/dist/drawingboard.min.js',
        'canvas.js',
        output='js_all.js'
    )
)

assets.register(
    'css_all',
Exemplo n.º 29
0
from functools import partial
from os import path

from flask import Flask
from flask.ext.assets import Environment, Bundle
from flask.ext.socketio import SocketIO

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)

env = Environment(app)

env.load_path = [
    path.join(path.dirname(__file__), 'bower_components'),
]

js_bundle = Bundle('jquery/dist/jquery.min.js',
                   'bootstrap-sass/dist/js/bootstrap.min.js',
                   output='js_all.js')

css_bundle = Bundle('bootstrap-sass/lib/bootstrap.scss',
                    filters=['pyscss'],
                    output='css_all.css')

env.register('js_all', js_bundle)
env.register('css_all', css_bundle)

env['js_all'].urls()
env['css_all'].urls()
Exemplo n.º 30
0
api = Api(app)

# init sql alchemy
db = SQLAlchemy(app)
 
# init login manager
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'

# init web assets
assets = Environment(app)

assets.load_path = [
    os.path.join(WEB_DIR, 'static', 'css'),
    os.path.join(WEB_DIR, 'static', 'js'),
    os.path.join(WEB_DIR, 'static', 'components'),
]

assets.register(
    'app_js',
    Bundle(
        'jquery/dist/jquery.min.js',
        'bootstrap/dist/js/bootstrap.min.js',
        Bundle(
            'underscore/underscore.js',
            'backbone/backbone.js',
            'socket.io-client/socket.io.js',
            'application.js',
            'views/console.js',
            'router.js',
Exemplo n.º 31
0
    message.extra_headers = {
        'X-MC-Subaccount': app.config['MANDRILL_TRANSACTIONAL_SUBACCOUNT'],
        'X-MC-Template': app.config['MANDRILL_TRANSACTIONAL_TEMPLATE'],
        'X-MC-GoogleAnalytics': 'pmg.org.za',
    }
    original_send(message)
app.extensions.get('mail').send = send_email_with_subaccount


# setup assets
from flask.ext.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.2.0/css/font-awesome.min.css',
      'chosen/chosen.min.css',
      Bundle(
        'resources/css/style.scss',
        'resources/css/committees.scss',
        'resources/css/bill-progress.scss',
        filters=PyScss(load_paths=assets.load_path),
        output='stylesheets/styles.%(version)s.css'),
      output='stylesheets/app.%(version)s.css'))
Exemplo n.º 32
0
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)

# add commands to manage chart cache
from whiskyton.managers.charts import ChartsCommand
manager.add_command('charts', ChartsCommand)

# add command to save analytics data via FTP
from whiskyton.managers.anaytics import AnalyticsCommand
manager.add_command('analytics', AnalyticsCommand)

# enable gzip compression
Compress(app)

# scss
assets = Environment(app)
assets.load_path = [app.config['BASEDIR'].child('whiskyton')]
assets.from_yaml(app.config['BASEDIR'].child('whiskyton', 'assets.yaml'))

# register blueprints
from whiskyton.blueprints.site import site
from whiskyton.blueprints.files import files
app.register_blueprint(site)
app.register_blueprint(files)

# log errors
log_handler = StreamHandler()
app.logger.setLevel(logging.DEBUG)
app.logger.addHandler(log_handler)
Exemplo n.º 33
0
)

# Analytics
Analytics(app)
app.config['ANALYTICS']['GOOGLE_UNIVERSAL_ANALYTICS']['ACCOUNT'] = ''

# Function to easily find your assets
# In your template use <link rel=stylesheet href="{{ static('filename') }}">
app.jinja_env.globals['static'] = (
    lambda filename: url_for('static', filename = filename)
)

# setup assets
assets = Environment(app)
assets.url_expire = False
assets.load_path = ['%s/static' % app.config.root_path]

# Bundle these in a specific order for dependency reasons
assets.register('js', Bundle(
    'js/vendor/jquery/jquery.js',
    'js/vendor/bootstrap.min.js',
    'js/vendor/d3/d3.min.js',
    'js/vendor/nvd3/nv.d3.min.js',
    'js/vendor/*.js',
    'js/*.js',
    output='js/app.%(version)s.js'))

assets.register('css',
    Bundle(
      'css/vendor/*.css',
      'css/*.css',
Exemplo n.º 34
0
login_manager.init_app(app)

# Configure paths
root = os.path.dirname(os.path.abspath(__file__))
app.config['UPLOAD_PATH'] = upload_path = os.path.join(root, '../uploads')
theme_path = os.path.join(root, 'static/theme') 
try:
    theme_files = tuple([f for f in os.listdir(theme_path) \
                         if os.path.isfile(os.path.join(theme_path, f))])
except:
    theme_files = tuple()

assets = Environment(app)
assets.load_path = [
    root + '/../node_modules',
    root + '/../client/style',
    theme_path
]
js = Bundle(
    'isotope-layout/dist/isotope.pkgd.min.js',
    'isotope-packery/packery-mode.pkgd.min.js'
)
assets.register('js', js)
css = Bundle(
    'bootstrap/dist/css/bootstrap.min.css',
    'base.css',
    Bundle(*theme_files)
)
assets.register('css', css)

@app.teardown_appcontext
Exemplo n.º 35
0
import json
from pprint import pprint

from flask import Flask, render_template, request, redirect, url_for
from flask.ext.assets import Environment, Bundle
import unirest

import settings

app = Flask(__name__)
app.debug = True

assets = Environment(app)
assets.load_path = [
    os.path.join(os.path.dirname(__file__), 'less'),
    os.path.join(os.path.dirname(__file__), 'js'),
    os.path.join(os.path.dirname(__file__), 'lib'),
]

css = Bundle('main.less',
             filters='less',
             output='gen/main.css',
             depends='bootstrap/less/*.less')
assets.register('css', css)

js = Bundle('jquery/jquery.js',
            'jquery/jquery.optionTree.js',
            'bootstrap/js/bootstrap.js',
            filters='rjsmin',
            output='gen/main.js')
assets.register('js', js)
Exemplo n.º 36
0
lm.init_app(app)
lm.login_view = "login"

if app.config['SENTRY_ENABLED']:
	from raven.contrib.flask import Sentry
	sentry = Sentry(app)

from intranet.models.user import AnonymousUser
lm.anonymous_user = AnonymousUser

@lm.user_loader
def load_user(userid):
	return users.get_user(user_id=userid)

assets.load_path = [
	os.path.join(os.path.dirname(__file__), 'static'),
	os.path.join(os.path.dirname(__file__), 'static', 'bower_components'),
]

assets.register(
	'js_all',
	Bundle(
		'jquery/dist/jquery.min.js',
		'bootstrap/dist/js/bootstrap.min.js',
		output='js_all.js'
	)
)

assets.register(
	'css_all',
	Bundle(
		'css/fonts.css',
Exemplo n.º 37
0
        output='../static/css/multiple-select.css'
    ),

    # JAVASCRIPT
    'main_js': Bundle(
        'lib/multiple-select/jquery.multiple.select.js',
        'js/main.js',
        filters='jsmin',
        output='../static/js/main.js'
    ),
    'download_js': Bundle(
        'js/download.js',
        output='../static/js/download.js',
        filters='jsmin'
    ),
    'edit_js': Bundle(
        'js/edit.js',
        output='../static/js/edit.js',
        filters='jsmin'
    ),
    'search_js': Bundle(
        'js/search.js',
        output='../static/js/search.js',
        filters='jsmin'
    )
}

assets = Environment(app)
assets.load_path = [abspath(join(app.root_path, 'assets'))]
assets.cache = abspath(join(app.root_path, 'assets/cache'))
assets.register(bundles)
Exemplo n.º 38
0
def init_app(app):
    db.init_app(app)
    cache.init_app(app)
    debug_toolbar.init_app(app)
    app.template_folder = os.path.join(os.path.dirname(__file__), 'templates/')

    migrate = Migrate(app, db)

    # Import and register the different asset bundles
    assets_env = Environment(app)
    assets_env.load_path = [os.path.join(os.path.dirname(__file__), 'static')]
    assets_env.directory = os.path.join(os.path.dirname(__file__), 'static')
    assets_env.url = '/admin/static/'
    # assets_env.register('js_all', js)
    print("directory ", assets_env.directory,
          os.path.join(os.path.dirname(__file__), 'static/'))
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in list(assets_loader.load_bundles().items()):
        assets_env.register(name, bundle)

    # Setup user handling
    from silverflask.models import User

    user_adapter = SQLAlchemyAdapter(db, User)
    user_manager = UserManager(user_adapter)
    user_manager.init_app(app)

    ###
    #  SILVERFLASK
    ###

    upload_path = os.path.join(app.instance_path,
                               app.config["SILVERFLASK_UPLOAD_PATH"])
    app.config["SILVERFLASK_ABSOLUTE_UPLOAD_PATH"] = upload_path
    app.storage_backend = LocalFileStorageBackend(upload_path)

    from silverflask.controllers.page_controller import SiteTreeController
    app.register_blueprint(SiteTreeController.create_blueprint(app))

    from silverflask.core.dev_controller import DevController
    app.register_blueprint(DevController.create_blueprint(app))

    from silverflask.controllers.cms_controller import CMSController, PagesCMSController, FilesCMSController, \
        DataObjectCMSController

    app.register_blueprint(CMSController.create_blueprint(app))
    app.register_blueprint(DataObjectCMSController.create_blueprint(app))
    app.register_blueprint(PagesCMSController.create_blueprint(app))
    app.register_blueprint(FilesCMSController.create_blueprint(app))
    from silverflask.controllers.security_controller import SecurityController
    app.register_blueprint(SecurityController.create_blueprint(app))

    from silverflask.core.theme import init_themes
    init_themes(app)

    from silverflask.controllers.main import setup_processors, init_blueprint
    from silverflask.controllers.cms import bp as cms_bp

    setup_processors(app)
    main = init_blueprint(app)
    app.register_blueprint(main)
    app.register_blueprint(cms_bp, url_prefix='/admin')

    # for rule in app.url_map.iter_rules():
    #     print(rule)

    return app
Exemplo n.º 39
0
from dexter.app import app

# setup assets
from flask.ext.assets import Environment, Bundle
assets = Environment(app)
assets.url_expire = False
assets.debug = app.config['ENV'] == 'development'
assets.directory = '%s/public' % app.config.root_path
assets.load_path = ['assets']
assets.url = '/public'

assets.register(
    'css',
    Bundle('css/bootstrap-3.2.0.min.css',
           'css/bootstrap-theme-3.2.0.min.css',
           'css/font-awesome-4.3.0.min.css',
           'css/datepicker3.css',
           'css/bootstrap-datetimepicker.min.css',
           'css/daterangepicker-bs3.css',
           'css/select2-3.4.8.css',
           'css/select2-bootstrap-3.4.8.css',
           'css/dropzone-3.10.2.css',
           Bundle('css/*.scss',
                  filters='pyscss',
                  output='css/app.%(version)s.css'),
           output='css/all.%(version)s.css'))

assets.register(
    'mine-css',
    Bundle('css/bootstrap-3.2.0.min.css',
           'css/bootstrap-theme-3.2.0.min.css',
Exemplo n.º 40
0
def create_v2_blueprint(app, app_static_root):
    blueprint = Blueprint(
        'webapp_v2',
        __name__,
        template_folder=os.path.join(PROJECT_ROOT, 'webapp/html')
    )

    from changes.web.index import IndexView
    from changes.web.static import StaticView

    static_root = os.path.join(PROJECT_ROOT, 'webapp')
    revision_facts = changes.get_revision_info() or {}
    revision = revision_facts.get('hash', '0') if not app.debug else '0'

    # all of these urls are automatically prefixed with v2
    # (see the register_blueprint call above)

    # static file paths contain the current revision so that users
    # don't hit outdated static resources
    blueprint.add_url_rule(
        '/static/' + revision + '/<path:filename>',
        view_func=StaticView.as_view(
            'static',
            root=static_root,
            hacky_vendor_root=app_static_root)
    )

    # no need to set up our own login/logout urls

    blueprint.add_url_rule('/<path:path>',
      view_func=IndexView.as_view('index-path', use_v2=True))
    blueprint.add_url_rule('/', view_func=IndexView.as_view('index', use_v2=True))

    # serve custom images if we have a custom content file
    if app.config['WEBAPP_CUSTOM_JS']:
        custom_dir = os.path.dirname(app.config['WEBAPP_CUSTOM_JS'])
        blueprint.add_url_rule(
            '/custom_image/' + revision + '/<path:filename>',
            view_func=StaticView.as_view(
                'custom_image',
                root=custom_dir)
        )

    # One last thing...v2 uses CSS bundling via flask-assets, so set that up on
    # the main app object
    assets = Environment(app)
    assets.config['directory'] = os.path.join(PROJECT_ROOT, 'webapp')
    assets.config['url'] = '/v2/static/' + revision + '/'
    # path to the lessc binary.
    assets.config['LESS_BIN'] = os.path.join(PROJECT_ROOT, 'node_modules/.bin/lessc')

    # on startup we need to trash the webassets cache and the existing bundled
    # css: the user could change WEBAPP_CUSTOM_CSS and we'd still serve the
    # old, cached bundle
    try:
        shutil.rmtree(os.path.join(PROJECT_ROOT, 'webapp/.webassets-cache'))
    except OSError:
        pass  # throws if the dir doesn't exist, ignore that

    try:
        os.remove(os.path.join(PROJECT_ROOT, 'webapp/css/bundled.css'))
    except OSError:
        pass

    # less needs to know where to find the WEBAPP_CUSTOM_CSS file. If we don't
    # have one, import a placeholder file instead.
    imported_custom_css = (app.config['WEBAPP_CUSTOM_CSS']
        if app.config['WEBAPP_CUSTOM_CSS']
        else os.path.join(PROJECT_ROOT, 'webapp/css/placeholder.less'))

    assets.config['LESS_EXTRA_ARGS'] = ['--global-var=custom_css="%s"' % imported_custom_css]

    assets.load_path = [
        os.path.join(PROJECT_ROOT, 'webapp')
    ]

    return blueprint