Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dbchiro
dbchiroweb
Commits
7aa10be0
Commit
7aa10be0
authored
Mar 16, 2021
by
hypsug0
Browse files
fix: search by territory
parent
f3f3a729
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
api/views.py
View file @
7aa10be0
...
...
@@ -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
sights/mixins.py
View file @
7aa10be0
...
...
@@ -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
...
...
templates/main/footer_main_assets.html
View file @
7aa10be0
...
...
@@ -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>
...
...
templates/sights/place_search.html
View file @
7aa10be0
...
...
@@ -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"
>
...
...
templates/sights/sighting_search.html
View file @
7aa10be0
This diff is collapsed.
Click to expand it.
Hypsug0
@fred.perso
mentioned in issue
#65 (closed)
·
Apr 07, 2021
mentioned in issue
#65 (closed)
mentioned in issue #65
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment