#-----------------------------------------------------------------------------# Copyright (c) 2012 - 2022, Anaconda, Inc., and Bokeh Contributors.# All rights reserved.## The full license is in the file LICENSE.txt, distributed with this software.#-----------------------------------------------------------------------------''' Provide a Request handler that lists the application (if more than one)or (if only one) redirects to the route of that applications.'''#-----------------------------------------------------------------------------# Boilerplate#-----------------------------------------------------------------------------from__future__importannotationsimportlogging# isort:skiplog=logging.getLogger(__name__)#-----------------------------------------------------------------------------# Imports#-----------------------------------------------------------------------------# External importsfromtornado.webimportRequestHandler,authenticated# Bokeh importsfrom.auth_mixinimportAuthMixin#-----------------------------------------------------------------------------# Globals and constants#-----------------------------------------------------------------------------__all__=('RootHandler',)#-----------------------------------------------------------------------------# General API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Dev API#-----------------------------------------------------------------------------
[docs]classRootHandler(AuthMixin,RequestHandler):''' Implements a custom Tornado handler to display the available applications If only one application it redirects to that application route '''
@authenticatedasyncdefget(self,*args,**kwargs):prefix=""ifself.prefixisNoneelseself.prefixifself.use_redirectandlen(self.applications)==1:app_names=list(self.applications.keys())redirect_to=prefix+app_names[0]self.redirect(redirect_to)else:index="app_index.html"ifself.indexisNoneelseself.indexself.render(index,prefix=prefix,items=sorted(self.applications.keys()))# NOTE: The methods below exist on both AuthMixin and RequestHandler. This# makes it explicit which of the versions is intended to be called.get_login_url=AuthMixin.get_login_urlget_current_user=AuthMixin.get_current_userprepare=AuthMixin.prepare