Ticket #17515: filterspec_custom_templates_0.1.diff
File filterspec_custom_templates_0.1.diff, 5.4 KB (added by , 13 years ago) |
---|
-
docs/ref/contrib/admin/index.txt
695 695 ('is_staff', BooleanFieldListFilter), 696 696 ) 697 697 698 .. note::699 698 700 The ``FieldListFilter`` API is currently considered internal 701 and prone to refactoring. 699 .. note:: 702 700 701 .. versionadded:: 1.4 702 703 It's possible customize the template used to display the filter, for example:: 704 705 class AdvancedDecadeBornListFilter(DecadeBornListFilter): 706 template_name = "custom_template.html" 707 708 709 710 .. note:: 711 712 The ``FieldListFilter`` API is currently considered internal 713 and prone to refactoring. 714 703 715 .. attribute:: ModelAdmin.list_max_show_all 704 716 705 717 .. versionadded:: 1.4 … … 2027 2039 :class:`ModelAdmin` instances described above. The ``opts`` variable can be any 2028 2040 object which has an ``app_label`` and ``module_name`` and is usually supplied 2029 2041 by the admin views for the current model. 2042 2043 -
tests/regressiontests/admin_views/admin.py
13 13 from django.db import models 14 14 from django.forms.models import BaseModelFormSet 15 15 from django.http import HttpResponse 16 from django.contrib.admin import BooleanFieldListFilter 16 17 17 18 from .models import (Article, Chapter, Account, Media, Child, Parent, Picture, 18 19 Widget, DooHickey, Grommet, Whatsit, FancyDoodad, Category, Link, … … 25 26 CoverLetter, Story, OtherStory, Book, Promo, ChapterXtra1, Pizza, Topping, 26 27 Album, Question, Answer, ComplexSortedPerson, PrePopulatedPostLargeSlug, 27 28 AdminOrderedField, AdminOrderedModelMethod, AdminOrderedAdminMethod, 28 AdminOrderedCallable, Report )29 AdminOrderedCallable, Report, Color2) 29 30 30 31 31 32 def callable_year(dt_value): … … 512 513 name='cable_extra'), 513 514 ) 514 515 516 class CustomTemplateBooleanFieldListFilter(BooleanFieldListFilter): 517 template_name = 'custom_filter_template.html' 518 519 class CustomTemplateFilterColorAdmin(admin.ModelAdmin): 520 list_filter = (('warm', CustomTemplateBooleanFieldListFilter),) 521 515 522 site = admin.AdminSite(name="admin") 516 523 site.register(Article, ArticleAdmin) 517 524 site.register(CustomArticle, CustomArticleAdmin) … … 581 588 site.register(AdminOrderedModelMethod, AdminOrderedModelMethodAdmin) 582 589 site.register(AdminOrderedAdminMethod, AdminOrderedAdminMethodAdmin) 583 590 site.register(AdminOrderedCallable, AdminOrderedCallableAdmin) 591 site.register(Color2, CustomTemplateFilterColorAdmin) 584 592 585 593 # Register core models we need in our tests 586 594 from django.contrib.auth.models import User, Group -
tests/regressiontests/admin_views/tests.py
573 573 except SuspiciousOperation: 574 574 self.fail("Filters should be allowed if they are defined on a ForeignKey pointing to this model") 575 575 576 def test_filter_with_custom_template(self): 577 response = self.client.get("/test_admin/admin/admin_views/color2/") 578 self.assertTrue('custom_filter_template.html' in [t.name for t in response.template]) 579 580 576 581 class AdminJavaScriptTest(AdminViewBasicTest): 577 582 urls = "regressiontests.admin_views.urls" 578 583 -
tests/regressiontests/admin_views/models.py
106 106 def __unicode__(self): 107 107 return self.value 108 108 109 # we replicate Color to register with another ModelAdmin 110 class Color2(Color): 111 class Meta: 112 proxy = True 109 113 110 114 class Thing(models.Model): 111 115 title = models.CharField(max_length=20) -
django/contrib/admin/templatetags/admin_list.py
13 13 from django.utils.translation import ugettext as _ 14 14 from django.utils.encoding import smart_unicode, force_unicode 15 15 from django.template import Library 16 from django.template.loader import get_template 17 from django.template.context import Context 16 18 17 18 19 register = Library() 19 20 20 21 DOT = '.' … … 360 361 'search_var': SEARCH_VAR 361 362 } 362 363 363 @register. inclusion_tag('admin/filter.html')364 @register.simple_tag() 364 365 def admin_list_filter(cl, spec): 365 return {'title': spec.title, 'choices' : list(spec.choices(cl))} 366 if hasattr(spec, 'template_name') and spec.template_name: 367 t = get_template(spec.template_name) 368 else: 369 t = get_template('admin/filter.html') 370 ctx = Context({'title': spec.title, 'choices' : list(spec.choices(cl)), 'spec': spec}) 371 return t.render(ctx) 366 372 367 373 @register.inclusion_tag('admin/actions.html', takes_context=True) 368 374 def admin_actions(context):