Skip to content

Commit 64448f0

Browse files
Merge pull request #7 from delsim/master
Version 0.2.0
2 parents 7134b2d + b3e2b61 commit 64448f0

File tree

9 files changed

+58
-27
lines changed

9 files changed

+58
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ coverage.xml
5454
*.log
5555
local_settings.py
5656
*/db.sqlite3
57+
demo/static/*
5758

5859
# Flask stuff:
5960
instance/

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ See the source for this project here:
1010
This README file provides a short guide to installing and using the package, and also
1111
outlines how to run the demonstration application.
1212

13-
14-
1513
More detailed information
1614
can be found in the online documentation at
1715
<https://readthedocs.org/projects/django-plotly-dash>
@@ -105,5 +103,5 @@ templates:
105103

106104
The registration code needs to be in a location
107105
that will be imported into the Django process before any model or template tag attempts to use it. The example Django application
108-
in the demo subdirectory achieves this through an import in the main urls.py file; any views.py would also be sufficient.
106+
in the demo subdirectory achieves this through an import in the main `urls.py` file; any `views.py` would also be sufficient.
109107

demo/demo/settings.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,13 @@
120120
# https://docs.djangoproject.com/en/2.0/howto/static-files/
121121

122122
STATIC_URL = '/static/'
123+
STATIC_ROOT = os.path.join(BASE_DIR,'static')
124+
125+
STATICFILES_DIRS = [
126+
]
127+
128+
import dash_core_components as dcc
129+
_rname = os.path.join(os.path.dirname(dcc.__file__),'..')
130+
for dash_module_name in ['dash_core_components','dash_html_components','dash_renderer',]:
131+
STATICFILES_DIRS.append( ("dash/%s"%dash_module_name, os.path.join(_rname,dash_module_name)) )
132+

django_plotly_dash/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22

3-
__version__ = "0.1.0"
3+
__version__ = "0.2.0"
44

55
from .dash_wrapper import DjangoDash
66

django_plotly_dash/dash_wrapper.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,30 @@ def have_current_state_entry(self, wid, key):
7272
'Do nothing impl - only matters if state present'
7373
pass
7474

75-
def form_dash_instance(self, replacements=None, specific_identifier=None):
75+
def get_base_pathname(self, specific_identifier):
7676
if not specific_identifier:
7777
app_pathname = "%s:app-%s"% (app_name, main_view_label)
78+
ndid = self._uid
7879
else:
7980
app_pathname="%s:%s" % (app_name, main_view_label)
81+
ndid = specific_identifier
82+
83+
try:
84+
full_url = reverse(app_pathname,kwargs={'id':ndid})
85+
except:
86+
full_url = "/%s/" %ndid
87+
88+
return ndid, full_url
89+
90+
def form_dash_instance(self, replacements=None, specific_identifier=None):
8091

81-
rd = NotDash(name_root=self._uid,
82-
app_pathname=app_pathname,
92+
ndid, base_pathname = self.get_base_pathname(specific_identifier)
93+
94+
rd = NotDash(base_pathname=base_pathname,
8395
expanded_callbacks = self._expanded_callbacks,
8496
replacements = replacements,
85-
specific_identifier = specific_identifier)
97+
ndid = ndid)
98+
8699
rd.layout = self.layout
87100

88101
for cb, func in self._callback_sets:
@@ -126,22 +139,24 @@ def run(self,*args,**kwargs):
126139
pass
127140

128141
class NotDash(Dash):
129-
def __init__(self, name_root, app_pathname=None, replacements = None, specific_identifier=None, expanded_callbacks=False, **kwargs):
142+
def __init__(self, base_pathname=None, replacements = None, ndid=None, expanded_callbacks=False, **kwargs):
130143

131-
if specific_identifier is not None:
132-
self._uid = specific_identifier
133-
else:
134-
self._uid = name_root
144+
self._uid = ndid
135145

136146
self._flask_app = Flask(self._uid)
137147
self._notflask = NotFlask()
138-
self._base_pathname = reverse(app_pathname,kwargs={'id':self._uid})
148+
self._base_pathname = base_pathname
139149

140150
kwargs['url_base_pathname'] = self._base_pathname
141151
kwargs['server'] = self._notflask
142152

143153
super(NotDash, self).__init__(**kwargs)
144154

155+
self.css.config.serve_locally = True
156+
#self.css.config.serve_locally = False
157+
158+
self.scripts.config.serve_locally = self.css.config.serve_locally
159+
145160
self._adjust_id = False
146161
self._dash_dispatch = not expanded_callbacks
147162
if replacements:
@@ -158,17 +173,16 @@ def use_dash_layout(self):
158173

159174
def augment_initial_layout(self, base_response):
160175
if self.use_dash_layout() and False:
161-
return HttpResponse(base_response.data,
162-
content_type=base_response.mimetype)
176+
return base_response.data, base_response.mimetype
163177
# Adjust the base layout response
164178
baseDataInBytes = base_response.data
165179
baseData = json.loads(baseDataInBytes.decode('utf-8'))
166180
# Walk tree. If at any point we have an element whose id matches, then replace any named values at this level
167181
reworked_data = self.walk_tree_and_replace(baseData)
168182
response_data = json.dumps(reworked_data,
169183
cls=PlotlyJSONEncoder)
170-
return HttpResponse(response_data,
171-
content_type=base_response.mimetype)
184+
185+
return response_data, base_response.mimetype
172186

173187
def walk_tree_and_extract(self, data, target):
174188
if isinstance(data, dict):

django_plotly_dash/urls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.urls import path
22
from django.views.decorators.csrf import csrf_exempt
33

4-
from .views import routes, layout, dependencies, update, main_view
4+
from .views import routes, layout, dependencies, update, main_view, component_suites
55

66
from .app_name import app_name, main_view_label
77

@@ -11,11 +11,13 @@
1111
path('instance/<slug:id>_dash-dependencies', dependencies, name="dependencies"),
1212
path('instance/<slug:id>_dash-update-component', csrf_exempt(update), name="update-component"),
1313
path('instance/<slug:id>', main_view, name=main_view_label),
14+
path('instance/<slug:id>_dash-component-suites/<slug:component>/<resource>', component_suites, name='component-suites'),
1415

1516
path('app/<slug:id>_dash-routes', routes, {'stateless':True}, name="app-routes"),
1617
path('app/<slug:id>_dash-layout', layout, {'stateless':True}, name="app-layout"),
1718
path('app/<slug:id>_dash-dependencies', dependencies, {'stateless':True}, name="app-dependencies"),
1819
path('app/<slug:id>_dash-update-component', csrf_exempt(update), {'stateless':True}, name="app-update-component"),
1920
path('app/<slug:id>', main_view, {'stateless':True}, name='app-%s'%main_view_label),
21+
path('app/<slug:id>_dash-component-suites/<slug:component>/<resource>', component_suites, {'stateless':True}, name='app-component-suites'),
2022
]
2123

django_plotly_dash/views.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.shortcuts import render, get_object_or_404
2-
from django.http import HttpResponse
2+
from django.http import HttpResponse, HttpResponseRedirect
33

44
import json
55

@@ -22,7 +22,9 @@ def layout(request, id, stateless=False, **kwargs):
2222

2323
mFunc = app.locate_endpoint_function('dash-layout')
2424
resp = mFunc()
25-
return app.augment_initial_layout(resp)
25+
response_data, mimetype = app.augment_initial_layout(resp)
26+
return HttpResponse(response_data,
27+
content_type=mimetype)
2628

2729
def update(request, id, stateless=False, **kwargs):
2830
da, app = DashApp.locate_item(id, stateless)
@@ -59,3 +61,12 @@ def main_view(request, id, stateless=False, **kwargs):
5961
resp = mFunc()
6062
return HttpResponse(resp)
6163

64+
def component_suites(request, resource=None, component=None, **kwargs):
65+
66+
eBig = request.GET.urlencode()
67+
if len(eBig) > 0:
68+
redone_url = "/static/dash/%s/%s?%s" %(component, resource, eBig)
69+
else:
70+
redone_url = "/static/dash/%s/%s" %(component, resource)
71+
72+
return HttpResponseRedirect(redirect_to=redone_url)

docs/index.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,3 @@ Contents
2222
models_and_state
2323

2424

25-
Indices and tables
26-
------------------
27-
28-
* :ref:`genindex`
29-
* :ref:`modindex`
30-
* :ref:`search`

prepare_demo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ source env/bin/activate
44
cd demo
55
./manage.py migrate
66
./manage.py shell < configdb.py # Add a superuser if needed
7+
./manage.py collectstatic -i "*.py" -i "*.pyc" --noinput --link
78
./manage.py runserver

0 commit comments

Comments
 (0)