Skip to content

Commit

Permalink
Remove unused search filters
Browse files Browse the repository at this point in the history
  • Loading branch information
smdsgn committed Nov 14, 2024
1 parent 5b4dcd5 commit 35e149d
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 61 deletions.
40 changes: 6 additions & 34 deletions project/views/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from project.models.create import update_period
from project.models.enums import ProjectChangeReason
from public_data.exceptions import LandException
from public_data.models import AdminRef, Land
from public_data.models import Land
from utils.views_mixins import BreadCrumbMixin, RedirectURLMixin

from .mixins import GroupMixin, ReactMixin
Expand Down Expand Up @@ -69,40 +69,12 @@ def get_context_data(self, **kwargs):

def form_valid(self, form):
"""If the form is valid, redirect to the supplied URL."""
if not form.cleaned_data["selection"]:
search_for = []
if form.cleaned_data["search_region"]:
search_for.append(AdminRef.REGION)
if form.cleaned_data["search_departement"]:
search_for.append(AdminRef.DEPARTEMENT)
if form.cleaned_data["search_epci"]:
search_for.append(AdminRef.EPCI)
if form.cleaned_data["search_commune"]:
search_for.append(AdminRef.COMMUNE)
if form.cleaned_data["search_scot"]:
search_for.append(AdminRef.SCOT)
needle = form.cleaned_data["keyword"]
if needle == "*":
needle = ""
results = Land.search(
needle,
region=form.cleaned_data["region"],
departement=form.cleaned_data["departement"],
epci=form.cleaned_data["epci"],
search_for=search_for,
)
kwargs = {
"results": {AdminRef.get_label(k): v for k, v in results.items()},
"form": form,
}
return self.render_to_response(self.get_context_data(**kwargs))
else:
project = create_from_public_key(form.cleaned_data["selection"], user=self.request.user)
project = create_from_public_key(form.cleaned_data["selection"], user=self.request.user)

if self.request.GET.get("next") == "download":
return redirect("project:report_download", pk=project.id)
else:
return redirect("project:splash", pk=project.id)
if self.request.GET.get("next") == "download":
return redirect("project:report_download", pk=project.id)
else:
return redirect("project:splash", pk=project.id)


class ProjectUpdateView(ReactMixin, UpdateView):
Expand Down
7 changes: 0 additions & 7 deletions public_data/models/administration/Commune.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ def search(cls, needle, region=None, departement=None, epci=None):
qs = qs.filter(similarity__gt=0.2) # Filtrer par un score minimum de similarité
qs = qs.order_by("-similarity") # Trier par score décroissant

if region:
qs = qs.filter(departement__region=region)
if departement:
qs = qs.filter(departement=departement)
if epci:
qs = qs.filter(epci=epci)

return qs

@classmethod
Expand Down
5 changes: 0 additions & 5 deletions public_data/models/administration/Departement.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,4 @@ def search(cls, needle, region=None, departement=None, epci=None):
qs = qs.filter(similarity__gt=0.15) # Filtrer par un score minimum de similarité
qs = qs.order_by("-similarity") # Trier par score décroissant

if region:
qs = qs.filter(region=region)
if departement:
qs = qs.filter(id=departement.id)

return qs
7 changes: 0 additions & 7 deletions public_data/models/administration/Epci.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ def search(cls, needle, region=None, departement=None, epci=None):
qs = qs.filter(similarity__gt=0.15) # Filtrer par un score minimum de similarité
qs = qs.order_by("-similarity") # Trier par score décroissant

if region:
qs = qs.filter(departements__region=region)
if departement:
qs = qs.filter(departements__id=departement.id)
if epci:
qs = qs.filter(id=epci.id)

qs = qs.distinct().order_by("-similarity")

return qs
3 changes: 0 additions & 3 deletions public_data/models/administration/Region.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ def search(cls, needle, region=None, departement=None, epci=None):
qs = qs.filter(similarity__gt=0.15) # Filtrer par un score minimum de similarité
qs = qs.order_by("-similarity") # Trier par score décroissant

if region:
qs = qs.filter(id=region.id)

return qs

@property
Expand Down
5 changes: 0 additions & 5 deletions public_data/models/administration/Scot.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,4 @@ def search(cls, needle, region=None, departement=None, epci=None):
qs = qs.filter(similarity__gt=0.15) # Filtrer par un score minimum de similarité
qs = qs.order_by("-similarity") # Trier par score décroissant

if region:
qs = qs.filter(regions=region)
if departement:
qs = qs.filter(id=departement.id)

return qs

0 comments on commit 35e149d

Please sign in to comment.