Commit 5601e012 authored by hypsug0's avatar hypsug0
Browse files

feat: search by territory

parent 809800bc
......@@ -501,6 +501,7 @@ class PlaceFilteringMixin:
metaplace = self.request.query_params.get("metaplace", None)
convention = self.request.query_params.get("convention", None)
managed = self.request.query_params.get("managed", None)
territory = self.request.query_params.get("territory", None)
qs = Place.objects.order_by("-timestamp_create")
......@@ -543,6 +544,9 @@ class PlaceFilteringMixin:
| Q(created_by__last_name__icontains=creator)
| Q(created_by__username__icontains=creator)
)
if territory is not None:
print(f"territory {territory}")
qs = qs.filter(territory__name__icontains=territory)
qs = qs.select_related("created_by", "type").prefetch_related(
Prefetch("municipality", queryset=Municipality.objects.only("name", "code"))
......@@ -611,6 +615,8 @@ class SightingFilteringMixin:
sexual_status = self.request.query_params.get("sexual_state", None)
age = self.request.query_params.get("age", None)
breed_colo = self.request.query_params.get("breed_colo", None)
territory = self.request.query_params.get("territory", None)
if municipality is not None:
qs = qs.filter(
......@@ -690,6 +696,8 @@ class SightingFilteringMixin:
qs = qs.filter(period__icontains=period)
if breed_colo is not None:
qs = qs.filter(breed_colo=True)
if territory is not None:
qs = qs.filter(session__place__territory__name__icontains=territory)
return qs
......
......@@ -36,6 +36,8 @@ from sights.tables import (
CountDetailTelemetryTable,
)
from geodata.models import Territory
IMAGE_FILE_TYPES = ["png", "jpg", "jpeg"]
DOCUMENT_FILE_TYPES = ["doc", "docx", "odt", "pdf"]
......@@ -324,6 +326,9 @@ class SightingSearch(LoginRequiredMixin, TemplateView):
def get_context_data(self, **kwargs):
context = super(SightingSearch, self).get_context_data(**kwargs)
enable_territory = Territory.objects.filter(coverage=True).all()
print(enable_territory)
context['enable_territory']=enable_territory
context["icon"] = "fa fa-fw fa-eye"
context["title"] = _("Rechercher une observation")
context[
......
......@@ -57,6 +57,8 @@ from ..tables import (
TreeTable,
)
from geodata.models import Territory
logger = logging.getLogger(__name__)
......@@ -320,19 +322,22 @@ class PlaceDelete(PlaceEditAuthMixin, DeleteView):
# class PlaceList(
# LoginRequiredMixin, FilterView, ExportMixin, SingleTableView, TemplateView
# ):
class PlaceList(LoginRequiredMixin, TemplateView):
template_name = "sights/place_search.html"
def get_context_data(self, **kwargs):
context = super(PlaceList, self).get_context_data(**kwargs)
context["icon"] = "fa fa-fw fa-map"
context["title"] = _("Rechercher une localité")
context["createplacebtn"] = True
context[
"js"
] = """
"""
return context
# class PlaceList(LoginRequiredMixin, TemplateView):
# template_name = "sights/place_search.html"
# def get_context_data(self, **kwargs):
# context = super(PlaceList, self).get_context_data(**kwargs)
# enable_territory = Territory.objects.filter(coverage==True).all()
# print(enable_territory)
# context['enable_territory']=enable_territory
# context["icon"] = "fa fa-fw fa-map"
# context["title"] = _("Rechercher une localité")
# context["createplacebtn"] = True
# context[
# "js"
# ] = """
# """
# return context
class PlaceList(LoginRequiredMixin, TemplateView):
......@@ -340,6 +345,9 @@ class PlaceList(LoginRequiredMixin, TemplateView):
def get_context_data(self, **kwargs):
context = super(PlaceList, self).get_context_data(**kwargs)
enable_territory = Territory.objects.filter(coverage=True).all()
print(enable_territory)
context['enable_territory']=enable_territory
context["icon"] = "fa fa-fw fa-map"
context["title"] = _("Rechercher une localité")
context["createplacebtn"] = True
......
......@@ -35,6 +35,16 @@
{# </form>#}
<form id="searchForm" class="form-inline text-center">
<div class="form-row">
<div class="form-group form-group-sm mr-2">
<label for="territory" class="control-label">Département</label>
<input class="form-control form-control-sm" type="text" id="territory"
name="territory" placeholder="Département" list="territories">
<datalist id="territories">
{% for t in enable_territory %}
<option value="{{t.name}}">
{% endfor %}
</datalist>
</div>
<div class="form-group form-group-sm mr-2">
<label for="municipality" class="control-label">Commune</label>
<input class="form-control form-control-sm" type="text" id="municipality"
......
......@@ -30,6 +30,16 @@
{# </form>#}
<form id="searchForm" class="form-inline text-center">
<div class="form-row">
<div class="form-group form-group-sm mr-2">
<label for="territory" class="control-label">Département</label>
<input class="form-control form-control-sm" type="text" id="territory"
name="territory" placeholder="Département" list="territories">
<datalist id="territories">
{% for t in enable_territory %}
<option value="{{t.name}}">
{% endfor %}
</datalist>
</div>
<div class="form-group form-group-sm mr-2">
<label for="municipality">Commune</label>
<input class="form-control form-control-sm" type="text" id="municipality"
......@@ -60,7 +70,6 @@
<label for="place_type">Type de localité</label>
<input class="form-control form-control-sm" type="text" id="place_type" name="place_type"
placeholder="Type de localité">
</div>
</div>
<div class="form-row">
<div class="form-group form-group-sm mr-2">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment