diff --git a/demo/demo/settings.py b/demo/demo/settings.py index fba8591..207198c 100644 --- a/demo/demo/settings.py +++ b/demo/demo/settings.py @@ -138,7 +138,7 @@ "cache_arguments" : True, # True for cache, False for session-based argument propagation - #"serve_locally" : True, # True to serve assets locally, False to use their unadulterated urls (eg a CDN) + "serve_locally" : True, # True to serve assets locally, False to use their unadulterated urls (eg a CDN) "stateless_loader" : "demo.scaffold.stateless_app_loader", } diff --git a/django_plotly_dash/dash_wrapper.py b/django_plotly_dash/dash_wrapper.py index e62c11b..ec4317c 100644 --- a/django_plotly_dash/dash_wrapper.py +++ b/django_plotly_dash/dash_wrapper.py @@ -223,7 +223,7 @@ def get_asset_static_url(self, asset_path): module_name = self.caller_module.__name__ return static_asset_path(module_name, asset_path) - def as_dash_instance(self, cache_id=None): + def as_dash_instance(self, cache_id=None, can_ignore_initial_state=False): ''' Form a dash instance, for stateless use of this app ''' diff --git a/django_plotly_dash/models.py b/django_plotly_dash/models.py index 6971d6c..d4d6b73 100644 --- a/django_plotly_dash/models.py +++ b/django_plotly_dash/models.py @@ -188,10 +188,13 @@ def current_state(self): setattr(self, '_current_state_hydrated_changed', False) return c_state - def as_dash_instance(self, cache_id=None): + def as_dash_instance(self, cache_id=None, can_ignore_initial_state=False): 'Return a dash application instance for this model instance' dash_app = self.stateless_app.as_dash_app() # pylint: disable=no-member - base = self.current_state() + if can_ignore_initial_state: + base = None + else: + base = self.current_state() return dash_app.do_form_dash_instance(replacements=base, specific_identifier=self.slug, cache_id=cache_id) @@ -220,7 +223,7 @@ def populate_values(self): self.base_state = json.dumps(obj) @staticmethod - def locate_item(ident, stateless=False, cache_id=None): + def locate_item(ident, stateless=False, cache_id=None, can_ignore_initial_state=False): '''Locate a dash application, given either the slug of an instance or the name for a stateless app''' if stateless: @@ -228,7 +231,7 @@ def locate_item(ident, stateless=False, cache_id=None): else: dash_app = get_object_or_404(DashApp, slug=ident) - app = dash_app.as_dash_instance(cache_id=cache_id) + app = dash_app.as_dash_instance(cache_id=cache_id, can_ignore_initial_state=can_ignore_initial_state) return dash_app, app class DashAppAdmin(admin.ModelAdmin): diff --git a/django_plotly_dash/tests.py b/django_plotly_dash/tests.py index 1be36ae..3ee6299 100644 --- a/django_plotly_dash/tests.py +++ b/django_plotly_dash/tests.py @@ -292,7 +292,8 @@ def test_local_serving(settings): 'Test local serve settings' from django_plotly_dash.util import serve_locally, static_asset_root, full_asset_path - assert serve_locally() == settings.DEBUG + # Now default to serving all files locally + assert serve_locally() == True assert static_asset_root() == 'dpd/assets' assert full_asset_path('fred.jim', 'harry') == 'dpd/assets/fred/jim/harry' diff --git a/django_plotly_dash/views.py b/django_plotly_dash/views.py index dbe4106..d83def9 100644 --- a/django_plotly_dash/views.py +++ b/django_plotly_dash/views.py @@ -78,7 +78,7 @@ def update(request, ident, stateless=False, **kwargs): def _update(request, ident, stateless=False, **kwargs): 'Generate update json response' - dash_app, app = DashApp.locate_item(ident, stateless) + dash_app, app = DashApp.locate_item(ident, stateless, can_ignore_initial_state=True) try: request_body = json.loads(request.body.decode('utf-8')) @@ -191,4 +191,3 @@ def add_stateless_apps(request, **kwargs): """Check all registered stateless apps and create ORM entries that are missing""" check_stateless_loaded() return redirect('admin:django_plotly_dash_statelessapp_changelist') -