From 4b01ee7a50a9bfa88991461bb4a91edc59b48d34 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 24 Feb 2013 13:12:41 +0100 Subject: [PATCH] URL-encoded URLs in FlatPage.get_absolute_url. --- django/contrib/flatpages/models.py | 5 ++--- django/contrib/flatpages/tests/__init__.py | 1 + django/contrib/flatpages/tests/models.py | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 django/contrib/flatpages/tests/models.py diff --git a/django/contrib/flatpages/models.py b/django/contrib/flatpages/models.py index 3a5b4d6135..7378c8c96b 100644 --- a/django/contrib/flatpages/models.py +++ b/django/contrib/flatpages/models.py @@ -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) diff --git a/django/contrib/flatpages/tests/__init__.py b/django/contrib/flatpages/tests/__init__.py index 5dd5e89dca..0805e9dfd6 100644 --- a/django/contrib/flatpages/tests/__init__.py +++ b/django/contrib/flatpages/tests/__init__.py @@ -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 * diff --git a/django/contrib/flatpages/tests/models.py b/django/contrib/flatpages/tests/models.py new file mode 100644 index 0000000000..44666d62b0 --- /dev/null +++ b/django/contrib/flatpages/tests/models.py @@ -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/') + +