Commit e7eea9a0 authored by hypsug0's avatar hypsug0
Browse files

fx: Remove heavy elements on place search API (session data aggregations)

parent 0acca16c
......@@ -223,13 +223,13 @@ const placeSearchBlock = () => {
} = d.properties
const div = document.createElement('ul')
const dataToDisplay = [
moreInfoElement('Dernière session', last_session?.date_start__max),
moreInfoElement("Types d'observations", contact?.contacts),
// moreInfoElement('Dernière session', last_session?.date_start__max),
// moreInfoElement("Types d'observations", contact?.contacts),
moreInfoElement('Commentaire', comment),
moreInfoElement('Site géré', is_managed ? 'Oui' : undefined),
moreInfoElement('Site géré', is_managed ? 'Oui' : 'Non'),
moreInfoElement(
'Convention refuge',
convention ? 'Oui' : undefined
convention ? 'Oui' : 'Non'
),
]
div.append(...dataToDisplay.filter((p) => p !== null))
......@@ -256,7 +256,7 @@ const placeSearchBlock = () => {
},
width: '100',
},
{ data: 'properties.name' },
{ data: (row) => `<a href="/place/${row.id}/detail" target="_blank">${row.properties.name}</a>` },
{ data: 'properties.altitude' },
{
data: (row) => {
......@@ -268,7 +268,7 @@ const placeSearchBlock = () => {
data: function (row) {
const data = row.properties.metaplace_data
return data?.name
? `<a href="/metaplace/${data.id_metaplace}/detail" target="_blank">data.name</a>`
? `<a href="/metaplace/${data.id_metaplace}/detail" target="_blank">${data.name}</a>`
: null
},
},
......@@ -279,13 +279,13 @@ const placeSearchBlock = () => {
: null
},
},
{
data: (row) => {
return row.properties.total_sessions
? row.properties.total_sessions
: 'Aucune'
},
},
// {
// data: (row) => {
// return row.properties.total_sessions
// ? row.properties.total_sessions
// : 'Aucune'
// },
// },
{
data: (row) => {
const creationDate = new Date(
......
......@@ -450,7 +450,11 @@ class PlaceFilteringMixin:
"""Mixin used for Place lists filtering"""
def get_queryset(self, *args, **kwargs):
qs = Place.objects
qs = (
Place.objects.select_related("municipality")
.select_related("creator")
.select_related("type")
)
municipality = self.request.query_params.get("municipality", None)
name = self.request.query_params.get("name", None)
......@@ -516,7 +520,7 @@ class PlaceFilteringMixin:
qs = qs.select_related("created_by", "type").prefetch_related(
Prefetch("municipality", queryset=Municipality.objects.only("name", "code"))
)
logger.debug(f"Q {qs}")
return qs
......@@ -679,7 +683,7 @@ class SightingFilteringMixin:
qs = qs.filter(period__icontains=period) if period is not None else qs
qs = qs.filter(breed_colo=True) if breed_colo is not None else qs
qs = qs.filter(session__place__territory__id=territory) if territory is not None else qs
logger.debug(f"Q {qs}")
return qs
......
......@@ -23,7 +23,7 @@ class GeoJSONPlaces(
def get_queryset(self):
qs = super(GeoJSONPlaces, self).get_queryset()
logger.debug(f"PLaceSearch API {qs}")
return qs.order_by("-timestamp_update").all()
......
......@@ -68,9 +68,9 @@ class PlaceSerializer(serializers.GeoFeatureModelSerializer):
type_data = PlaceTypeSerializer(source="type")
creator = PlaceUserSerializer(source="created_by")
metaplace_data = PlaceMetaplaceSerializer(source="metaplace")
total_sessions = SerializerMethodField()
last_session = SerializerMethodField()
contact = SerializerMethodField()
# total_sessions = SerializerMethodField()
# last_session = SerializerMethodField()
# contact = SerializerMethodField()
class Meta:
model = Place
......@@ -88,24 +88,24 @@ class PlaceSerializer(serializers.GeoFeatureModelSerializer):
"geom",
"creator",
"timestamp_create",
"total_sessions",
"last_session",
"contact",
# "total_sessions",
# "last_session",
# "contact",
)
def get_total_sessions(self, place):
session = Session.objects.filter(place=place.id_place)
return session.count()
# def get_total_sessions(self, place):
# session = Session.objects.filter(place=place.id_place)
# return session.count()
def get_last_session(self, place):
session = Session.objects.filter(place=place.id_place)
return session.aggregate(Max("date_start"))
# def get_last_session(self, place):
# session = Session.objects.filter(place=place.id_place)
# return session.aggregate(Max("date_start"))
def get_contact(self, place):
session = Session.objects.filter(place=place.id_place)
return session.aggregate(
contacts=StringAgg("contact__descr", delimiter=", ", distinct=True)
)
# def get_contact(self, place):
# session = Session.objects.filter(place=place.id_place)
# return session.aggregate(
# contacts=StringAgg("contact__descr", delimiter=", ", distinct=True)
# )
class PlaceBboxSerializer(serializers.GeoFeatureModelSerializer):
......
......@@ -220,7 +220,7 @@
<th>Commune</th>
<th>Métasite</th>
<th>Type</th>
<th>Sessions</th>
{% comment %} <th>Sessions</th> {% endcomment %}
<th>Création</th>
</tr>
</thead>
......
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