Commit 37b42a81 authored by Yohan Boniface's avatar Yohan Boniface

First shot in allowing unicode in URLs (cf #76)

Problem:

In [14]: print reverse("map", kwargs={'slug': u"академический", 'pk': 729})
/en-us/map/%D0%B0%D0%BA%D0%B0%D0%B4%D0%B5%D0%BC%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B8%D0%B9_729
parent 5ca4add3
......@@ -3,10 +3,10 @@ import urllib2
from django import forms
from django.contrib.gis.geos import Point
from django.utils.translation import ugettext_lazy as _
from django.template.defaultfilters import slugify
from django.conf import settings
from vectorformats.formats import geojson, kml, gpx, csv
from slugify import slugify
from .models import Map, Category, Polyline, Polygon, Marker
......
# -*- coding:utf-8 -*-
import os
from django.test import TransactionTestCase
......@@ -46,6 +48,24 @@ class MapViews(BaseTest):
self.assertEqual(created_map.tilelayers.count(), 1)
self.assertEqual(created_map.tilelayers.all()[0], self.tilelayer)
def test_map_creation_should_allow_unicode_names(self):
url = reverse('map_add')
# POST only mendatory fields
name = u'Академический'
post_data = {
'name': name,
'licence': self.licence.pk
}
self.client.login(username=self.user.username, password="123123")
response = self.client.post(url, post_data)
self.assertEqual(response.status_code, 200)
json = simplejson.loads(response.content)
created_map = Map.objects.latest('pk')
self.assertEqual(json['redirect'], created_map.get_absolute_url())
self.assertEqual(created_map.name, name)
# Lower case of the russian original name
self.assertEqual(created_map.slug, u"академический")
def test_quick_update_GET(self):
url = reverse('map_update', kwargs={'map_id': self.map.pk})
self.client.login(username=self.user.username, password="123123")
......
......@@ -436,7 +436,7 @@ class EmbedMap(DetailView):
site_url = (settings.SHORT_SITE_URL if hasattr(settings, 'SHORT_SITE_URL')
else settings.SITE_URL if hasattr(settings, 'SITE_URL')
else 'http://%s' % self.request.META['HTTP_HOST'])
iframe_url = map_url = '%s%s' % (site_url, self.object.get_absolute_url())
iframe_url = map_url = u'%s%s' % (site_url, self.object.get_absolute_url())
qs_kwargs = {
'allowEdit': 0,
'embedControl': 0,
......@@ -447,9 +447,9 @@ class EmbedMap(DetailView):
'scaleControl': 0,
'miniMap': 0,
}
query_string = "&".join("%s=%s" % (k, v) for k, v in qs_kwargs.iteritems())
iframe_url = "%s?%s" % (iframe_url, query_string)
map_short_url = "%s%s" % (site_url, reverse_lazy('map_short_url', kwargs={'pk': self.object.pk}))
query_string = u"&".join("%s=%s" % (k, v) for k, v in qs_kwargs.iteritems())
iframe_url = u"%s?%s" % (iframe_url, query_string)
map_short_url = u"%s%s" % (site_url, reverse_lazy('map_short_url', kwargs={'pk': self.object.pk}))
kwargs.update({
'map_url': map_url,
'iframe_url': iframe_url,
......
......@@ -3,4 +3,5 @@ psycopg2>=2.4.5
PIL
git+git://github.com/yohanboniface/vectorformats.git@leafletstorage
South
simplejson
\ No newline at end of file
simplejson
unicode-slugify==0.1
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment