Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #14164 -- Ensure that sitemap priorities aren't rendere…

…d with localized numerical formats. Thanks to dokterbob for the report, and vung for the draft patch.

Backport of r13644 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13646 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 38e9ca1e09bcbfdb5bf3c5bb906b7ba13efed3c6 1 parent 2370a10
Russell Keith-Magee authored August 27, 2010
2  django/contrib/sitemaps/__init__.py
@@ -69,7 +69,7 @@ def get_urls(self, page=1):
69 69
                 'location':   loc,
70 70
                 'lastmod':    self.__get('lastmod', item, None),
71 71
                 'changefreq': self.__get('changefreq', item, None),
72  
-                'priority':   self.__get('priority', item, None)
  72
+                'priority':   str(self.__get('priority', item, ''))
73 73
             }
74 74
             urls.append(url_info)
75 75
         return urls
1  django/contrib/sitemaps/tests/__init__.py
... ...
@@ -0,0 +1 @@
  1
+from django.contrib.sitemaps.tests.basic import *
39  django/contrib/sitemaps/tests/basic.py
... ...
@@ -0,0 +1,39 @@
  1
+from datetime import date
  2
+from django.conf import settings
  3
+from django.test import TestCase
  4
+from django.utils.formats import localize
  5
+from django.utils.translation import activate
  6
+
  7
+
  8
+class SitemapTests(TestCase):
  9
+    urls = 'django.contrib.sitemaps.tests.urls'
  10
+
  11
+    def setUp(self):
  12
+        self.old_USE_L10N = settings.USE_L10N
  13
+
  14
+    def tearDown(self):
  15
+        settings.USE_L10N = self.old_USE_L10N
  16
+
  17
+    def test_simple_sitemap(self):
  18
+        "A simple sitemap can be rendered"
  19
+        # Retrieve the sitemap.
  20
+        response = self.client.get('/sitemaps/sitemap.xml')
  21
+        # Check for all the important bits:
  22
+        self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
  23
+<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  24
+<url><loc>http://example.com/ticket14164</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
  25
+</urlset>
  26
+""" % date.today().strftime('%Y-%m-%d'))
  27
+
  28
+    def test_localized_priority(self):
  29
+        "The priority value should not be localized (Refs #14164)"
  30
+        # Localization should be active
  31
+        settings.USE_L10N = True
  32
+        activate('fr')
  33
+        self.assertEqual(u'0,3', localize(0.3))
  34
+
  35
+        # Retrieve the sitemap. Check that priorities
  36
+        # haven't been rendered in localized format
  37
+        response = self.client.get('/sitemaps/sitemap.xml')
  38
+        self.assertContains(response, '<priority>0.5</priority>')
  39
+        self.assertContains(response, '<lastmod>%s</lastmod>' % date.today().strftime('%Y-%m-%d'))
20  django/contrib/sitemaps/tests/urls.py
... ...
@@ -0,0 +1,20 @@
  1
+from datetime import datetime
  2
+from django.conf.urls.defaults import *
  3
+from django.contrib.sitemaps import Sitemap
  4
+
  5
+class SimpleSitemap(Sitemap):
  6
+    changefreq = "never"
  7
+    priority = 0.5
  8
+    location = '/ticket14164'
  9
+    lastmod = datetime.now()
  10
+
  11
+    def items(self):
  12
+        return [object()]
  13
+
  14
+sitemaps = {
  15
+    'simple': SimpleSitemap,
  16
+}
  17
+
  18
+urlpatterns = patterns('django.contrib.sitemaps.views',
  19
+    (r'^sitemaps/sitemap\.xml$', 'sitemap', {'sitemaps': sitemaps}),
  20
+)

0 notes on commit 38e9ca1

Please sign in to comment.
Something went wrong with that request. Please try again.