summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-04-29 11:51:12 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-04-29 11:51:12 +0200
commit905bd7fb44a0dbd0be0d455ab428c388714ae700 (patch)
tree37f15685992bcfca2d66d3f19027dd3dfaa4a963 /tests
parent7c27d1561e3210132576b315f0cd0603e2c1f7bd (diff)
Fixed #13196 -- Formatting in admin changelists.
Handled values returned by functions more like field values. In particular, localized dates, times and datetimes properly, and converted datetimes to the current timezone.
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/admin_changelist/admin.py13
-rw-r--r--tests/regressiontests/admin_changelist/models.py2
-rw-r--r--tests/regressiontests/admin_changelist/tests.py22
3 files changed, 32 insertions, 5 deletions
diff --git a/tests/regressiontests/admin_changelist/admin.py b/tests/regressiontests/admin_changelist/admin.py
index 80bb732eb0..9ecfbc6e12 100644
--- a/tests/regressiontests/admin_changelist/admin.py
+++ b/tests/regressiontests/admin_changelist/admin.py
@@ -3,8 +3,8 @@ from __future__ import absolute_import
from django.contrib import admin
from django.core.paginator import Paginator
-from .models import (Child, Parent, Genre, Band, Musician, Group, Quartet,
- Membership, ChordsMusician, ChordsBand, Invitation, Swallow)
+from .models import (Event, Child, Parent, Genre, Band, Musician, Group,
+ Quartet, Membership, ChordsMusician, ChordsBand, Invitation, Swallow)
site = admin.AdminSite(name="admin")
@@ -15,6 +15,15 @@ class CustomPaginator(Paginator):
allow_empty_first_page=allow_empty_first_page)
+class EventAdmin(admin.ModelAdmin):
+ list_display = ['event_date_func']
+
+ def event_date_func(self, event):
+ return event.date
+
+site.register(Event, EventAdmin)
+
+
class ParentAdmin(admin.ModelAdmin):
list_filter = ['child__name']
search_fields = ['child__name']
diff --git a/tests/regressiontests/admin_changelist/models.py b/tests/regressiontests/admin_changelist/models.py
index 1c615eab19..dcc343bb6a 100644
--- a/tests/regressiontests/admin_changelist/models.py
+++ b/tests/regressiontests/admin_changelist/models.py
@@ -1,5 +1,7 @@
from django.db import models
+class Event(models.Model):
+ date = models.DateField()
class Parent(models.Model):
name = models.CharField(max_length=128)
diff --git a/tests/regressiontests/admin_changelist/tests.py b/tests/regressiontests/admin_changelist/tests.py
index f4cdbde4fb..62166ce174 100644
--- a/tests/regressiontests/admin_changelist/tests.py
+++ b/tests/regressiontests/admin_changelist/tests.py
@@ -1,5 +1,7 @@
from __future__ import absolute_import
+import datetime
+
from django.contrib import admin
from django.contrib.admin.options import IncorrectLookupParameters
from django.contrib.admin.views.main import ChangeList, SEARCH_VAR, ALL_VAR
@@ -7,14 +9,15 @@ from django.contrib.auth.models import User
from django.template import Context, Template
from django.test import TestCase
from django.test.client import RequestFactory
+from django.utils import formats
from .admin import (ChildAdmin, QuartetAdmin, BandAdmin, ChordsBandAdmin,
GroupAdmin, ParentAdmin, DynamicListDisplayChildAdmin,
DynamicListDisplayLinksChildAdmin, CustomPaginationAdmin,
FilteredChildAdmin, CustomPaginator, site as custom_site,
SwallowAdmin)
-from .models import (Child, Parent, Genre, Band, Musician, Group, Quartet,
- Membership, ChordsMusician, ChordsBand, Invitation, Swallow,
+from .models import (Event, Child, Parent, Genre, Band, Musician, Group,
+ Quartet, Membership, ChordsMusician, ChordsBand, Invitation, Swallow,
UnorderedObject, OrderedObject)
@@ -325,6 +328,19 @@ class ChangeListTests(TestCase):
self.assertEqual(cl.paginator.count, 30)
self.assertEqual(cl.paginator.page_range, [1, 2, 3])
+ def test_computed_list_display_localization(self):
+ """
+ Regression test for #13196: output of functions should be localized
+ in the changelist.
+ """
+ User.objects.create_superuser(
+ username='super', email='super@localhost', password='secret')
+ self.client.login(username='super', password='secret')
+ event = Event.objects.create(date=datetime.date.today())
+ response = self.client.get('/admin/admin_changelist/event/')
+ self.assertContains(response, formats.localize(event.date))
+ self.assertNotContains(response, unicode(event.date))
+
def test_dynamic_list_display(self):
"""
Regression tests for #14206: dynamic list_display support.
@@ -519,4 +535,4 @@ class ChangeListTests(TestCase):
OrderedObjectAdmin.ordering = ['-id', 'bool']
check_results_order()
OrderedObjectAdmin.ordering = ['id', 'bool']
- check_results_order(ascending=True) \ No newline at end of file
+ check_results_order(ascending=True)