Remove suprious comma. Fixing a tuple <= int bug
[htsworkflow.git] / samples / changelist.py
1 from __future__ import absolute_import, print_function, unicode_literals
2
3 import django
4 from django.contrib.admin.views.main import ChangeList
5
6 class HTSChangeList(ChangeList):
7     def __init__(self, request, model, list_filter, search_fields,
8                  list_per_page, model_admin, extra_filters=None):
9         """Simplification of the django model filter view
10
11         The new parameter "extra_filter" should be a mapping
12         of that will be passed as keyword arguments to
13         queryset.filter
14         """
15         self.extra_filters = extra_filters
16
17         args = {
18             'request': request, #request
19             'model': model, #model
20             'list_display': [], # list_display
21             'list_display_links': None, # list_display_links
22             'list_filter': list_filter, #list_filter
23             'date_hierarchy': None, # date_hierarchy
24             'search_fields': search_fields, #search_fields
25             'list_select_related': None, # list_select_related,
26             'list_per_page': list_per_page, #list_per_page
27             'list_editable': None, # list_editable
28             'model_admin': model_admin #model_admin
29         }
30         if django.VERSION[0] >= 1 and django.VERSION[1] >= 4:
31             args['list_max_show_all'] = 20000 #list_max_show_all
32         super(HTSChangeList, self).__init__(**args)
33
34         self.is_popup = False
35         # I removed to field in the first version
36
37         self.multi_page = True
38         self.can_show_all = False
39
40     def get_queryset(self, request=None):
41         args = {}
42         if django.VERSION[0] >= 1 and django.VERSION[1] >= 4:
43             args['request'] = request #list_max_show_all
44
45         qs = super(HTSChangeList, self).get_queryset(**args)
46         if self.extra_filters:
47             new_qs = qs.filter(**self.extra_filters)
48             if new_qs is not None:
49                 qs = new_qs
50         return qs