Class based views

* refactors method based views for parcel fetching, home and logout to class based
This commit is contained in:
mpeltriaux 2023-08-15 11:29:38 +02:00
parent 6de3fab800
commit 865a3a51fe
5 changed files with 156 additions and 145 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
# Project exclude paths # Project exclude paths
/venv/ /venv/
/.idea/ /.idea/
/.coverage
/htmlcov/

View File

@ -19,17 +19,17 @@ from django.urls import path, include
from konova.settings import SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY, DEBUG from konova.settings import SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY, DEBUG
from konova.sso.sso import KonovaSSOClient from konova.sso.sso import KonovaSSOClient
from konova.views.logout import logout_view from konova.views.logout import LogoutView
from konova.views.geometry import get_geom_parcels, get_geom_parcels_content from konova.views.geometry import GeomParcelsView, GeomParcelsContentView
from konova.views.home import home_view from konova.views.home import HomeView
from konova.views.map_proxy import ClientProxyParcelSearch, ClientProxyParcelWFS from konova.views.map_proxy import ClientProxyParcelSearch, ClientProxyParcelWFS
sso_client = KonovaSSOClient(SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY) sso_client = KonovaSSOClient(SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY)
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('login/', include(sso_client.get_urls())), path('login/', include(sso_client.get_urls())),
path('logout/', logout_view, name="logout"), path('logout/', LogoutView.as_view(), name="logout"),
path('', home_view, name="home"), path('', HomeView.as_view(), name="home"),
path('intervention/', include("intervention.urls")), path('intervention/', include("intervention.urls")),
path('compensation/', include("compensation.urls")), path('compensation/', include("compensation.urls")),
path('ema/', include("ema.urls")), path('ema/', include("ema.urls")),
@ -38,8 +38,8 @@ urlpatterns = [
path('cl/', include("codelist.urls")), path('cl/', include("codelist.urls")),
path('analysis/', include("analysis.urls")), path('analysis/', include("analysis.urls")),
path('api/', include("api.urls")), path('api/', include("api.urls")),
path('geom/<id>/parcels/', get_geom_parcels, name="geometry-parcels"), path('geom/<id>/parcels/', GeomParcelsView.as_view(), name="geometry-parcels"),
path('geom/<id>/parcels/<int:page>', get_geom_parcels_content, name="geometry-parcels-content"), path('geom/<id>/parcels/<int:page>', GeomParcelsContentView.as_view(), name="geometry-parcels-content"),
path('client/proxy', ClientProxyParcelSearch.as_view(), name="client-proxy-search"), path('client/proxy', ClientProxyParcelSearch.as_view(), name="client-proxy-search"),
path('client/proxy/wfs', ClientProxyParcelWFS.as_view(), name="client-proxy-wfs"), path('client/proxy/wfs', ClientProxyParcelWFS.as_view(), name="client-proxy-wfs"),
] ]

View File

@ -5,16 +5,20 @@ Contact: ksp-servicestelle@sgdnord.rlp.de
Created on: 19.08.22 Created on: 19.08.22
""" """
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.gis.geos import MultiPolygon from django.contrib.gis.geos import MultiPolygon
from django.http import HttpResponse, HttpRequest 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.views import View
from konova.models import Geometry, Municipal from konova.models import Geometry
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
def get_geom_parcels(request: HttpRequest, id: str): class GeomParcelsView(LoginRequiredMixin, View):
def get(self, request: HttpRequest, id: str):
""" Getter for HTMX """ Getter for HTMX
Returns all parcels of the requested geometry rendered into a simple HTML table Returns all parcels of the requested geometry rendered into a simple HTML table
@ -66,7 +70,9 @@ def get_geom_parcels(request: HttpRequest, id: str):
return HttpResponse(None, status=404) return HttpResponse(None, status=404)
def get_geom_parcels_content(request: HttpRequest, id: str, page: int): class GeomParcelsContentView(LoginRequiredMixin, View):
def get(self, request: HttpRequest, id: str, page: int):
""" Getter for infinite scroll of HTMX """ Getter for infinite scroll of HTMX
Returns parcels of a specific page/slice of the found parcel set. Returns parcels of a specific page/slice of the found parcel set.

View File

@ -5,12 +5,13 @@ Contact: ksp-servicestelle@sgdnord.rlp.de
Created on: 19.08.22 Created on: 19.08.22
""" """
from django.contrib.auth.decorators import login_required from django.contrib.auth.mixins import LoginRequiredMixin
from django.db.models import Q from django.db.models import Q
from django.http import HttpRequest from django.http import HttpRequest
from django.shortcuts import render from django.shortcuts import render
from django.utils import timezone from django.utils.decorators import method_decorator
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views import View
from compensation.models import EcoAccount, Compensation from compensation.models import EcoAccount, Compensation
from intervention.models import Intervention from intervention.models import Intervention
@ -20,9 +21,10 @@ from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
from news.models import ServerMessage from news.models import ServerMessage
@login_required class HomeView(LoginRequiredMixin, View):
@any_group_check
def home_view(request: HttpRequest): @method_decorator(any_group_check)
def get(self, request: HttpRequest):
""" """
Renders the landing page Renders the landing page
@ -33,7 +35,6 @@ def home_view(request: HttpRequest):
A redirect A redirect
""" """
template = "konova/home.html" template = "konova/home.html"
now = timezone.now()
user = request.user user = request.user
user_teams = user.shared_teams user_teams = user.shared_teams

View File

@ -8,11 +8,13 @@ Created on: 19.08.22
from django.contrib.auth import logout from django.contrib.auth import logout
from django.http import HttpRequest from django.http import HttpRequest
from django.shortcuts import redirect from django.shortcuts import redirect
from django.views import View
from konova.sub_settings.sso_settings import SSO_SERVER_BASE from konova.sub_settings.sso_settings import SSO_SERVER_BASE
def logout_view(request: HttpRequest): class LogoutView(View):
def get(self, request: HttpRequest):
""" """
Logout route for ending the session manually. Logout route for ending the session manually.