Commit 7aa10be0 authored by hypsug0's avatar hypsug0
Browse files

fix: search by territory

parent f3f3a729
......@@ -14,6 +14,7 @@ from accounts.models import UserFullName
from dicts.models import Specie
from geodata.models import Territory, Municipality
from sights.models import Place, MetaPlace
from management.models import Study
# Get an instance of a logger
logger = logging.getLogger(__name__)
......@@ -377,3 +378,17 @@ def places_in_metaplace_as_geojson(request, pk):
field = ("pk", "name")
geojson = serialize("geojson", place_list, geometry_field="geom", fields=field)
return HttpResponse(geojson, content_type="application/json")
class StudyAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
# Don't forget to filter out results depending on the visitor !
if not self.request.user.is_authenticated:
return Study.objects.none()
qs = Study.objects.all().order_by("name")
if self.q:
qs = qs.filter(name__icontains=self.q)
return qs
......@@ -545,8 +545,7 @@ class PlaceFilteringMixin:
| Q(created_by__username__icontains=creator)
)
if territory is not None:
print(f"territory {territory}")
qs = qs.filter(territory__name__icontains=territory)
qs = qs.filter(territory__id=territory)
qs = qs.select_related("created_by", "type").prefetch_related(
Prefetch("municipality", queryset=Municipality.objects.only("name", "code"))
......@@ -697,7 +696,7 @@ class SightingFilteringMixin:
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)
qs = qs.filter(session__place__territory__id=territory)
return qs
......
......@@ -2,6 +2,7 @@
{% load cache %}
{% cache 500 jsload %}
<script src="{% static 'js/jquery/jquery.min.js' %} "></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="{% static 'js/datatables.min.js' %} "></script>
<script src="{% static 'js/moment.min.js' %} "></script>
<script src="{% static 'js/bootstrap-datetimepicker.min.js' %} "></script>
......
......@@ -35,16 +35,15 @@
{# </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="territory" class="control-label">Département</label>
<select class="form-control form-control-sm" name="territory" id="territory">
<option value="">-</option>
{% for t in enable_territory %}
<option value="{{t.id}}">{{ t.name }} ({{ t.code }})</option>
{% endfor %}
</select>
</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"
......@@ -525,7 +524,7 @@
function showValues() {
var str = $('#searchForm input').map(function () {
var str = $('#searchForm input, select').map(function () {
return $(this).val().trim() == "" ? null : this;
}).serialize();
$("#results").text(str);
......@@ -563,14 +562,8 @@
</script>
{% endif %}
{# <div class="col-sm-12 col-md-6 col-lg-5">#}
{# {% leaflet_map "main" %}#}
{# </div>#}
<div class="col-sm-12 col-md-6 col-lg-5">
{% leaflet_map "main" %}
{# <div id="searchMap">#}
{# <div id="spinner"></div>#}
{# </div>#}
</div>
<script type="text/javascript">
......
This diff is collapsed.
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