diff options
| author | Jannis Leidel <jannis@leidel.info> | 2012-02-09 18:59:05 +0000 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2012-02-09 18:59:05 +0000 |
| commit | 4dbeb4bca4638ff851a2f4844d262dbe1652f7b5 (patch) | |
| tree | 219211a0fed93719262c6c8aa7c3b03085742824 /tests | |
| parent | 875a5ea8d47c2c10432572fec788a81217073a4f (diff) | |
Fixed #17515 -- Added ability to override the template of custom admin FilterSpec classes. Thanks, saxix and Julien Phalip.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17483 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
4 files changed, 33 insertions, 1 deletions
diff --git a/tests/regressiontests/admin_views/admin.py b/tests/regressiontests/admin_views/admin.py index e541a4265e..62228663fe 100644 --- a/tests/regressiontests/admin_views/admin.py +++ b/tests/regressiontests/admin_views/admin.py @@ -13,6 +13,7 @@ from django.conf.urls import patterns, url from django.db import models from django.forms.models import BaseModelFormSet from django.http import HttpResponse +from django.contrib.admin import BooleanFieldListFilter from .models import (Article, Chapter, Account, Media, Child, Parent, Picture, Widget, DooHickey, Grommet, Whatsit, FancyDoodad, Category, Link, @@ -25,7 +26,7 @@ from .models import (Article, Chapter, Account, Media, Child, Parent, Picture, CoverLetter, Story, OtherStory, Book, Promo, ChapterXtra1, Pizza, Topping, Album, Question, Answer, ComplexSortedPerson, PrePopulatedPostLargeSlug, AdminOrderedField, AdminOrderedModelMethod, AdminOrderedAdminMethod, - AdminOrderedCallable, Report) + AdminOrderedCallable, Report, Color2) def callable_year(dt_value): @@ -525,6 +526,12 @@ class ReportAdmin(admin.ModelAdmin): ) +class CustomTemplateBooleanFieldListFilter(BooleanFieldListFilter): + template = 'custom_filter_template.html' + +class CustomTemplateFilterColorAdmin(admin.ModelAdmin): + list_filter = (('warm', CustomTemplateBooleanFieldListFilter),) + site = admin.AdminSite(name="admin") site.register(Article, ArticleAdmin) site.register(CustomArticle, CustomArticleAdmin) @@ -594,6 +601,7 @@ site.register(AdminOrderedField, AdminOrderedFieldAdmin) site.register(AdminOrderedModelMethod, AdminOrderedModelMethodAdmin) site.register(AdminOrderedAdminMethod, AdminOrderedAdminMethodAdmin) site.register(AdminOrderedCallable, AdminOrderedCallableAdmin) +site.register(Color2, CustomTemplateFilterColorAdmin) # Register core models we need in our tests from django.contrib.auth.models import User, Group diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py index b3426b4ec3..7d58952b87 100644 --- a/tests/regressiontests/admin_views/models.py +++ b/tests/regressiontests/admin_views/models.py @@ -105,6 +105,10 @@ class Color(models.Model): def __unicode__(self): return self.value +# we replicate Color to register with another ModelAdmin +class Color2(Color): + class Meta: + proxy = True class Thing(models.Model): title = models.CharField(max_length=20) diff --git a/tests/regressiontests/admin_views/templates/custom_filter_template.html b/tests/regressiontests/admin_views/templates/custom_filter_template.html new file mode 100644 index 0000000000..e5c9a8e7d8 --- /dev/null +++ b/tests/regressiontests/admin_views/templates/custom_filter_template.html @@ -0,0 +1,7 @@ +<h3>By {{ filter_title }} (custom)</h3> +<ul> +{% for choice in choices %} + <li{% if choice.selected %} class="selected"{% endif %}> + <a href="{{ choice.query_string|iriencode }}">{{ choice.display }}</a></li> +{% endfor %} +</ul> diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index fc46f7e8ae..fa189203a2 100755 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -1,6 +1,7 @@ # coding: utf-8 from __future__ import with_statement, absolute_import +import os import re import datetime import urlparse @@ -593,6 +594,18 @@ class AdminViewFormUrlTest(TestCase): self.assertTrue('form_url' in response.context, msg='form_url not present in response.context') self.assertEqual(response.context['form_url'], 'pony') + def test_filter_with_custom_template(self): + """ + Ensure that one can use a custom template to render an admin filter. + Refs #17515. + """ + template_dirs = settings.TEMPLATE_DIRS + ( + os.path.join(os.path.dirname(__file__), 'templates'),) + with self.settings(TEMPLATE_DIRS=template_dirs): + response = self.client.get("/test_admin/admin/admin_views/color2/") + self.assertTrue('custom_filter_template.html' in [t.name for t in response.templates]) + + class AdminJavaScriptTest(AdminViewBasicTest): urls = "regressiontests.admin_views.urls" |
