Ticket #13607: 13607.2.diff

File 13607.2.diff, 6.6 KB (added by Simon Meers, 14 years ago)

Whitespace fixes :)

  • django/contrib/admin/templatetags/admin_list.py

    # HG changeset patch
    # User Simon Meers <DrMeers@gmail.com>
    # Date 1291439705 -39600
    # Node ID 0675b055926093ac42165c7f22c6e311a977b166
    # Parent  b728d13c407ac210c9f9fe6e248863d71ee12c8f
    imported patch 13607
    
    diff -r b728d13c407a -r 0675b0559260 django/contrib/admin/templatetags/admin_list.py
    a b  
    231231
    232232        link = lambda d: cl.get_query_string(d, [field_generic])
    233233
     234        if not (year_lookup or month_lookup or day_lookup):
     235            # select appropriate start level
     236            date_range = cl.query_set.aggregate(first=models.Min(field_name),
     237                                                last=models.Max(field_name))
     238            if date_range['first'] and date_range['last']:
     239                if date_range['first'].year == date_range['last'].year:
     240                    year_lookup = date_range['first'].year
     241                    if date_range['first'].month == date_range['last'].month:
     242                        month_lookup = date_range['first'].month
     243
    234244        if year_lookup and month_lookup and day_lookup:
    235245            day = datetime.date(int(year_lookup), int(month_lookup), int(day_lookup))
    236246            return {
  • tests/regressiontests/admin_views/models.py

    diff -r b728d13c407a -r 0675b0559260 tests/regressiontests/admin_views/models.py
    a b  
    320320class PodcastAdmin(admin.ModelAdmin):
    321321    list_display = ('name', 'release_date')
    322322    list_editable = ('release_date',)
    323 
     323    date_hierarchy = 'release_date'
    324324    ordering = ('name',)
    325325
    326326class Vodcast(Media):
  • tests/regressiontests/admin_views/tests.py

    diff -r b728d13c407a -r 0675b0559260 tests/regressiontests/admin_views/tests.py
    a b  
    55from django.conf import settings
    66from django.core import mail
    77from django.core.files import temp as tempfile
     8from django.core.urlresolvers import reverse
    89from django.contrib.auth import REDIRECT_FIELD_NAME, admin # Register auth models with the admin.
    910from django.contrib.auth.models import User, Permission, UNUSABLE_PASSWORD
    1011from django.contrib.contenttypes.models import ContentType
     
    23932394        response = self.client.get('/test_admin/%s/admin_views/' % self.urlbit)
    23942395        self.failIf(' lang=""' in response.content)
    23952396        self.failIf(' xml:lang=""' in response.content)
     2397
     2398
     2399class DateHierarchyTests(TestCase):
     2400    fixtures = ['admin-views-users.xml']
     2401
     2402    def setUp(self):
     2403        self.client.login(username='super', password='secret')
     2404
     2405    def assert_contains_year_link(self, response, date):
     2406        self.assertContains(response, '?release_date__year=%d"' % (date.year,))
     2407
     2408    def assert_contains_month_link(self, response, date):
     2409        self.assertContains(
     2410            response, '?release_date__year=%d&amp;release_date__month=%d"' % (
     2411                date.year, date.month))
     2412
     2413    def assert_contains_day_link(self, response, date):
     2414        self.assertContains(
     2415            response, '?release_date__year=%d&amp;'
     2416            'release_date__month=%d&amp;release_date__day=%d"' % (
     2417                date.year, date.month, date.day))
     2418
     2419    def test_empty(self):
     2420        """
     2421        Ensure that no date hierarchy links display with empty changelist.
     2422        """
     2423        response = self.client.get(
     2424            reverse('admin:admin_views_podcast_changelist'))
     2425        self.assertNotContains(response, 'release_date__year=')
     2426        self.assertNotContains(response, 'release_date__month=')
     2427        self.assertNotContains(response, 'release_date__day=')
     2428
     2429    def test_single(self):
     2430        """
     2431        Ensure that single day-level date hierarchy appears for single object.
     2432        """
     2433        DATE = datetime.date(2000,6,30)
     2434        Podcast.objects.create(release_date=DATE)
     2435        response = self.client.get(
     2436            reverse('admin:admin_views_podcast_changelist'))
     2437        self.assert_contains_day_link(response, DATE)
     2438
     2439    def test_within_month(self):
     2440        """
     2441        Ensure that day-level links appear for changelist within single month.
     2442        """
     2443        DATES = (datetime.date(2000,6,30),
     2444                 datetime.date(2000,6,15),
     2445                 datetime.date(2000,6,3))
     2446        for date in DATES:
     2447            Podcast.objects.create(release_date=date)
     2448        response = self.client.get(
     2449            reverse('admin:admin_views_podcast_changelist'))
     2450        for date in DATES:
     2451            self.assert_contains_day_link(response, date)
     2452
     2453    def test_within_year(self):
     2454        """
     2455        Ensure that month-level links appear for changelist within single year.
     2456        """
     2457        DATES = (datetime.date(2000,1,30),
     2458                 datetime.date(2000,3,15),
     2459                 datetime.date(2000,5,3))
     2460        for date in DATES:
     2461            Podcast.objects.create(release_date=date)
     2462        response = self.client.get(
     2463            reverse('admin:admin_views_podcast_changelist'))
     2464        # no day-level links
     2465        self.assertNotContains(response, 'release_date__day=')
     2466        for date in DATES:
     2467            self.assert_contains_month_link(response, date)
     2468
     2469    def test_multiple_years(self):
     2470        """
     2471        Ensure that year-level links appear for year-spanning changelist.
     2472        """
     2473        DATES = (datetime.date(2001,1,30),
     2474                 datetime.date(2003,3,15),
     2475                 datetime.date(2005,5,3))
     2476        for date in DATES:
     2477            Podcast.objects.create(release_date=date)
     2478        response = self.client.get(
     2479            reverse('admin:admin_views_podcast_changelist'))
     2480        # no day/month-level links
     2481        self.assertNotContains(response, 'release_date__day=')
     2482        self.assertNotContains(response, 'release_date__month=')
     2483        for date in DATES:
     2484            self.assert_contains_year_link(response, date)
     2485
     2486        # and make sure GET parameters still behave correctly
     2487        for date in DATES:
     2488            response = self.client.get(
     2489                '%s?release_date__year=%d' % (
     2490                    reverse('admin:admin_views_podcast_changelist'),
     2491                    date.year))
     2492            self.assert_contains_month_link(response, date)
     2493
     2494            response = self.client.get(
     2495                '%s?release_date__year=%d&release_date__month=%d' % (
     2496                    reverse('admin:admin_views_podcast_changelist'),
     2497                    date.year, date.month))
     2498            self.assert_contains_day_link(response, date)
Back to Top