1 """
2 FilterSpec encapsulates the logic for displaying filters in the Django admin.
3 Filters are specified in models with the "list_filter" option.
4
5 Each filter subclass knows how to display a filter for a field that passes a
6 certain test -- e.g. being a DateField or ForeignKey.
7 """
8
9 from django.db import models
10 from django.utils.encoding import smart_unicode, iri_to_uri
11 from django.utils.translation import ugettext as _
12 from django.utils.html import escape
13 from django.utils.safestring import mark_safe
14 import datetime
15
17 filter_specs = []
18 - def __init__(self, f, request, params, model):
19 self.field = f
20 self.params = params
21
24 register = classmethod(register)
25
26 - def create(cls, f, request, params, model):
30 create = classmethod(create)
31
34
36 raise NotImplementedError()
37
40
42 t = []
43 if self.has_output():
44 t.append(_(u'<h3>By %s:</h3>\n<ul>\n') % escape(self.title()))
45
46 for choice in self.choices(cl):
47 t.append(u'<li%s><a href="%s">%s</a></li>\n' % \
48 ((choice['selected'] and ' class="selected"' or ''),
49 iri_to_uri(choice['query_string']),
50 choice['display']))
51 t.append('</ul>\n\n')
52 return mark_safe("".join(t))
53