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