Ticket #15234: 15234_localized_year_in_date_hierarchy.diff

File 15234_localized_year_in_date_hierarchy.diff, 4.9 KB (added by julien, 5 years ago)
  • django/contrib/admin/templatetags/admin_list.py

    diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py
    index db58af9..806be24 100644
    a b def date_hierarchy(cl): 
    261261                'show': True,
    262262                'back': {
    263263                    'link': link({year_field: year_lookup}),
    264                     'title': year_lookup
     264                    'title': str(year_lookup)
    265265                },
    266266                'choices': [{
    267267                    'link': link({year_field: year_lookup, month_field: month_lookup, day_field: day.day}),
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index f392393..53a2c73 100644
    a b class DateHierarchyTests(TestCase): 
    25882588    def setUp(self):
    25892589        self.client.login(username='super', password='secret')
    25902590
     2591    def assert_non_localized_year(self, url, year):
     2592        """ Refs #15234. Ensure that the year is not localized with
     2593            USE_THOUSAND_SEPARATOR.
     2594        """
     2595        self.old_USE_THOUSAND_SEPARATOR = settings.USE_THOUSAND_SEPARATOR
     2596        self.old_USE_L10N = settings.USE_L10N
     2597        settings.USE_THOUSAND_SEPARATOR = True
     2598        settings.USE_L10N = True
     2599        response = self.client.get(url)
     2600        self.assertNotContains(response, formats.number_format(year))
     2601        settings.USE_THOUSAND_SEPARATOR = self.old_USE_THOUSAND_SEPARATOR
     2602        settings.USE_L10N = self.old_USE_L10N
     2603       
    25912604    def assert_contains_year_link(self, response, date):
    25922605        self.assertContains(response, '?release_date__year=%d"' % (date.year,))
    25932606
    class DateHierarchyTests(TestCase): 
    26182631        """
    26192632        DATE = datetime.date(2000, 6, 30)
    26202633        Podcast.objects.create(release_date=DATE)
    2621         response = self.client.get(
    2622             reverse('admin:admin_views_podcast_changelist'))
     2634        url = reverse('admin:admin_views_podcast_changelist')
     2635        response = self.client.get(url)
    26232636        self.assert_contains_day_link(response, DATE)
     2637        self.assert_non_localized_year(url, 2000)
    26242638
    26252639    def test_within_month(self):
    26262640        """
    class DateHierarchyTests(TestCase): 
    26312645                 datetime.date(2000, 6, 3))
    26322646        for date in DATES:
    26332647            Podcast.objects.create(release_date=date)
    2634         response = self.client.get(
    2635             reverse('admin:admin_views_podcast_changelist'))
     2648        url = reverse('admin:admin_views_podcast_changelist')
     2649        response = self.client.get(url)
    26362650        for date in DATES:
    26372651            self.assert_contains_day_link(response, date)
     2652        self.assert_non_localized_year(url, 2000)
    26382653
    26392654    def test_within_year(self):
    26402655        """
    class DateHierarchyTests(TestCase): 
    26452660                 datetime.date(2000, 5, 3))
    26462661        for date in DATES:
    26472662            Podcast.objects.create(release_date=date)
    2648         response = self.client.get(
    2649             reverse('admin:admin_views_podcast_changelist'))
     2663        url = reverse('admin:admin_views_podcast_changelist')
     2664        response = self.client.get(url)
    26502665        # no day-level links
    26512666        self.assertNotContains(response, 'release_date__day=')
    26522667        for date in DATES:
    26532668            self.assert_contains_month_link(response, date)
     2669        self.assert_non_localized_year(url, 2000)
    26542670
    26552671    def test_multiple_years(self):
    26562672        """
    class DateHierarchyTests(TestCase): 
    26712687
    26722688        # and make sure GET parameters still behave correctly
    26732689        for date in DATES:
    2674             response = self.client.get(
    2675                 '%s?release_date__year=%d' % (
    2676                     reverse('admin:admin_views_podcast_changelist'),
    2677                     date.year))
     2690            url = '%s?release_date__year=%d' % (
     2691                  reverse('admin:admin_views_podcast_changelist'),
     2692                  date.year)
     2693            response = self.client.get(url)
    26782694            self.assert_contains_month_link(response, date)
    2679 
    2680             response = self.client.get(
    2681                 '%s?release_date__year=%d&release_date__month=%d' % (
    2682                     reverse('admin:admin_views_podcast_changelist'),
    2683                     date.year, date.month))
     2695            self.assert_non_localized_year(url, 2000)
     2696            self.assert_non_localized_year(url, 2003)
     2697            self.assert_non_localized_year(url, 2005)
     2698
     2699            url = '%s?release_date__year=%d&release_date__month=%d' % (
     2700                  reverse('admin:admin_views_podcast_changelist'),
     2701                  date.year, date.month)
     2702            response = self.client.get(url)
    26842703            self.assert_contains_day_link(response, date)
     2704            self.assert_non_localized_year(url, 2000)
     2705            self.assert_non_localized_year(url, 2003)
     2706            self.assert_non_localized_year(url, 2005)
Back to Top