MCPcopy Create free account
hub / github.com/django-haystack/django-haystack / changelist_view

Method changelist_view

haystack/admin.py:68–163  ·  view source on GitHub ↗
(self, request, extra_context=None)

Source from the content-addressed store, hash-verified

66
67 @csrf_protect_m
68 def changelist_view(self, request, extra_context=None):
69 if not self.has_change_permission(request, None):
70 raise PermissionDenied
71
72 if SEARCH_VAR not in request.GET:
73 # Do the usual song and dance.
74 return super().changelist_view(request, extra_context)
75
76 # Do a search of just this model and populate a Changelist with the
77 # returned bits.
78 indexed_models = (
79 connections[self.haystack_connection]
80 .get_unified_index()
81 .get_indexed_models()
82 )
83
84 if self.model not in indexed_models:
85 # Oops. That model isn't being indexed. Return the usual
86 # behavior instead.
87 return super().changelist_view(request, extra_context)
88
89 # So. Much. Boilerplate.
90 # Why copy-paste a few lines when you can copy-paste TONS of lines?
91 list_display = list(self.list_display)
92
93 kwargs = {
94 "haystack_connection": self.haystack_connection,
95 "request": request,
96 "model": self.model,
97 "list_display": list_display,
98 "list_display_links": self.list_display_links,
99 "list_filter": self.list_filter,
100 "date_hierarchy": self.date_hierarchy,
101 "search_fields": self.search_fields,
102 "list_select_related": self.list_select_related,
103 "list_per_page": self.list_per_page,
104 "list_editable": self.list_editable,
105 "list_max_show_all": self.list_max_show_all,
106 "model_admin": self,
107 }
108 if hasattr(self, "get_sortable_by"): # Django 2.1+
109 kwargs["sortable_by"] = self.get_sortable_by(request)
110 changelist = SearchChangeList(**kwargs)
111 changelist.formset = None
112 media = self.media
113
114 # Build the action form and populate it with available actions.
115 # Check actions to see if any are available on this changelist
116 actions = self.get_actions(request)
117 if actions:
118 action_form = self.action_form(auto_id=None)
119 action_form.fields["action"].choices = self.get_action_choices(request)
120 else:
121 action_form = None
122
123 selection_note = ngettext(
124 "0 of %(count)d selected",
125 "of %(count)d selected",

Callers

nothing calls this directly

Calls 5

get_model_ct_tupleFunction · 0.90
SearchChangeListClass · 0.85
get_indexed_modelsMethod · 0.80
get_unified_indexMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected