Author: russellm
Date: 2010-08-27 10:18:10 -0500 (Fri, 27 Aug 2010)
New Revision: 13646

Added:
   django/branches/releases/1.2.X/django/contrib/sitemaps/tests/
   django/branches/releases/1.2.X/django/contrib/sitemaps/tests/__init__.py
   django/branches/releases/1.2.X/django/contrib/sitemaps/tests/basic.py
   django/branches/releases/1.2.X/django/contrib/sitemaps/tests/urls.py
Modified:
   django/branches/releases/1.2.X/django/contrib/sitemaps/__init__.py
Log:
[1.2.X] Fixed #14164 -- Ensure that sitemap priorities aren't rendered with 
localized numerical formats. Thanks to dokterbob for the report, and vung for 
the draft patch.

Backport of r13644 from trunk.

Modified: django/branches/releases/1.2.X/django/contrib/sitemaps/__init__.py
===================================================================
--- django/branches/releases/1.2.X/django/contrib/sitemaps/__init__.py  
2010-08-27 15:16:30 UTC (rev 13645)
+++ django/branches/releases/1.2.X/django/contrib/sitemaps/__init__.py  
2010-08-27 15:18:10 UTC (rev 13646)
@@ -69,7 +69,7 @@
                 'location':   loc,
                 'lastmod':    self.__get('lastmod', item, None),
                 'changefreq': self.__get('changefreq', item, None),
-                'priority':   self.__get('priority', item, None)
+                'priority':   str(self.__get('priority', item, ''))
             }
             urls.append(url_info)
         return urls

Added: django/branches/releases/1.2.X/django/contrib/sitemaps/tests/__init__.py
===================================================================
--- django/branches/releases/1.2.X/django/contrib/sitemaps/tests/__init__.py    
                        (rev 0)
+++ django/branches/releases/1.2.X/django/contrib/sitemaps/tests/__init__.py    
2010-08-27 15:18:10 UTC (rev 13646)
@@ -0,0 +1 @@
+from django.contrib.sitemaps.tests.basic import *

Added: django/branches/releases/1.2.X/django/contrib/sitemaps/tests/basic.py
===================================================================
--- django/branches/releases/1.2.X/django/contrib/sitemaps/tests/basic.py       
                        (rev 0)
+++ django/branches/releases/1.2.X/django/contrib/sitemaps/tests/basic.py       
2010-08-27 15:18:10 UTC (rev 13646)
@@ -0,0 +1,39 @@
+from datetime import date
+from django.conf import settings
+from django.test import TestCase
+from django.utils.formats import localize
+from django.utils.translation import activate
+
+
+class SitemapTests(TestCase):
+    urls = 'django.contrib.sitemaps.tests.urls'
+
+    def setUp(self):
+        self.old_USE_L10N = settings.USE_L10N
+
+    def tearDown(self):
+        settings.USE_L10N = self.old_USE_L10N
+
+    def test_simple_sitemap(self):
+        "A simple sitemap can be rendered"
+        # Retrieve the sitemap.
+        response = self.client.get('/sitemaps/sitemap.xml')
+        # Check for all the important bits:
+        self.assertEquals(response.content, """<?xml version="1.0" 
encoding="UTF-8"?>
+<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9";>
+<url><loc>http://example.com/ticket14164</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
+</urlset>
+""" % date.today().strftime('%Y-%m-%d'))
+
+    def test_localized_priority(self):
+        "The priority value should not be localized (Refs #14164)"
+        # Localization should be active
+        settings.USE_L10N = True
+        activate('fr')
+        self.assertEqual(u'0,3', localize(0.3))
+
+        # Retrieve the sitemap. Check that priorities
+        # haven't been rendered in localized format
+        response = self.client.get('/sitemaps/sitemap.xml')
+        self.assertContains(response, '<priority>0.5</priority>')
+        self.assertContains(response, '<lastmod>%s</lastmod>' % 
date.today().strftime('%Y-%m-%d'))

Added: django/branches/releases/1.2.X/django/contrib/sitemaps/tests/urls.py
===================================================================
--- django/branches/releases/1.2.X/django/contrib/sitemaps/tests/urls.py        
                        (rev 0)
+++ django/branches/releases/1.2.X/django/contrib/sitemaps/tests/urls.py        
2010-08-27 15:18:10 UTC (rev 13646)
@@ -0,0 +1,20 @@
+from datetime import datetime
+from django.conf.urls.defaults import *
+from django.contrib.sitemaps import Sitemap
+
+class SimpleSitemap(Sitemap):
+    changefreq = "never"
+    priority = 0.5
+    location = '/ticket14164'
+    lastmod = datetime.now()
+
+    def items(self):
+        return [object()]
+
+sitemaps = {
+    'simple': SimpleSitemap,
+}
+
+urlpatterns = patterns('django.contrib.sitemaps.views',
+    (r'^sitemaps/sitemap\.xml$', 'sitemap', {'sitemaps': sitemaps}),
+)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to