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