Skip to content

Commit

Permalink
⚡ [PERF] Delay loading filter form in List Views (#2967)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chatewgne committed Dec 27, 2024
1 parent cf156cd commit c22defd
Show file tree
Hide file tree
Showing 20 changed files with 166 additions and 49 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ CHANGELOG
2.111.0+dev (XXXX-XX-XX)
----------------------------

**Performances**

- Delay loading filter form in List Views (refs #2967)

**Documentation**

- Update theme color
- Fix typo in documentation
- Update and homogenize README.rst


2.111.0 (2024-12-05)
----------------------------

Expand Down
5 changes: 0 additions & 5 deletions geotrek/common/static/common/main.js

This file was deleted.

This file was deleted.

9 changes: 7 additions & 2 deletions geotrek/common/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from mapentity import views as mapentity_views
from mapentity.helpers import api_bbox
from mapentity.registry import app_settings, registry
from mapentity.views import MapEntityList
from mapentity.views import MapEntityList, MapEntityFilter
from paperclip import settings as settings_paperclip
from paperclip.views import _handle_attachment_form
from rest_framework import mixins, viewsets
Expand Down Expand Up @@ -292,14 +292,19 @@ def import_update_json(request):

class HDViewPointList(MapEntityList):
queryset = HDViewPoint.objects.all()
filterform = HDViewPointFilterSet
columns = ['id', 'title']


class HDViewPointFilter(MapEntityFilter):
model = HDViewPoint
filterset_class = HDViewPointFilterSet


class HDViewPointViewSet(GeotrekMapentityViewSet):
model = HDViewPoint
serializer_class = HDViewPointSerializer
geojson_serializer_class = HDViewPointGeoJSONSerializer
filterset_class = HDViewPointFilterSet
mapentity_list_class = HDViewPointList

def get_queryset(self):
Expand Down
16 changes: 13 additions & 3 deletions geotrek/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from django.views.generic.detail import BaseDetailView
from mapentity.serializers import GPXSerializer
from mapentity.views import (MapEntityList, MapEntityDetail, MapEntityDocument, MapEntityCreate, MapEntityUpdate,
MapEntityDelete, MapEntityFormat, LastModifiedMixin)
MapEntityDelete, MapEntityFormat, LastModifiedMixin, MapEntityFilter)
from rest_framework.decorators import action
from rest_framework.renderers import JSONRenderer, BrowsableAPIRenderer
from rest_framework.response import Response
Expand Down Expand Up @@ -60,14 +60,19 @@ def get_initial(self):

class PathList(CustomColumnsMixin, MapEntityList):
queryset = Path.objects.all()
filterform = PathFilterSet
mandatory_columns = ['id', 'checkbox', 'name', 'length']
default_extra_columns = ['length_2d']
unorderable_columns = ['checkbox']
searchable_columns = ['id', 'name']


class PathFilter(MapEntityFilter):
model = Path
filterset_class = PathFilterSet


class PathFormatList(MapEntityFormat, PathList):
filterset_class = PathFilterSet
mandatory_columns = ['id']
default_extra_columns = [
'structure', 'valid', 'visible', 'name', 'comments', 'departure', 'arrival',
Expand Down Expand Up @@ -343,13 +348,18 @@ class CertificationTrailMixin(FormsetMixin):

class TrailList(CustomColumnsMixin, MapEntityList):
queryset = Trail.objects.existing()
filterform = TrailFilterSet
mandatory_columns = ['id', 'name']
default_extra_columns = ['departure', 'arrival', 'length']
searchable_columns = ['id', 'name', 'departure', 'arrival', ]


class TrailFilter(MapEntityFilter):
model = Trail
filterset_class = TrailFilterSet


class TrailFormatList(MapEntityFormat, TrailList):
filterset_class = TrailFilterSet
mandatory_columns = ['id']
default_extra_columns = [
'structure', 'name', 'comments',
Expand Down
9 changes: 7 additions & 2 deletions geotrek/diving/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings
from django.contrib.gis.db.models.functions import Transform
from mapentity.views import (MapEntityList, MapEntityFormat, MapEntityDetail, MapEntityMapImage,
from mapentity.views import (MapEntityList, MapEntityFormat, MapEntityFilter, MapEntityDetail, MapEntityMapImage,
MapEntityDocument, MapEntityCreate, MapEntityUpdate, MapEntityDelete)

from geotrek.authent.decorators import same_structure_required
Expand All @@ -15,15 +15,20 @@


class DiveList(CustomColumnsMixin, FlattenPicturesMixin, MapEntityList):
filterform = DiveFilterSet
queryset = Dive.objects.existing()
mandatory_columns = ['id', 'name']
default_extra_columns = ['levels', 'thumbnail']
unorderable_columns = ['thumbnail']
searchable_columns = ['id', 'name']


class DiveFilter(MapEntityFilter):
model = Dive
filterset_class = DiveFilterSet


class DiveFormatList(MapEntityFormat, DiveList):
filterset_class = DiveFilterSet
mandatory_columns = ['id']
default_extra_columns = [
'eid', 'structure', 'name', 'departure',
Expand Down
9 changes: 7 additions & 2 deletions geotrek/feedback/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class ReportList(CustomColumnsMixin, mapentity_views.MapEntityList):
.prefetch_related("attachments")
)
model = feedback_models.Report
filterform = ReportEmailFilterSet
mandatory_columns = ['id', 'eid', 'activity']
default_extra_columns = ['category', 'status', 'date_update']
searchable_columns = ['id', 'eid']
Expand All @@ -45,6 +44,11 @@ def get_queryset(self):
qs = qs.filter(assigned_user=self.request.user)
return qs


class ReportFilter(mapentity_views.MapEntityFilter):
model = feedback_models.Report
filterset_class = ReportEmailFilterSet

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
# Remove email from available filters in workflow mode for supervisors
Expand All @@ -54,12 +58,13 @@ def get_context_data(self, **kwargs):
self._filterform.helper = FormHelper()
self._filterform.helper.field_class = 'form-control-sm'
self._filterform.helper.submit = None
context['filterform'] = self._filterform
context['filter'] = self._filterform
return context


class ReportFormatList(mapentity_views.MapEntityFormat, ReportList):
mandatory_columns = ['id', 'email']
filterset_class = ReportEmailFilterSet
default_extra_columns = [
'activity', 'comment', 'category',
'problem_magnitude', 'status', 'related_trek',
Expand Down
8 changes: 7 additions & 1 deletion geotrek/infrastructure/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
MapEntityDocument,
MapEntityFormat,
MapEntityList,
MapEntityFilter,
MapEntityUpdate,
)

Expand All @@ -25,13 +26,18 @@

class InfrastructureList(CustomColumnsMixin, MapEntityList):
queryset = Infrastructure.objects.existing()
filterform = InfrastructureFilterSet
mandatory_columns = ['id', 'name']
default_extra_columns = ['type', 'conditions', 'cities']
searchable_columns = ['id', 'name']


class InfrastructureFilter(MapEntityFilter):
model = Infrastructure
filterset_class = InfrastructureFilterSet


class InfrastructureFormatList(MapEntityFormat, InfrastructureList):
filterset_class = InfrastructureFilterSet
mandatory_columns = ['id']
default_extra_columns = [
'id', 'name', 'type', 'conditions', 'description', 'accessibility',
Expand Down
44 changes: 37 additions & 7 deletions geotrek/land/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings
from django.contrib.gis.db.models.functions import Transform
from mapentity.views import (MapEntityList, MapEntityFormat, MapEntityDetail, MapEntityDocument,
from mapentity.views import (MapEntityList, MapEntityFormat, MapEntityFilter, MapEntityDetail, MapEntityDocument,
MapEntityCreate, MapEntityUpdate, MapEntityDelete)

from geotrek.common.mixins.views import CustomColumnsMixin
Expand All @@ -22,12 +22,17 @@

class PhysicalEdgeList(CustomColumnsMixin, CreateFromTopologyMixin, MapEntityList):
queryset = PhysicalEdge.objects.existing()
filterform = PhysicalEdgeFilterSet
mandatory_columns = ['id', 'physical_type']
default_extra_columns = ['length', 'length_2d']


class PhysicalEdgeFilter(MapEntityFilter):
model = PhysicalEdge
filterset_class = PhysicalEdgeFilterSet


class PhysicalEdgeFormatList(MapEntityFormat, PhysicalEdgeList):
filterset_class = PhysicalEdgeFilterSet
mandatory_columns = ['id', 'physical_type']
default_extra_columns = [
'date_insert', 'date_update',
Expand Down Expand Up @@ -77,12 +82,17 @@ def get_queryset(self):

class LandEdgeList(CustomColumnsMixin, MapEntityList):
queryset = LandEdge.objects.existing()
filterform = LandEdgeFilterSet
mandatory_columns = ['id', 'land_type']
default_extra_columns = ['length', 'length_2d']


class LandEdgeFilter(MapEntityFilter):
model = LandEdge
filterset_class = LandEdgeFilterSet


class LandEdgeFormatList(MapEntityFormat, LandEdgeList):
filterset_class = LandEdgeFilterSet
mandatory_columns = ['id']
default_extra_columns = [
'land_type', 'owner', 'agreement', 'date_insert', 'date_update',
Expand Down Expand Up @@ -130,12 +140,17 @@ def get_queryset(self):

class CirculationEdgeList(CustomColumnsMixin, MapEntityList):
queryset = CirculationEdge.objects.existing()
filterform = CirculationEdgeFilterSet
mandatory_columns = ['id', 'circulation_type', 'authorization_type']
default_extra_columns = ['length', 'length_2d']


class CirculationEdgeFilter(MapEntityFilter):
model = CirculationEdge
filterset_class = CirculationEdgeFilterSet


class CirculationEdgeFormatList(MapEntityFormat, CirculationEdgeList):
filterset_class = CirculationEdgeFilterSet
mandatory_columns = ['id']
default_extra_columns = [
'circulation_type', 'authorization_type', 'date_insert', 'date_update',
Expand Down Expand Up @@ -183,12 +198,17 @@ def get_queryset(self):

class CompetenceEdgeList(CustomColumnsMixin, MapEntityList):
queryset = CompetenceEdge.objects.existing()
filterform = CompetenceEdgeFilterSet
mandatory_columns = ['id', 'organization']
default_extra_columns = ['length', 'length_2d']


class CompetenceEdgeFilter(MapEntityFilter):
model = CompetenceEdge
filterset_class = CompetenceEdgeFilterSet


class CompetenceEdgeFormatList(MapEntityFormat, CompetenceEdgeList):
filterset_class = CompetenceEdgeFilterSet
mandatory_columns = ['id', 'organization']
default_extra_columns = [
'date_insert', 'date_update',
Expand Down Expand Up @@ -236,12 +256,17 @@ def get_queryset(self):

class WorkManagementEdgeList(CustomColumnsMixin, MapEntityList):
queryset = WorkManagementEdge.objects.existing()
filterform = WorkManagementEdgeFilterSet
mandatory_columns = ['id', 'organization']
default_extra_columns = ['length', 'length_2d']


class WorkManagementEdgeFilter(MapEntityFilter):
model = WorkManagementEdge
filterset_class = WorkManagementEdgeFilterSet


class WorkManagementEdgeFormatList(MapEntityFormat, WorkManagementEdgeList):
filterset_class = WorkManagementEdgeFilterSet
mandatory_columns = ['id', 'organization']
default_extra_columns = [
'date_insert', 'date_update', 'cities', 'districts', 'areas', 'uuid', 'length_2d'
Expand Down Expand Up @@ -288,12 +313,17 @@ def get_queryset(self):

class SignageManagementEdgeList(CustomColumnsMixin, MapEntityList):
queryset = SignageManagementEdge.objects.existing()
filterform = SignageManagementEdgeFilterSet
mandatory_columns = ['id', 'organization']
default_extra_columns = ['length', 'length_2d']


class SignageManagementEdgeFilter(MapEntityFilter):
model = SignageManagementEdge
filterset_class = SignageManagementEdgeFilterSet


class SignageManagementEdgeFormatList(MapEntityFormat, SignageManagementEdgeList):
filterset_class = SignageManagementEdgeFilterSet
mandatory_columns = ['id', 'organization']
default_extra_columns = [
'date_insert', 'date_update', 'cities', 'districts', 'areas', 'uuid', 'length_2d'
Expand Down
2 changes: 1 addition & 1 deletion geotrek/maintenance/static/maintenance/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $(window).on('entity:view:add', function (e, data) {
};
});

$(window).on('entity:view:list', function (e, data) {
$(window).on('entity:view:filter', function (e, data) {
if (data.modelname === "intervention"){
setDatePickerConfig('#id_begin_date_0, #id_begin_date_1, #id_end_date_0, #id_end_date_1');
};
Expand Down
16 changes: 13 additions & 3 deletions geotrek/maintenance/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.db.models import Subquery, OuterRef, Sum
from django.db.models.expressions import Value
from django.utils.translation import gettext_lazy as _
from mapentity.views import (MapEntityList, MapEntityFormat, MapEntityDetail, MapEntityDocument,
from mapentity.views import (MapEntityList, MapEntityFormat, MapEntityFilter, MapEntityDetail, MapEntityDocument,
MapEntityCreate, MapEntityUpdate, MapEntityDelete)

from geotrek.altimetry.models import AltimetryMixin
Expand Down Expand Up @@ -34,14 +34,19 @@ def _normalize_annotation_column_name(col_name):

class InterventionList(CustomColumnsMixin, MapEntityList):
queryset = Intervention.objects.existing()
filterform = InterventionFilterSet
mandatory_columns = ['id', 'name']
default_extra_columns = ['begin_date', 'end_date', 'type', 'target', 'status', 'stake']
searchable_columns = ['id', 'name']
unorderable_columns = ['target']


class InterventionFilter(MapEntityFilter):
model = Intervention
filterset_class = InterventionFilterSet


class InterventionFormatList(MapEntityFormat, InterventionList):
filterset_class = InterventionFilterSet

@classmethod
def build_cost_column_name(cls, job_name):
Expand Down Expand Up @@ -190,14 +195,19 @@ def get_queryset(self):

class ProjectList(CustomColumnsMixin, MapEntityList):
queryset = Project.objects.existing()
filterform = ProjectFilterSet
mandatory_columns = ['id', 'name']
default_extra_columns = ['period', 'type', 'domain']
searchable_columns = ['id', 'name']
unorderable_columns = ['period', ]


class ProjectFilter(MapEntityFilter):
model = Project
filterset_class = ProjectFilterSet


class ProjectFormatList(MapEntityFormat, ProjectList):
filterset_class = ProjectFilterSet
mandatory_columns = ['id']
default_extra_columns = [
'structure', 'name', 'period', 'type', 'domain', 'constraint', 'global_cost',
Expand Down
Loading

0 comments on commit c22defd

Please sign in to comment.