def form_valid(self, form):
        query = form.cleaned_data["q"]
        results = form.search()
        narrow = []

        faceted_by = {
            "python": None,
            "os": None,
            "license": None,
            "implementation": None,
        }

        # Check for facets.
        if self.request.GET.get("python"):
            faceted_by["python"] = self.request.GET["python"]
            narrow.append("python_versions:%s" % self.request.GET["python"])

        if self.request.GET.get("os"):
            faceted_by["os"] = self.request.GET["os"]
            narrow.append(self.request.GET["os"] % "operating_systems:%s")

        if self.request.GET.get("license"):
            faceted_by["license"] = self.request.GET["license"]
            narrow.append("licenses:%s" % self.request.GET.get("license"))

        if self.request.GET.get("implementation"):
            faceted_by["implementation"] = self.request.GET["implementation"]
            narrow.append("implementations:%s" % self.request.GET.get("implementation"))

        if len(narrow):
            results = results.narrow(" AND ".join(narrow))

        page_size = self.get_paginate_by()

        if page_size:
            facets = results.facet("python_versions").facet("operating_systems").facet("licenses").facet("implementations").facet_counts()
            paginator, page, results, is_paginated = self.paginate_results(results, page_size)

            # Save it!
            self.save_search(page, query, results)

            # Grumble.
            duped = self.request.GET.copy()
            try:
                del duped["page"]
            except KeyError:
                pass
            query_params = urllib.urlencode(duped, doseq=True)
        else:
            facets = {}
            query_params = ""
            paginator, page, is_paginated = None, None, False

        print faceted_by

        ctx = {
            "form": form,
            "query": query,
            "results": results,
            "page": page,
            "paginator": paginator,
            "is_paginated": is_paginated,
            "facets": facets,
            "faceted_by": faceted_by,
            "query_params": query_params,
        }

        return self.render_to_response(self.get_context_data(**ctx))

    # Copy-pasta from saved_searches with light modification...
dataset/ETHPy150Open crate-archive/crate-site/crateweb/apps/search/views.py/Search.form_valid/swapped operands of `%`