# Parcel view refactoring

* refactors parcel view to inherit from BaseView
This commit is contained in:
mpeltriaux 2025-10-21 14:06:11 +02:00
parent d2a57df080
commit 1175fe3b37

View File

@ -10,15 +10,16 @@ from django.http import HttpResponse, HttpRequest
from django.shortcuts import get_object_or_404
from django.template.loader import render_to_string
from django.utils import timezone
from django.views import View
from konova.models import Geometry
from konova.settings import GEOM_THRESHOLD_RECALCULATION_SECONDS
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
from konova.tasks import celery_update_parcels
from konova.views.base import BaseView
class GeomParcelsView(View):
class GeomParcelsView(BaseView):
_TEMPLATE = "konova/includes/parcels/parcel_table_frame.html"
def get(self, request: HttpRequest, id: str):
""" Getter for HTMX
@ -32,7 +33,6 @@ class GeomParcelsView(View):
Returns:
A rendered piece of HTML
"""
template = "konova/includes/parcels/parcel_table_frame.html"
geom = get_object_or_404(Geometry, id=id)
geos_geom = geom.geom or MultiPolygon(srid=DEFAULT_SRID_RLP)
@ -85,7 +85,7 @@ class GeomParcelsView(View):
"geom_id": str(id),
"next_page": next_page,
}
html = render_to_string(template, context, request)
html = render_to_string(self._TEMPLATE, context, request)
return HttpResponse(html, status=status_code)
else:
return HttpResponse(None, status=404)
@ -107,8 +107,15 @@ class GeomParcelsView(View):
waiting_too_long = (pcs_diff >= wait_for_seconds)
return waiting_too_long
def _user_has_shared_access(self, user, **kwargs):
return True
class GeomParcelsContentView(View):
def _user_has_permission(self, user):
return True
class GeomParcelsContentView(BaseView):
_TEMPLATE = "konova/includes/parcels/parcel_table_content.html"
def get(self, request: HttpRequest, id: str, page: int):
""" Getter for infinite scroll of HTMX
@ -130,7 +137,6 @@ class GeomParcelsContentView(View):
# HTTP code 286 states that the HTMX should stop polling for updates
# https://htmx.org/docs/#polling
status_code = 286
template = "konova/includes/parcels/parcel_table_content.html"
geom = get_object_or_404(Geometry, id=id)
parcels = geom.get_underlying_parcels()
@ -148,5 +154,11 @@ class GeomParcelsContentView(View):
"geom_id": str(id),
"next_page": next_page,
}
html = render_to_string(template, context, request)
html = render_to_string(self._TEMPLATE, context, request)
return HttpResponse(html, status=status_code)
def _user_has_shared_access(self, user, **kwargs):
return True
def _user_has_permission(self, user):
return True