Ticket #13881: 13881.tests_and_fix2.patch

File 13881.tests_and_fix2.patch, 3.4 KB (added by Gregor Müllegger, 14 years ago)

"refactored" patch.

  • django/contrib/sitemaps/__init__.py

    === modified file 'django/contrib/sitemaps/__init__.py'
     
    6565        urls = []
    6666        for item in self.paginator.page(page).object_list:
    6767            loc = "http://%s%s" % (current_site.domain, self.__get('location', item))
     68            priority = self.__get('priority', item, None)
     69            if priority is not None:
     70                priority = u"%f" % priority
     71                priority = priority.rstrip(u'0')
    6872            url_info = {
    6973                'location':   loc,
    7074                'lastmod':    self.__get('lastmod', item, None),
    7175                'changefreq': self.__get('changefreq', item, None),
    72                 'priority':   self.__get('priority', item, None)
     76                'priority':   priority
    7377            }
    7478            urls.append(url_info)
    7579        return urls
  • tests/regressiontests/sitemaps/__init__.py

    === added directory 'tests/regressiontests/sitemaps'
    === added file 'tests/regressiontests/sitemaps/__init__.py'
     
     1# empty.
  • tests/regressiontests/sitemaps/models.py

    === added file 'tests/regressiontests/sitemaps/models.py'
     
     1# empty.
  • tests/regressiontests/sitemaps/tests.py

    === added file 'tests/regressiontests/sitemaps/tests.py'
     
     1# -*- coding: utf-8 -*-
     2from datetime import datetime
     3from django.conf import settings
     4from django.utils import translation
     5from django.test import TestCase
     6
     7
     8class TestSitemap(TestCase):
     9    urls = 'regressiontests.sitemaps.urls'
     10
     11    def test_localized_priority(self):
     12        '''
     13        Issue 13881: Priority's decimal separator is localized but shouldn't.
     14        '''
     15        org_l10n, settings.USE_L10N = settings.USE_L10N, True
     16        org_lang = translation.get_language()
     17        settings.INSTALLED_APPS += ('django.contrib.sitemaps',)
     18        try:
     19            translation.activate('ru')
     20            response = self.client.get('/sitemap-page.xml')
     21            self.assertNotContains(response, '<priority>0,5</priority>')
     22            self.assertContains(response, '<priority>0.5</priority>')
     23        finally:
     24            settings.L10N = org_l10n
     25            settings.INSTALLED_APPS = settings.INSTALLED_APPS[:-1]
     26            translation.activate(org_lang)
  • tests/regressiontests/sitemaps/urls.py

    === added file 'tests/regressiontests/sitemaps/urls.py'
     
     1from datetime import datetime
     2from django.conf.urls.defaults import handler404, handler500, patterns, url
     3from django.contrib.sitemaps import Sitemap
     4
     5
     6class Page(object):
     7    def get_absolute_url(self):
     8        return '/'
     9
     10
     11class PageSitemap(Sitemap):
     12    changefreq = 'weekly'
     13    priority = 0.5
     14
     15    def items(self):
     16        return [Page(), Page(), Page()]
     17
     18    def lastmod(self, obj):
     19        return datetime.now()
     20
     21sitemaps = {
     22    'page': PageSitemap(),
     23}
     24
     25urlpatterns = patterns('django.contrib.sitemaps.views',
     26    url(r'^sitemap-(?P<section>\w+).xml$', 'sitemap', {'sitemaps': sitemaps}),
     27)
Back to Top