areski / django-nvd3

Django wrapper for nvd3 - It's time for beautiful charts
Other
416 stars 124 forks source link

slugify can't decode django.utils.safestring.SafeText #29

Closed jayme-github closed 10 years ago

jayme-github commented 10 years ago

areski/python-nvd3@dd7077d9af266184f7c75e80c78522e6614c9a0f adds a slugify call around the container name. From django (1.7), this value is provided as django.utils.safestring.SafeText instance which is not detected as unicode by slugify causing the following traceback:

  File "django-nvd3/django_nvd3/templatetags/nvd3_tags.py", line 48, in load_chart
    chart = eval(chart_type)(**kw_extra)
  File python-nvd3/nvd3/pieChart.py", line 79, in __init__
    NVD3Chart.__init__(self, **kwargs)
  File "python-nvd3/nvd3/NVD3Chart.py", line 136, in __init__
    self.name = slugify(kwargs.get('name', self.model))
  File "local/lib/python2.7/site-packages/slugify/__init__.py", line 60, in slugify
    text = unicode(text, 'utf-8', 'ignore')
TypeError: decoding Unicode is not supported

Don't know if this is okay for python3:

diff --git a/django_nvd3/templatetags/nvd3_tags.py b/django_nvd3/templatetags/nvd3_tags.py
index e76af39..cd096ca 100644
--- a/django_nvd3/templatetags/nvd3_tags.py
+++ b/django_nvd3/templatetags/nvd3_tags.py
@@ -42,7 +42,7 @@ def load_chart(chart_type, series, container, kw_extra, *args, **kwargs):
     if not 'tag_script_js' in kw_extra:
         kw_extra['tag_script_js'] = True
     # set the container name
-    kw_extra['name'] = container
+    kw_extra['name'] = unicode(container)

     # Build chart
     chart = eval(chart_type)(**kw_extra)
@@ -97,7 +97,7 @@ def include_container(include_container, height=400, width=600):
         * ``width`` - Chart width
     """
     chart = NVD3Chart()
-    chart.name = include_container
+    chart.name = unicode(include_container)
     chart.set_graph_height(height)
     chart.set_graph_width(width)
     chart.buildcontainer()
areski commented 10 years ago

could you send a pull request for this?

jayme-github commented 10 years ago

Shure but I have no idea how to merge it with this issue :/

areski commented 10 years ago

I merged but you raised an other issue, we don't support python3 :( neither python-slugify does, we should put some energy on this :)