views:

40

answers:

1

Hi,

I am having a problem using Djajaxice with international characters...

I have a django template...in that template is the following select:

 <select name="region" id="id" onchange="Dajaxice.crc.regions('my_callback',{'data':this.value});">
         <option value="" selected="selected" ></option>
         {% for region in regions %}
              <option value="{{ region.region }}">{{ region.region }}</option>
         {% endfor %}
    </select>

As you can see on the onchange of the select I am calling the regions function and passing it two parameters. The name of the call back and the selected value

Here is the function in the ajax.py file

def regions(request, data):
    CityList = City.objects.filter(region__exact=data)
    out = "".join(['<option value="%s">%s</option>' % (c.city,c.city) for c in CityList])
    return simplejson.dumps(out)

dajaxice_functions.register(regions)

This works ok and calls, with the relevant data, my JavaScript function in the template with no problems when the name of the region does not have any international characters in it.

Say 'Antalya' for example. However when a region such as 'Muğla' comes along, it doesn't work. On close inspection the variable data contains 'Mu%u011Fla' and I can't seem to get it back to what I assume is the necessary format so that Django can access the model data correctly.

I have used the magic quotes at the top of the page, I have tried using unescaping it with data.decode('string-escape') and shoving it between utf-8 and back..but nothing I try seems to work...

Is this a Dajaxice, Django or python issue...or am I missing something really simple here?

I have been at it two days now, trying to figure this out....so many thanks in advance for any help you may be able to provide.

Cheers

A: 

Ok, fixed this...

So for anyone else using Dajaxice, and using international characters you should change line 10 in the Dajaxice.core.js file from the following:

send_data.push('argv='+escape(JSON.stringify(argv)));

to this:

send_data.push('argv='+encodeURIComponent(JSON.stringify(argv)));

and all works well.

Phew two days and a few hours of life slipped into the murky waters of code.... ... help us all!

Chez