Ticket #671: filter.py

File filter.py, 1.3 KB (added by ian@…, 19 years ago)

modifcation of hugo's IRC log filter

Line 
1"wrapped generic list view adding searching parameters "
2from django import models
3from django.core.meta import FieldDoesNotExist
4from django.views.generic.list_detail import object_list
5
6def wrapped(generic):
7
8 def _wrapper(request, app_label, module_name, *args, **kw):
9 direction = request.GET.get('direction', None)
10 if direction in ('newest_top', 'oldest_top'):
11 request.session['direction'] = direction
12 else:
13 direction = request.session.get('direction', 'oldest_top')
14
15 if not kw.has_key('extra_lookup_kwargs'):
16 kw['extra_lookup_kwargs'] = {}
17
18 keys = request.GET.keys()
19 if keys:
20 mod = models.get_module(app_label, module_name)
21 meta = mod.Klass._meta
22 for key in keys:
23 try:
24 meta.get_field(key)
25 value = request.GET.get(key,None)
26
27 if value:
28 print key+'__contains', '=', value
29 kw['extra_lookup_kwargs'][key+'__contains'] = value
30 except FieldDoesNotExist, msg:
31 print msg
32
33 if not kw.has_key('extra_context'):
34 kw['extra_context'] = {}
35
36 return generic(request, app_label, module_name, *args, **kw)
37
38 return _wrapper
39
40object_list = wrapped(object_list)
41
Back to Top