Commit 4dbeb4bc authored by Jannis Leidel's avatar Jannis Leidel
Browse files

Fixed #17515 -- Added ability to override the template of custom admin...

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
parent 875a5ea8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ from django.contrib.admin.util import (get_model_from_relation,

class ListFilter(object):
    title = None  # Human-readable title to appear in the right sidebar.
    template = 'admin/filter.html'

    def __init__(self, request, params, model, model_admin):
        # This dictionary will eventually contain the request's query string
+9 −3
Original line number Diff line number Diff line
@@ -13,7 +13,8 @@ from django.utils.text import capfirst
from django.utils.translation import ugettext as _
from django.utils.encoding import smart_unicode, force_unicode
from django.template import Library

from django.template.loader import get_template
from django.template.context import Context

register = Library()

@@ -360,9 +361,14 @@ def search_form(cl):
        'search_var': SEARCH_VAR
    }

@register.inclusion_tag('admin/filter.html')
@register.simple_tag
def admin_list_filter(cl, spec):
    return {'title': spec.title, 'choices' : list(spec.choices(cl))}
    tpl = get_template(spec.template)
    return tpl.render(Context({
        'title': spec.title,
        'choices' : list(spec.choices(cl)),
        'spec': spec,
    }))

@register.inclusion_tag('admin/actions.html', takes_context=True)
def admin_actions(context):
+12 −2
Original line number Diff line number Diff line
@@ -697,8 +697,18 @@ subclass::

      .. note::

          The ``FieldListFilter`` API is currently considered internal
          and prone to refactoring.
        The ``FieldListFilter`` API is currently considered internal and prone
        to refactoring.

    .. versionadded:: 1.4

    It is possible to specify a custom template for rendering a list filter::

        class FilterWithCustomTemplate(SimpleListFilter):
            template = "custom_template.html"

    See the default template provided by django (``admin/filter.html``) for
    a concrete example.

.. attribute:: ModelAdmin.list_max_show_all

+9 −1
Original line number Diff line number Diff line
@@ -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
+4 −0
Original line number Diff line number Diff line
@@ -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)
Loading