Skip to content

Commit b7a5ef9

Browse files
author
Mark Gibbs
committed
2 parents 9c36c2d + 49c6b05 commit b7a5ef9

File tree

8 files changed

+43
-30
lines changed

8 files changed

+43
-30
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,5 @@ templates:
103103

104104
The registration code needs to be in a location
105105
that will be imported into the Django process before any model or template tag attempts to use it. The example Django application
106-
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.
107107

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.1"
44

55
from .dash_wrapper import DjangoDash
66

django_plotly_dash/dash_wrapper.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def as_dash_instance(self):
6060
'''
6161
Form a dash instance, for stateless use of this app
6262
'''
63-
return self.form_dash_instance()
63+
return self.do_form_dash_instance()
6464

6565
def handle_current_state(self):
6666
'Do nothing impl - only matters if state present'
@@ -80,21 +80,23 @@ def get_base_pathname(self, specific_identifier):
8080
app_pathname="%s:%s" % (app_name, main_view_label)
8181
ndid = specific_identifier
8282

83-
try:
84-
full_url = reverse(app_pathname,kwargs={'id':ndid})
85-
except:
86-
full_url = "/%s/" %ndid
87-
83+
full_url = reverse(app_pathname,kwargs={'id':ndid})
8884
return ndid, full_url
8985

90-
def form_dash_instance(self, replacements=None, specific_identifier=None):
86+
def do_form_dash_instance(self, replacements=None, specific_identifier=None):
9187

9288
ndid, base_pathname = self.get_base_pathname(specific_identifier)
89+
return self.form_dash_instance(replacements, ndid, base_pathname)
9390

94-
rd = NotDash(base_pathname=base_pathname,
95-
expanded_callbacks = self._expanded_callbacks,
96-
replacements = replacements,
97-
ndid = ndid)
91+
def form_dash_instance(self, replacements=None, ndid=None, base_pathname=None):
92+
93+
if ndid is None:
94+
ndid = self._uid
95+
96+
rd = WrappedDash(base_pathname=base_pathname,
97+
expanded_callbacks = self._expanded_callbacks,
98+
replacements = replacements,
99+
ndid = ndid)
98100

99101
rd.layout = self.layout
100102

@@ -121,7 +123,7 @@ def expanded_callback(self, output, inputs=[], state=[], events=[]):
121123
self._expanded_callbacks = True
122124
return self.callback(output, inputs, state, events)
123125

124-
class NotFlask:
126+
class PseudoFlask:
125127
def __init__(self):
126128
self.config = {}
127129
self.endpoints = {}
@@ -138,21 +140,24 @@ def before_first_request(self,*args,**kwargs):
138140
def run(self,*args,**kwargs):
139141
pass
140142

141-
class NotDash(Dash):
143+
class WrappedDash(Dash):
142144
def __init__(self, base_pathname=None, replacements = None, ndid=None, expanded_callbacks=False, **kwargs):
143145

144146
self._uid = ndid
145147

146148
self._flask_app = Flask(self._uid)
147-
self._notflask = NotFlask()
149+
self._notflask = PseudoFlask()
148150
self._base_pathname = base_pathname
149151

150152
kwargs['url_base_pathname'] = self._base_pathname
151153
kwargs['server'] = self._notflask
152154

153-
super(NotDash, self).__init__(**kwargs)
155+
super(WrappedDash, self).__init__(**kwargs)
154156

155157
self.css.config.serve_locally = True
158+
self.css.config.serve_locally = False
159+
160+
self.scripts.config.serve_locally = self.css.config.serve_locally
156161

157162
self._adjust_id = False
158163
self._dash_dispatch = not expanded_callbacks
@@ -270,10 +275,10 @@ def _fix_callback_item(self, item):
270275
return item
271276

272277
def callback(self, output, inputs=[], state=[], events=[]):
273-
return super(NotDash, self).callback(self._fix_callback_item(output),
274-
[self._fix_callback_item(x) for x in inputs],
275-
[self._fix_callback_item(x) for x in state],
276-
[self._fix_callback_item(x) for x in events])
278+
return super(WrappedDash, self).callback(self._fix_callback_item(output),
279+
[self._fix_callback_item(x) for x in inputs],
280+
[self._fix_callback_item(x) for x in state],
281+
[self._fix_callback_item(x) for x in events])
277282

278283
def dispatch(self):
279284
import flask

django_plotly_dash/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ def current_state(self):
103103
def as_dash_instance(self):
104104
dd = self._stateless_dash_app()
105105
base = self.current_state()
106-
return dd.form_dash_instance(replacements=base,
107-
specific_identifier=self.slug)
106+
return dd.do_form_dash_instance(replacements=base,
107+
specific_identifier=self.slug)
108108

109109
def _get_base_state(self):
110110
'''

django_plotly_dash/views.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,11 @@ def main_view(request, id, stateless=False, **kwargs):
6262
return HttpResponse(resp)
6363

6464
def component_suites(request, resource=None, component=None, **kwargs):
65-
print("Blagging component suites")
66-
print(kwargs)
6765

6866
eBig = request.GET.urlencode()
6967
if len(eBig) > 0:
70-
redone_url = "/STATIC/%s/%s?%s" %(component, resource, eBig)
68+
redone_url = "/static/dash/%s/%s?%s" %(component, resource, eBig)
7169
else:
72-
redone_url = "/STATIC/%s/%s" %(component, resource)
70+
redone_url = "/static/dash/%s/%s" %(component, resource)
7371

74-
print(redone_url)
75-
76-
return HttpResponseRedirect(redirect_to="/static/someth")
72+
return HttpResponseRedirect(redirect_to=redone_url)

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)