def get_request_filters(request): filters = HaystackFacetFilter.get_request_filters(request) # Remove items with empty values. # # NOTE 1: We copy the keys list to avoid a RuntimeError that occurs when modifying a dict while iterating. # # NOTE 2: We filter in this fashion, as opposed to dictionary comprehension, due to the fact that filters # is a `QueryDict` object, not a `dict`. Dictionary comprehension will not preserve the values of # `QueryDict.getlist()`. Since we support multiple values for a single parameter, dictionary comprehension is a # dealbreaker (and production breaker). for key in list(filters.keys()): if not filters[key]: del filters[key] return filters