Exemplo n.º 1
0
def configure_web_routes(app):
    from changes.web.auth import AuthorizedView, LoginView, LogoutView
    from changes.web.index import IndexView
    from changes.web.static import StaticView

    if app.debug:
        static_root = os.path.join(PROJECT_ROOT, 'static')
        revision = '0'
    else:
        static_root = os.path.join(PROJECT_ROOT, 'static-built')
        revision = changes.get_revision() or '0'

    app.add_url_rule(
        '/static/' + revision + '/<path:filename>',
        view_func=StaticView.as_view('static', root=static_root))
    app.add_url_rule(
        '/partials/<path:filename>',
        view_func=StaticView.as_view('partials', root=os.path.join(PROJECT_ROOT, 'partials')))

    app.add_url_rule(
        '/auth/login/', view_func=LoginView.as_view('login', authorized_url='authorized'))
    app.add_url_rule(
        '/auth/logout/', view_func=LogoutView.as_view('logout', complete_url='index'))
    app.add_url_rule(
        '/auth/complete/', view_func=AuthorizedView.as_view('authorized', authorized_url='authorized', complete_url='index'))

    app.add_url_rule(
        '/<path:path>', view_func=IndexView.as_view('index-path'))
    app.add_url_rule(
        '/', view_func=IndexView.as_view('index'))
Exemplo n.º 2
0
def configure_web_routes(app):
    from changes.web.auth import AuthorizedView, LoginView, LogoutView
    from changes.web.index import IndexView
    from changes.web.static import StaticView

    if app.debug:
        static_root = os.path.join(PROJECT_ROOT, 'static')
        revision = '0'
    else:
        static_root = os.path.join(PROJECT_ROOT, 'static-built')
        revision = changes.get_revision() or '0'

    app.add_url_rule('/static/' + revision + '/<path:filename>',
                     view_func=StaticView.as_view('static', root=static_root))
    app.add_url_rule('/partials/<path:filename>',
                     view_func=StaticView.as_view('partials',
                                                  root=os.path.join(
                                                      PROJECT_ROOT,
                                                      'partials')))

    app.add_url_rule('/auth/login/',
                     view_func=LoginView.as_view('login',
                                                 authorized_url='authorized'))
    app.add_url_rule('/auth/logout/',
                     view_func=LogoutView.as_view('logout',
                                                  complete_url='index'))
    app.add_url_rule('/auth/complete/',
                     view_func=AuthorizedView.as_view(
                         'authorized',
                         authorized_url='authorized',
                         complete_url='index'))

    app.add_url_rule('/<path:path>', view_func=IndexView.as_view('index-path'))
    app.add_url_rule('/', view_func=IndexView.as_view('index'))
Exemplo n.º 3
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.º 4
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'))
    app.add_url_rule('/', view_func=IndexView.as_view('index'))

    # 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
    configure_assets(app)
Exemplo n.º 5
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'))
    app.add_url_rule('/', view_func=IndexView.as_view('index'))

    # 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
    configure_assets(app)
Exemplo n.º 6
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.º 7
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))
    return blueprint
Exemplo n.º 8
0
def configure_web_routes(app):
    from changes.web.auth import AuthorizedView, LoginView, LogoutView
    from changes.web.index import IndexView
    from changes.web.static import StaticView

    # the path used by the webapp for static resources uses the current app
    # version (which is a git hash) so that browsers don't use an old, cached
    # versions of those resources

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

    app.add_url_rule('/static/' + revision + '/<path:filename>',
                     view_func=StaticView.as_view('static', root=static_root))
    app.add_url_rule('/partials/<path:filename>',
                     view_func=StaticView.as_view('partials',
                                                  root=os.path.join(
                                                      PROJECT_ROOT,
                                                      'partials')))

    app.add_url_rule('/auth/login/',
                     view_func=LoginView.as_view('login',
                                                 authorized_url='authorized'))
    app.add_url_rule('/auth/logout/',
                     view_func=LogoutView.as_view('logout',
                                                  complete_url='index'))
    app.add_url_rule('/auth/complete/',
                     view_func=AuthorizedView.as_view(
                         'authorized',
                         complete_url='index',
                         authorized_url='authorized',
                     ))

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

    # bit of a hack: we use this for creating the v2 blueprint
    return static_root
Exemplo n.º 9
0
def configure_web_routes(app):
    from changes.web.auth import AuthorizedView, LoginView, LogoutView
    from changes.web.index import IndexView
    from changes.web.static import StaticView

    # the path used by the webapp for static resources uses the current app
    # version (which is a git hash) so that browsers don't use an old, cached
    # versions of those resources

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

    app.add_url_rule(
        '/static/' + revision + '/<path:filename>',
        view_func=StaticView.as_view('static', root=static_root))
    app.add_url_rule(
        '/partials/<path:filename>',
        view_func=StaticView.as_view('partials', root=os.path.join(PROJECT_ROOT, 'partials')))

    app.add_url_rule(
        '/auth/login/', view_func=LoginView.as_view('login', authorized_url='authorized'))
    app.add_url_rule(
        '/auth/logout/', view_func=LogoutView.as_view('logout', complete_url='index'))
    app.add_url_rule(
        '/auth/complete/', view_func=AuthorizedView.as_view('authorized',
                                                            complete_url='index',
                                                            authorized_url='authorized',
                                                            ))

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

    # bit of a hack: we use this for creating the v2 blueprint
    return static_root
Exemplo n.º 10
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.º 11
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