Skip to content

Commit def91a6

Browse files
author
Mark Gibbs
committed
More rationalisation for the process to locate stateless apps
1 parent ae896fb commit def91a6

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

django_plotly_dash/dash_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def add_usable_app(name, app):
2121
usable_apps[name] = app
2222
return name
2323

24-
def get_stateless_by_name(name):
24+
def get_local_stateless_by_name(name):
2525
'''
2626
Locate a registered dash app by name, and return a DjangoDash instance encapsulating the app.
2727
'''

django_plotly_dash/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django.utils.text import slugify
44
from django.shortcuts import get_object_or_404
55

6-
from .dash_wrapper import get_stateless_by_name
6+
from .dash_wrapper import get_local_stateless_by_name
77

88
import json
99

@@ -26,6 +26,9 @@ class StatelessAppAdmin(admin.ModelAdmin):
2626
list_display = ['app_name','slug',]
2727
list_filter = ['app_name','slug',]
2828

29+
def get_stateless_by_name(name):
30+
return get_local_stateless_by_name(name)
31+
2932
class DashApp(models.Model):
3033
'''
3134
An instance of this model represents a dash application and its internal state

django_plotly_dash/templatetags/plotly_dash.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
register = template.Library()
55

6-
from django_plotly_dash.models import DashApp, get_stateless_by_name
6+
from django_plotly_dash.models import DashApp
77

88
@register.inclusion_tag("django_plotly_dash/plotly_item.html", takes_context=True)
99
def plotly_app(context, name=None, slug=None, da=None, ratio=0.1, use_frameborder=False):
@@ -25,12 +25,16 @@ def plotly_app(context, name=None, slug=None, da=None, ratio=0.1, use_frameborde
2525
height: 100%;
2626
"""
2727

28+
app = None
29+
2830
if name is not None:
29-
da = get_stateless_by_name(name)
31+
da, app = DashApp.locate_item(name, stateless=True)
3032

3133
if slug is not None:
32-
da = get_object_or_404(DashApp,slug=slug)
34+
da, app = DashApp.locate_item(slug, stateless=False)
35+
36+
if not app:
37+
app = da.as_dash_instance()
3338

34-
app = da.as_dash_instance()
3539
return locals()
3640

0 commit comments

Comments
 (0)