Ticket #7145: 7145_django_1.3.patch

File 7145_django_1.3.patch, 4.2 KB (added by daniellindsley, 14 years ago)

Django 1.3 version of the patch

  • tests/regressiontests/admin_util/models.py

    diff --git a/tests/regressiontests/admin_util/models.py b/tests/regressiontests/admin_util/models.py
    index d5e29e9..c5e1d6a 100644
    a b class Guest(models.Model):  
    3535
    3636    class Meta:
    3737        verbose_name = "awesome guest"
     38
     39class AnotherArticle(models.Model):
     40    title = models.CharField(max_length=100)
     41    created = models.DateTimeField(blank=True, null=True)
     42
     43    def __unicode__(self):
     44        return self.title
  • tests/regressiontests/admin_util/tests.py

    diff --git a/tests/regressiontests/admin_util/tests.py b/tests/regressiontests/admin_util/tests.py
    index 24dde41..408434b 100644
    a b from datetime import datetime  
    22
    33from django.conf import settings
    44from django.contrib import admin
     5from django.contrib.admin.templatetags.admin_list import date_hierarchy
    56from django.contrib.admin.util import display_for_field, label_for_field, lookup_field
    67from django.contrib.admin.util import NestedObjects
    7 from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
     8from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE, ChangeList
    89from django.contrib.sites.models import Site
    910from django.db import models, DEFAULT_DB_ALIAS
    1011from django.test import TestCase
    1112from django.utils import unittest
    1213from django.utils.formats import localize
    1314
    14 from models import Article, Count, Event, Location
     15from models import Article, Count, Event, Location, AnotherArticle
    1516
    1617
    1718class NestedObjectsTests(TestCase):
    class UtilTests(unittest.TestCase):  
    235236            label_for_field('guest', Event, return_attr=True),
    236237            ('awesome guest', None),
    237238        )
     239
     240
     241class MockRequest(object):
     242    pass
     243
     244
     245class AnotherArticleAdmin(admin.ModelAdmin):
     246    list_display = ['title', 'created']
     247    date_hierarchy = 'created'
     248
     249
     250class DateHierarchyTestCase(TestCase):
     251    fixtures = ['admin_util_anotherarticles.json']
     252   
     253    def test_nullable_date_hierarchy(self):
     254        """
     255        Tests to ensure that the ``date_hierarchy`` tag doesn't blow up on
     256        nullable dates.
     257        """
     258        mock_admin = AnotherArticleAdmin(AnotherArticle, None)
     259        mock_request = MockRequest()
     260       
     261        mock_request.GET = {}
     262       
     263        cl = ChangeList(mock_request, AnotherArticle, mock_admin.list_display, mock_admin.list_filter, [], mock_admin.date_hierarchy, [], None, 50, False, mock_admin)
     264        self.assertEqual(date_hierarchy(cl), {'choices': [{'link': '?created__year=2010', 'title': '2010'}, {'link': '?created__year=2011', 'title': '2011'}], 'show': True})
     265       
     266        mock_request.GET = {'created__year': '2010'}
     267        cl = ChangeList(mock_request, AnotherArticle, mock_admin.list_display, mock_admin.list_filter, [], mock_admin.date_hierarchy, [], None, 50, False, mock_admin)
     268        self.assertEqual(date_hierarchy(cl), {'choices': [{'link': '?created__year=2010&created__month=1', 'title': u'January 2010'}, {'link': '?created__year=2010&created__month=10', 'title': u'October 2010'}], 'back': {'link': '?', 'title': u'All dates'}, 'show': True})
     269       
     270        mock_request.GET = {'created__year': '2010', 'created__month': '10'}
     271        cl = ChangeList(mock_request, AnotherArticle, mock_admin.list_display, mock_admin.list_filter, [], mock_admin.date_hierarchy, [], None, 50, False, mock_admin)
     272        self.assertEqual(date_hierarchy(cl), {'choices': [{'link': '?created__day=12&created__year=2010&created__month=10', 'title': u'October 12'}, {'link': '?created__day=13&created__year=2010&created__month=10', 'title': u'October 13'}], 'back': {'link': '?created__year=2010', 'title': '2010'}, 'show': True})
     273       
     274        mock_request.GET = {'created__year': '2010', 'created__month': '10', 'created__day': '13'}
     275        cl = ChangeList(mock_request, AnotherArticle, mock_admin.list_display, mock_admin.list_filter, [], mock_admin.date_hierarchy, [], None, 50, False, mock_admin)
     276        self.assertEqual(date_hierarchy(cl), {'choices': [{'title': u'October 13'}], 'back': {'link': '?created__year=2010&created__month=10', 'title': u'October 2010'}, 'show': True})
Back to Top