jorgebastida / django-dajax

Easy to use library to create asynchronous presentation logic with django and dajaxice
http://dajaxproject.com/
BSD 3-Clause "New" or "Revised" License
346 stars 99 forks source link

UnicodeEncodeError: 'ascii' codec can't encode characters in _clean method #4

Closed spoof closed 14 years ago

spoof commented 14 years ago

When i use localized data in my forms with Dajax i get error:

  UnicodeEncodeError: 'ascii' codec can't encode characters 

in dajax/core/Dajax.py on _clean(self, data):

   return str(data).replace('\n','').replace('\r','')

Maybe it should use 'unicode()' instead of 'str()' ?

jorgebastida commented 14 years ago

Hello spoof, Probably your fix will solve the problem, but can you share some example to reproduce the problem?

spoof commented 14 years ago

Hello,

It happens when dajax returns data and this data contains with non ascii chars. In my example i use default <option></option> tag with {% trans %} template tag:

ajax.py:

def ajax_selectbox(request, _id):
  dajax = Dajax()
  objs = SomeModel.objects.filter(id=_id)
  out = render_to_string('template.html', {'objs' : objs})
  dajax.assign('#options', 'innerHTML', out)
  return dajax.json()

template.html:

{% load i18n %}
<option value="">{% trans "Please select model" %}</option>
....
jorgebastida commented 14 years ago

After some testing, seems to work well. Changes will be released in 0.8.4

jorgebastida commented 14 years ago

Fixed in dajaxice-0.1.3