Skip to content

Commit 208095e

Browse files
committed
Add bokeh_django module from bokeh core
1 parent d3dc726 commit 208095e

File tree

5 files changed

+614
-0
lines changed

5 files changed

+614
-0
lines changed

bokeh_django/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Bokeh imports
2+
from bokeh.util.dependencies import import_required
3+
4+
# Bokeh imports
5+
from .apps import DjangoBokehConfig
6+
from .routing import autoload, directory, document
7+
from .static import static_extensions
8+
9+
import_required("django", "django is required by bokeh.server.django")
10+
import_required("channels", "The package channels is required by bokeh.server.django and must be installed")
11+
12+
default_app_config = "bokeh.server.django.DjangoBokehConfig"

bokeh_django/apps.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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

Comments
 (0)