URL-encoded URLs in FlatPage.get_absolute_url.

This commit is contained in:
Aymeric Augustin 2013-02-24 13:12:41 +01:00
parent e4ee3d8fca
commit 4b01ee7a50
3 changed files with 18 additions and 3 deletions

View File

@ -3,8 +3,7 @@ from __future__ import unicode_literals
from django.db import models
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import python_2_unicode_compatible
from django.utils.encoding import iri_to_uri, python_2_unicode_compatible
@python_2_unicode_compatible
class FlatPage(models.Model):
@ -27,4 +26,4 @@ class FlatPage(models.Model):
return "%s -- %s" % (self.url, self.title)
def get_absolute_url(self):
return self.url
return iri_to_uri(self.url)

View File

@ -1,5 +1,6 @@
from django.contrib.flatpages.tests.csrf import *
from django.contrib.flatpages.tests.forms import *
from django.contrib.flatpages.tests.models import *
from django.contrib.flatpages.tests.middleware import *
from django.contrib.flatpages.tests.templatetags import *
from django.contrib.flatpages.tests.views import *

View File

@ -0,0 +1,15 @@
# coding: utf-8
from __future__ import unicode_literals
from django.contrib.flatpages.models import FlatPage
from django.test import TestCase
class FlatpageModelTests(TestCase):
def test_get_absolute_url_urlencodes(self):
pf = FlatPage(title="Café!", url='/café/')
self.assertEqual(pf.get_absolute_url(), '/caf%C3%A9/')