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
def configure_web_routes(app): from changes.web.auth import AuthorizedView, LoginView, LogoutView # 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( '/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', )) configure_default(app)
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)
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
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)
def configure_web_routes(app): from changes.web.auth import AuthorizedView, LoginView, LogoutView # 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('/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', )) configure_default(app)
def get(self, path=''): # get user options, e.g. colorblind current_user = get_current_user() user_options = {} if current_user: user_options = dict( db.session.query( ItemOption.name, ItemOption.value, ).filter(ItemOption.item_id == current_user.id, )) statsreporter.stats().incr('homepage_view') if current_app.config['SENTRY_DSN'] and False: parsed = urlparse.urlparse(current_app.config['SENTRY_DSN']) dsn = '%s://%s@%s/%s' % ( parsed.scheme.rsplit('+', 1)[-1], parsed.username, parsed.hostname + (':%s' % (parsed.port, ) if parsed.port else ''), parsed.path, ) else: dsn = None # variables to ship down to the webapp use_another_host = current_app.config['WEBAPP_USE_ANOTHER_HOST'] # if we have custom js, embed it in the html (making sure we # only do one file read in prod). fetch_custom_js = (current_app.config['WEBAPP_CUSTOM_JS'] and (current_app.debug or not IndexView.custom_js)) if fetch_custom_js: IndexView.custom_js = open( current_app.config['WEBAPP_CUSTOM_JS']).read() disable_custom = request.args and "disable_custom" in request.args return render_template( 'webapp.html', **{ 'SENTRY_PUBLIC_DSN': dsn, 'RELEASE_INFO': changes.get_revision_info(), 'WEBAPP_USE_ANOTHER_HOST': use_another_host, 'WEBAPP_CUSTOM_JS': (IndexView.custom_js if not disable_custom else None), 'USE_PACKAGED_JS': not current_app.debug, 'HAS_CUSTOM_CSS': (current_app.config['WEBAPP_CUSTOM_CSS'] and not disable_custom), 'IS_DEBUG': current_app.debug, 'PHABRICATOR_LINK_HOST': current_app.config['PHABRICATOR_LINK_HOST'], 'COLORBLIND': (user_options.get('user.colorblind') and user_options.get('user.colorblind') != '0'), })
def get(self, path=''): # get user options, e.g. colorblind current_user = get_current_user() user_options = {} if current_user: user_options = dict(db.session.query( ItemOption.name, ItemOption.value, ).filter( ItemOption.item_id == current_user.id, )) statsreporter.stats().incr('homepage_view') if current_app.config['SENTRY_DSN'] and False: parsed = urlparse.urlparse(current_app.config['SENTRY_DSN']) dsn = '%s://%s@%s/%s' % ( parsed.scheme.rsplit('+', 1)[-1], parsed.username, parsed.hostname + (':%s' % (parsed.port,) if parsed.port else ''), parsed.path, ) else: dsn = None # variables to ship down to the webapp use_another_host = current_app.config['WEBAPP_USE_ANOTHER_HOST'] # if we have custom js, embed it in the html (making sure we # only do one file read in prod). fetch_custom_js = (current_app.config['WEBAPP_CUSTOM_JS'] and (current_app.debug or not IndexView.custom_js)) if fetch_custom_js: IndexView.custom_js = open(current_app.config['WEBAPP_CUSTOM_JS']).read() disable_custom = request.args and "disable_custom" in request.args # use new react code if self.use_v2: return render_template('webapp.html', **{ 'SENTRY_PUBLIC_DSN': dsn, 'RELEASE_INFO': changes.get_revision_info(), 'WEBAPP_USE_ANOTHER_HOST': use_another_host, 'WEBAPP_CUSTOM_JS': (IndexView.custom_js if not disable_custom else None), 'USE_PACKAGED_JS': not current_app.debug, 'HAS_CUSTOM_CSS': (current_app.config['WEBAPP_CUSTOM_CSS'] and not disable_custom), 'IS_DEBUG': current_app.debug, 'PHABRICATOR_HOST': current_app.config['PHABRICATOR_HOST'], 'COLORBLIND': (user_options.get('user.colorblind') and user_options.get('user.colorblind') != '0'), }) return render_template('index.html', **{ 'SENTRY_PUBLIC_DSN': dsn, 'VERSION': changes.get_version(), 'WEBAPP_USE_ANOTHER_HOST': use_another_host })
def get(self, path=""): # get user options, e.g. colorblind current_user = get_current_user() user_options = {} if current_user: user_options = dict( db.session.query(ItemOption.name, ItemOption.value).filter(ItemOption.item_id == current_user.id) ) statsreporter.stats().incr("homepage_view") if current_app.config["SENTRY_DSN"] and False: parsed = urlparse.urlparse(current_app.config["SENTRY_DSN"]) dsn = "%s://%s@%s/%s" % ( parsed.scheme.rsplit("+", 1)[-1], parsed.username, parsed.hostname + (":%s" % (parsed.port,) if parsed.port else ""), parsed.path, ) else: dsn = None # variables to ship down to the webapp use_another_host = current_app.config["WEBAPP_USE_ANOTHER_HOST"] # if we have custom js, embed it in the html (making sure we # only do one file read in prod). fetch_custom_js = current_app.config["WEBAPP_CUSTOM_JS"] and (current_app.debug or not IndexView.custom_js) if fetch_custom_js: IndexView.custom_js = open(current_app.config["WEBAPP_CUSTOM_JS"]).read() disable_custom = request.args and "disable_custom" in request.args # use new react code if self.use_v2: return render_template( "webapp.html", **{ "SENTRY_PUBLIC_DSN": dsn, "RELEASE_INFO": changes.get_revision_info(), "WEBAPP_USE_ANOTHER_HOST": use_another_host, "WEBAPP_CUSTOM_JS": (IndexView.custom_js if not disable_custom else None), "USE_PACKAGED_JS": not current_app.debug, "HAS_CUSTOM_CSS": (current_app.config["WEBAPP_CUSTOM_CSS"] and not disable_custom), "IS_DEBUG": current_app.debug, "PHABRICATOR_LINK_HOST": current_app.config["PHABRICATOR_LINK_HOST"], "COLORBLIND": (user_options.get("user.colorblind") and user_options.get("user.colorblind") != "0"), } ) return render_template( "index.html", **{"SENTRY_PUBLIC_DSN": dsn, "VERSION": changes.get_version(), "WEBAPP_USE_ANOTHER_HOST": use_another_host} )
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') ]
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
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
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
def get(self, path=""): statsreporter.stats().incr("homepage_view") if current_app.config["SENTRY_DSN"] and False: parsed = urlparse.urlparse(current_app.config["SENTRY_DSN"]) dsn = "%s://%s@%s/%s" % ( parsed.scheme.rsplit("+", 1)[-1], parsed.username, parsed.hostname + (":%s" % (parsed.port,) if parsed.port else ""), parsed.path, ) else: dsn = None # variables to ship down to the webapp webapp_use_another_host = current_app.config["WEBAPP_USE_ANOTHER_HOST"] # note that we're only shipping down the filename! webapp_customized_content = None if current_app.config["WEBAPP_CUSTOMIZED_CONTENT_FILE"]: webapp_customized_content = open(current_app.config["WEBAPP_CUSTOMIZED_CONTENT_FILE"]).read() # use new react code if self.use_v2: return render_template( "webapp.html", **{ "SENTRY_PUBLIC_DSN": dsn, "RELEASE_INFO": changes.get_revision_info(), "WEBAPP_USE_ANOTHER_HOST": webapp_use_another_host, "WEBAPP_CUSTOMIZED_CONTENT": webapp_customized_content, "USE_PACKAGED_JS": not current_app.debug, "IS_DEBUG": current_app.debug, } ) return render_template( "index.html", **{ "SENTRY_PUBLIC_DSN": dsn, "VERSION": changes.get_version(), "WEBAPP_USE_ANOTHER_HOST": webapp_use_another_host, } )
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
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
def get(self, path=''): statsreporter.stats().incr('homepage_view') if current_app.config['SENTRY_DSN'] and False: parsed = urlparse.urlparse(current_app.config['SENTRY_DSN']) dsn = '%s://%s@%s/%s' % ( parsed.scheme.rsplit('+', 1)[-1], parsed.username, parsed.hostname + (':%s' % (parsed.port,) if parsed.port else ''), parsed.path, ) else: dsn = None # variables to ship down to the webapp use_another_host = current_app.config['WEBAPP_USE_ANOTHER_HOST'] # if we have custom js, embed it in the html (making sure we # only do one file read in prod). fetch_custom_js = (current_app.config['WEBAPP_CUSTOM_JS'] and (current_app.debug or not IndexView.custom_js)) if fetch_custom_js: IndexView.custom_js = open(current_app.config['WEBAPP_CUSTOM_JS']).read() # use new react code if self.use_v2: return render_template('webapp.html', **{ 'SENTRY_PUBLIC_DSN': dsn, 'RELEASE_INFO': changes.get_revision_info(), 'WEBAPP_USE_ANOTHER_HOST': use_another_host, 'WEBAPP_CUSTOM_JS': IndexView.custom_js, 'USE_PACKAGED_JS': not current_app.debug, 'IS_DEBUG': current_app.debug }) return render_template('index.html', **{ 'SENTRY_PUBLIC_DSN': dsn, 'VERSION': changes.get_version(), 'WEBAPP_USE_ANOTHER_HOST': use_another_host })
def get(self, path=''): statsreporter.stats().incr('homepage_view') if current_app.config['SENTRY_DSN'] and False: parsed = urlparse.urlparse(current_app.config['SENTRY_DSN']) dsn = '%s://%s@%s/%s' % ( parsed.scheme.rsplit('+', 1)[-1], parsed.username, parsed.hostname + (':%s' % (parsed.port, ) if parsed.port else ''), parsed.path, ) else: dsn = None # variables to ship down to the webapp webapp_use_another_host = current_app.config['WEBAPP_USE_ANOTHER_HOST'] # note that we're only shipping down the filename! webapp_customized_content = None if current_app.config['WEBAPP_CUSTOMIZED_CONTENT_FILE']: webapp_customized_content = open( current_app.config['WEBAPP_CUSTOMIZED_CONTENT_FILE']).read() # use new react code if self.use_v2: return render_template( 'webapp.html', **{ 'SENTRY_PUBLIC_DSN': dsn, 'RELEASE_INFO': changes.get_revision_info(), 'WEBAPP_USE_ANOTHER_HOST': webapp_use_another_host, 'WEBAPP_CUSTOMIZED_CONTENT': webapp_customized_content, 'USE_PACKAGED_JS': not current_app.debug, 'IS_DEBUG': current_app.debug }) return render_template( 'index.html', **{ 'SENTRY_PUBLIC_DSN': dsn, 'VERSION': changes.get_version(), 'WEBAPP_USE_ANOTHER_HOST': webapp_use_another_host })
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