class HotspotFilteredView (HotspotSearchView): filter_form = None def get (self, request, *args, **kwargs): self.filter_form = HotspotFilterForm (request.GET) return super (HotspotFilteredView, self).get (request, *args, **kwargs) def get_queryset (self): center = self.view_options.get ("center", None) if center: queryset = super (HotspotFilteredView, self).get_queryset () else: queryset = Hotspot.objects.filter ( geometry__distance_lte=(self.center_point, D(mi=25)) ).select_related (depth=2) if self.filter_form.is_valid (): free = self.filter_form.cleaned_data["free"] queryset = queryset.filter (restricted=not free) return queryset def get_context_data (self, **kwargs): context = super (HotspotFilteredView, self).get_context_data (**kwargs) context["filter_form"] = self.filter_form if not self.filter_form.is_valid (): context["filter_form"] = HotspotFilterForm () return context
class FilteredView (ListView): filter_form = None def get (self, request, *args, **kwargs): self.filter_form = HotspotFilterForm (request.GET) return super (FilteredView, self).get (request, *args, **kwargs) def get_queryset (self): queryset = super (FilteredView, self).get_queryset () if self.filter_form.is_valid (): free = self.filter_form.cleaned_data["free"] queryset = queryset.filter (restricted=not free) return queryset def get_context_data (self, **kwargs): context = super (FilteredView, self).get_context_data (**kwargs) context["filter_form"] = self.filter_form if not self.filter_form.is_valid (): context["filter_form"] = HotspotFilterForm () return context
def get (self, request, *args, **kwargs): self.filter_form = HotspotFilterForm (request.GET) return super (FilteredView, self).get (request, *args, **kwargs)