1- from django .shortcuts import render
1+ from django .shortcuts import render , get_object_or_404
22from django .http import HttpResponse
33
44import json
55
66from .models import DashApp
7+ from .dash_wrapper import get_stateless_by_name
78
89def routes (* args ,** kwargs ):
9- pass
10+ raise NotImplementedError
11+
12+ def dependencies (request , id , stateless = False , ** kwargs ):
13+ if stateless :
14+ da = get_stateless_by_name (id )
15+ else :
16+ da = get_object_or_404 (DashApp ,slug = id )
17+
18+ app = da .as_dash_instance ()
1019
11- def dependencies (request , id , ** kwargs ):
12- app = DashApp .get_app_instance (id )
1320 with app .app_context ():
1421 mFunc = app .locate_endpoint_function ('dash-dependencies' )
1522 resp = mFunc ()
1623 return HttpResponse (resp .data ,
1724 content_type = resp .mimetype )
1825
19- def layout (request , id , ** kwargs ):
20- app = DashApp .get_app_instance (id )
26+ def layout (request , id , stateless = False , ** kwargs ):
27+ if stateless :
28+ da = get_stateless_by_name (id )
29+ else :
30+ da = get_object_or_404 (DashApp ,slug = id )
31+ app = da .as_dash_instance ()
32+
2133 mFunc = app .locate_endpoint_function ('dash-layout' )
2234 resp = mFunc ()
2335 return app .augment_initial_layout (resp )
2436
25- def update (request , id , ** kwargs ):
26- app = DashApp .get_app_instance (id )
37+ def update (request , id , stateless = False , ** kwargs ):
38+ if stateless :
39+ da = get_stateless_by_name (id )
40+ else :
41+ da = get_object_or_404 (DashApp ,slug = id )
42+ app = da .as_dash_instance ()
43+
2744 rb = json .loads (request .body .decode ('utf-8' ))
2845
2946 if app .use_dash_dispatch ():
@@ -44,8 +61,13 @@ def update(request, id, **kwargs):
4461 return HttpResponse (resp .data ,
4562 content_type = resp .mimetype )
4663
47- def main_view (request , id , ** kwargs ):
48- app = DashApp .get_app_instance (id )
64+ def main_view (request , id , stateless = False , ** kwargs ):
65+ if stateless :
66+ da = get_stateless_by_name (id )
67+ else :
68+ da = get_object_or_404 (DashApp ,slug = id )
69+ app = da .as_dash_instance ()
70+
4971 mFunc = app .locate_endpoint_function ()
5072 resp = mFunc ()
5173 return HttpResponse (resp )
0 commit comments