|
| 1 | +#----------------------------------------------------------------------------- |
| 2 | +# Copyright (c) 2012 - 2022, Anaconda, Inc., and Bokeh Contributors. |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# The full license is in the file LICENSE.txt, distributed with this software. |
| 6 | +#----------------------------------------------------------------------------- |
| 7 | + |
| 8 | +#----------------------------------------------------------------------------- |
| 9 | +# Boilerplate |
| 10 | +#----------------------------------------------------------------------------- |
| 11 | +from __future__ import annotations |
| 12 | + |
| 13 | +import logging # isort:skip |
| 14 | +log = logging.getLogger(__name__) |
| 15 | + |
| 16 | +#----------------------------------------------------------------------------- |
| 17 | +# Imports |
| 18 | +#----------------------------------------------------------------------------- |
| 19 | + |
| 20 | +# Standard library imports |
| 21 | +from importlib import import_module |
| 22 | +from typing import List |
| 23 | + |
| 24 | +# External imports |
| 25 | +from django.apps import AppConfig |
| 26 | +from django.conf import settings |
| 27 | + |
| 28 | +# Bokeh imports |
| 29 | +from .routing import Routing, RoutingConfiguration |
| 30 | + |
| 31 | +#----------------------------------------------------------------------------- |
| 32 | +# Globals and constants |
| 33 | +#----------------------------------------------------------------------------- |
| 34 | + |
| 35 | +__all__ = ( |
| 36 | + 'DjangoBokehConfig', |
| 37 | +) |
| 38 | + |
| 39 | +#----------------------------------------------------------------------------- |
| 40 | +# General API |
| 41 | +#----------------------------------------------------------------------------- |
| 42 | + |
| 43 | +class DjangoBokehConfig(AppConfig): |
| 44 | + |
| 45 | + name = label = 'bokeh.server.django' |
| 46 | + |
| 47 | + _routes: RoutingConfiguration | None = None |
| 48 | + |
| 49 | + @property |
| 50 | + def bokeh_apps(self) -> List[Routing]: |
| 51 | + module = settings.ROOT_URLCONF |
| 52 | + url_conf = import_module(module) if isinstance(module, str) else module |
| 53 | + return url_conf.bokeh_apps |
| 54 | + |
| 55 | + @property |
| 56 | + def routes(self) -> RoutingConfiguration: |
| 57 | + if self._routes is None: |
| 58 | + self._routes = RoutingConfiguration(self.bokeh_apps) |
| 59 | + return self._routes |
| 60 | + |
| 61 | +#----------------------------------------------------------------------------- |
| 62 | +# Dev API |
| 63 | +#----------------------------------------------------------------------------- |
| 64 | + |
| 65 | +#----------------------------------------------------------------------------- |
| 66 | +# Private API |
| 67 | +#----------------------------------------------------------------------------- |
| 68 | + |
| 69 | +#----------------------------------------------------------------------------- |
| 70 | +# Code |
| 71 | +#----------------------------------------------------------------------------- |
0 commit comments