From da140357a1c382c85e4c154b20c842bf655383e5 Mon Sep 17 00:00:00 2001
From: sdementen <sdementen@users.noreply.github.com>
Date: Thu, 18 Mar 2021 03:05:47 +0100
Subject: [PATCH] fix #328 by: (#329)

- converting initial_arguments given as json string into a dict in `store_initial_arguments`
- add in the test of the template tag a call to the _dash-layout to ensure the initial_arguments are parsed properly

Co-authored-by: GFJ138 <sebastien.dementen@engie.com>
---
 demo/demo/tests/test_dpd_demo.py | 8 +++++++-
 django_plotly_dash/util.py       | 6 +++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/demo/demo/tests/test_dpd_demo.py b/demo/demo/tests/test_dpd_demo.py
index 997dba7..52c55db 100644
--- a/demo/demo/tests/test_dpd_demo.py
+++ b/demo/demo/tests/test_dpd_demo.py
@@ -22,11 +22,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 
 '''
+import re
 
 import pytest
-
 from django.urls import reverse
 
+
 @pytest.mark.django_db
 def test_template_tag_use(client):
     'Check use of template tag'
@@ -39,6 +40,11 @@ def test_template_tag_use(client):
         assert response.content
         assert response.status_code == 200
 
+        for src in re.findall('iframe src="(.*?)"', response.content.decode("utf-8")):
+            response = client.get(src + "_dash-layout")
+            assert response.status_code == 200, ""
+
+
 @pytest.mark.django_db
 def test_add_to_session(client):
     'Check use of session variable access helper'
diff --git a/django_plotly_dash/util.py b/django_plotly_dash/util.py
index 5246c86..03fc89d 100644
--- a/django_plotly_dash/util.py
+++ b/django_plotly_dash/util.py
@@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 
 '''
-
+import json
 import uuid
 
 from django.conf import settings
@@ -75,6 +75,10 @@ def store_initial_arguments(request, initial_arguments=None):
     if initial_arguments is None:
         return None
 
+    # convert to dict is json string
+    if isinstance(initial_arguments, str):
+        initial_arguments = json.loads(initial_arguments)
+
     # Generate a cache id
     cache_id = "dpd-initial-args-%s" % str(uuid.uuid4()).replace('-', '')
 
-- 
GitLab