-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters.py
36 lines (27 loc) · 1.16 KB
/
filters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#coding: utf-8
from django import forms
from django.contrib.admin.filters import ListFilter
from django.contrib.admin.views.main import IGNORED_PARAMS
class BaseInputFilter(ListFilter):
is_search_filter = True
form_template = 'inputfilters/form.html'
def __init__(self, request, params, model, model_admin):
super(BaseInputFilter, self).__init__(request, params, model, model_admin)
fields = {}
for k, v in request.GET.items():
if k not in IGNORED_PARAMS and k not in self.form.base_fields:
fields.setdefault(k, forms.CharField(widget=forms.HiddenInput)).initial = v
self.form = type('InputFilterForm', (self.form,), fields)(request.GET)
for field in self.form.fields.values():
field.required = False
for p in self.expected_parameters():
if p in params:
value = params.pop(p)
self.used_parameters[p] = value
def expected_parameters(self):
for field in self.form.fields:
yield field
def has_output(self):
return True
def choices(self, cl):
return ()