# Index views
* refactors index view methods into classes * introduces AbstractIndexView as base class
This commit is contained in:
parent
4c4d64cc3d
commit
fdf3adf5ae
@ -17,13 +17,13 @@ from compensation.views.compensation.action import NewCompensationActionView, Ed
|
|||||||
RemoveCompensationActionView
|
RemoveCompensationActionView
|
||||||
from compensation.views.compensation.state import NewCompensationStateView, EditCompensationStateView, \
|
from compensation.views.compensation.state import NewCompensationStateView, EditCompensationStateView, \
|
||||||
RemoveCompensationStateView
|
RemoveCompensationStateView
|
||||||
from compensation.views.compensation.compensation import index_view, new_view, new_id_view, detail_view, edit_view, \
|
from compensation.views.compensation.compensation import new_view, new_id_view, detail_view, edit_view, \
|
||||||
remove_view
|
remove_view, IndexCompensationView
|
||||||
from compensation.views.compensation.log import CompensationLogView
|
from compensation.views.compensation.log import CompensationLogView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# Main compensation
|
# Main compensation
|
||||||
path("", index_view, name="index"),
|
path("", IndexCompensationView.as_view(), name="index"),
|
||||||
path('new/id', new_id_view, name='new-id'),
|
path('new/id', new_id_view, name='new-id'),
|
||||||
path('new/<intervention_id>', new_view, name='new'),
|
path('new/<intervention_id>', new_view, name='new'),
|
||||||
path('new', new_view, name='new'),
|
path('new', new_view, name='new'),
|
||||||
|
|||||||
@ -8,8 +8,8 @@ Created on: 24.08.21
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from compensation.autocomplete.eco_account import EcoAccountAutocomplete
|
from compensation.autocomplete.eco_account import EcoAccountAutocomplete
|
||||||
from compensation.views.eco_account.eco_account import index_view, new_view, new_id_view, edit_view, remove_view, \
|
from compensation.views.eco_account.eco_account import new_view, new_id_view, edit_view, remove_view, \
|
||||||
detail_view
|
detail_view, IndexEcoAccountView
|
||||||
from compensation.views.eco_account.log import EcoAccountLogView
|
from compensation.views.eco_account.log import EcoAccountLogView
|
||||||
from compensation.views.eco_account.record import EcoAccountRecordView
|
from compensation.views.eco_account.record import EcoAccountRecordView
|
||||||
from compensation.views.eco_account.report import report_view
|
from compensation.views.eco_account.report import report_view
|
||||||
@ -28,7 +28,7 @@ from compensation.views.eco_account.deduction import NewEcoAccountDeductionView,
|
|||||||
|
|
||||||
app_name = "acc"
|
app_name = "acc"
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", index_view, name="index"),
|
path("", IndexEcoAccountView.as_view(), name="index"),
|
||||||
path('new/', new_view, name='new'),
|
path('new/', new_view, name='new'),
|
||||||
path('new/id', new_id_view, name='new-id'),
|
path('new/id', new_id_view, name='new-id'),
|
||||||
path('<id>', detail_view, name='detail'),
|
path('<id>', detail_view, name='detail'),
|
||||||
|
|||||||
@ -8,8 +8,7 @@ Created on: 19.08.22
|
|||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.db.models import Sum
|
from django.http import HttpRequest, JsonResponse, HttpResponse
|
||||||
from django.http import HttpRequest, JsonResponse
|
|
||||||
from django.shortcuts import get_object_or_404, render, redirect
|
from django.shortcuts import get_object_or_404, render, redirect
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
@ -28,38 +27,36 @@ from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
|||||||
from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE, DATA_CHECKED_PREVIOUSLY_TEMPLATE, \
|
from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE, DATA_CHECKED_PREVIOUSLY_TEMPLATE, \
|
||||||
RECORDED_BLOCKS_EDIT, CHECK_STATE_RESET, FORM_INVALID, PARAMS_INVALID, IDENTIFIER_REPLACED, \
|
RECORDED_BLOCKS_EDIT, CHECK_STATE_RESET, FORM_INVALID, PARAMS_INVALID, IDENTIFIER_REPLACED, \
|
||||||
COMPENSATION_ADDED_TEMPLATE, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
COMPENSATION_ADDED_TEMPLATE, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
||||||
|
from konova.views.index import AbstractIndexView
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class IndexCompensationView(AbstractIndexView):
|
||||||
@any_group_check
|
def get(self, request, *args, **kwargs) -> HttpResponse:
|
||||||
def index_view(request: HttpRequest):
|
"""
|
||||||
"""
|
Renders the index view for compensation
|
||||||
Renders the index view for compensation
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
request (HttpRequest): The incoming request
|
request (HttpRequest): The incoming request
|
||||||
|
|
||||||
Returns:
|
|
||||||
A rendered view
|
|
||||||
"""
|
|
||||||
template = "generic_index.html"
|
|
||||||
compensations = Compensation.objects.filter(
|
|
||||||
deleted=None, # only show those which are not deleted individually
|
|
||||||
intervention__deleted=None, # and don't show the ones whose intervention has been deleted
|
|
||||||
).order_by(
|
|
||||||
"-modified__timestamp"
|
|
||||||
)
|
|
||||||
table = CompensationTable(
|
|
||||||
request=request,
|
|
||||||
queryset=compensations
|
|
||||||
)
|
|
||||||
context = {
|
|
||||||
"table": table,
|
|
||||||
TAB_TITLE_IDENTIFIER: _("Compensations - Overview"),
|
|
||||||
}
|
|
||||||
context = BaseContext(request, context).context
|
|
||||||
return render(request, template, context)
|
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A rendered view
|
||||||
|
"""
|
||||||
|
compensations = Compensation.objects.filter(
|
||||||
|
deleted=None, # only show those which are not deleted individually
|
||||||
|
intervention__deleted=None, # and don't show the ones whose intervention has been deleted
|
||||||
|
).order_by(
|
||||||
|
"-modified__timestamp"
|
||||||
|
)
|
||||||
|
table = CompensationTable(
|
||||||
|
request=request,
|
||||||
|
queryset=compensations
|
||||||
|
)
|
||||||
|
context = {
|
||||||
|
"table": table,
|
||||||
|
TAB_TITLE_IDENTIFIER: _("Compensations - Overview"),
|
||||||
|
}
|
||||||
|
context = BaseContext(request, context).context
|
||||||
|
return render(request, self._TEMPLATE, context)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@default_group_required
|
@default_group_required
|
||||||
|
|||||||
@ -7,8 +7,7 @@ Created on: 19.08.22
|
|||||||
"""
|
"""
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.db.models import Sum
|
from django.http import HttpRequest, JsonResponse, HttpResponse
|
||||||
from django.http import HttpRequest, JsonResponse
|
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
@ -24,36 +23,35 @@ from konova.settings import ETS_GROUP, DEFAULT_GROUP, ZB_GROUP
|
|||||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||||
from konova.utils.message_templates import CANCEL_ACC_RECORDED_OR_DEDUCTED, RECORDED_BLOCKS_EDIT, FORM_INVALID, \
|
from konova.utils.message_templates import CANCEL_ACC_RECORDED_OR_DEDUCTED, RECORDED_BLOCKS_EDIT, FORM_INVALID, \
|
||||||
IDENTIFIER_REPLACED, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
IDENTIFIER_REPLACED, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
||||||
|
from konova.views.index import AbstractIndexView
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class IndexEcoAccountView(AbstractIndexView):
|
||||||
@any_group_check
|
def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
|
||||||
def index_view(request: HttpRequest):
|
"""
|
||||||
"""
|
Renders the index view for eco accounts
|
||||||
Renders the index view for eco accounts
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
request (HttpRequest): The incoming request
|
request (HttpRequest): The incoming request
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A rendered view
|
A rendered view
|
||||||
"""
|
"""
|
||||||
template = "generic_index.html"
|
eco_accounts = EcoAccount.objects.filter(
|
||||||
eco_accounts = EcoAccount.objects.filter(
|
deleted=None,
|
||||||
deleted=None,
|
).order_by(
|
||||||
).order_by(
|
"-modified__timestamp"
|
||||||
"-modified__timestamp"
|
)
|
||||||
)
|
table = EcoAccountTable(
|
||||||
table = EcoAccountTable(
|
request=request,
|
||||||
request=request,
|
queryset=eco_accounts
|
||||||
queryset=eco_accounts
|
)
|
||||||
)
|
context = {
|
||||||
context = {
|
"table": table,
|
||||||
"table": table,
|
TAB_TITLE_IDENTIFIER: _("Eco-account - Overview"),
|
||||||
TAB_TITLE_IDENTIFIER: _("Eco-account - Overview"),
|
}
|
||||||
}
|
context = BaseContext(request, context).context
|
||||||
context = BaseContext(request, context).context
|
return render(request, self._TEMPLATE, context)
|
||||||
return render(request, template, context)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
@ -10,7 +10,7 @@ from django.urls import path
|
|||||||
from ema.views.action import NewEmaActionView, EditEmaActionView, RemoveEmaActionView
|
from ema.views.action import NewEmaActionView, EditEmaActionView, RemoveEmaActionView
|
||||||
from ema.views.deadline import NewEmaDeadlineView, EditEmaDeadlineView, RemoveEmaDeadlineView
|
from ema.views.deadline import NewEmaDeadlineView, EditEmaDeadlineView, RemoveEmaDeadlineView
|
||||||
from ema.views.document import NewEmaDocumentView, EditEmaDocumentView, RemoveEmaDocumentView, GetEmaDocumentView
|
from ema.views.document import NewEmaDocumentView, EditEmaDocumentView, RemoveEmaDocumentView, GetEmaDocumentView
|
||||||
from ema.views.ema import index_view, new_view, new_id_view, detail_view, edit_view, remove_view
|
from ema.views.ema import new_view, new_id_view, detail_view, edit_view, remove_view, IndexEmaView
|
||||||
from ema.views.log import EmaLogView
|
from ema.views.log import EmaLogView
|
||||||
from ema.views.record import EmaRecordView
|
from ema.views.record import EmaRecordView
|
||||||
from ema.views.report import report_view
|
from ema.views.report import report_view
|
||||||
@ -20,7 +20,7 @@ from ema.views.state import NewEmaStateView, EditEmaStateView, RemoveEmaStateVie
|
|||||||
|
|
||||||
app_name = "ema"
|
app_name = "ema"
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", index_view, name="index"),
|
path("", IndexEmaView.as_view(), name="index"),
|
||||||
path("new/", new_view, name="new"),
|
path("new/", new_view, name="new"),
|
||||||
path("new/id", new_id_view, name="new-id"),
|
path("new/id", new_id_view, name="new-id"),
|
||||||
path("<id>", detail_view, name="detail"),
|
path("<id>", detail_view, name="detail"),
|
||||||
|
|||||||
@ -7,8 +7,7 @@ Created on: 19.08.22
|
|||||||
"""
|
"""
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.db.models import Sum
|
from django.http import HttpRequest, JsonResponse, HttpResponse
|
||||||
from django.http import HttpRequest, JsonResponse
|
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
@ -25,35 +24,35 @@ from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP
|
|||||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||||
from konova.utils.message_templates import RECORDED_BLOCKS_EDIT, IDENTIFIER_REPLACED, FORM_INVALID, \
|
from konova.utils.message_templates import RECORDED_BLOCKS_EDIT, IDENTIFIER_REPLACED, FORM_INVALID, \
|
||||||
DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
||||||
|
from konova.views.index import AbstractIndexView
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class IndexEmaView(AbstractIndexView):
|
||||||
def index_view(request: HttpRequest):
|
def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
|
||||||
""" Renders the index view for EMAs
|
""" Renders the index view for EMAs
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
request (HttpRequest): The incoming request
|
request (HttpRequest): The incoming request
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
template = "generic_index.html"
|
emas = Ema.objects.filter(
|
||||||
emas = Ema.objects.filter(
|
deleted=None,
|
||||||
deleted=None,
|
).order_by(
|
||||||
).order_by(
|
"-modified__timestamp"
|
||||||
"-modified__timestamp"
|
)
|
||||||
)
|
|
||||||
|
|
||||||
table = EmaTable(
|
table = EmaTable(
|
||||||
request,
|
request,
|
||||||
queryset=emas
|
queryset=emas
|
||||||
)
|
)
|
||||||
context = {
|
context = {
|
||||||
"table": table,
|
"table": table,
|
||||||
TAB_TITLE_IDENTIFIER: _("EMAs - Overview"),
|
TAB_TITLE_IDENTIFIER: _("EMAs - Overview"),
|
||||||
}
|
}
|
||||||
context = BaseContext(request, context).context
|
context = BaseContext(request, context).context
|
||||||
return render(request, template, context)
|
return render(request, self._TEMPLATE, context)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
@ -14,7 +14,8 @@ from intervention.views.deduction import NewInterventionDeductionView, EditInter
|
|||||||
RemoveInterventionDeductionView
|
RemoveInterventionDeductionView
|
||||||
from intervention.views.document import NewInterventionDocumentView, GetInterventionDocumentView, \
|
from intervention.views.document import NewInterventionDocumentView, GetInterventionDocumentView, \
|
||||||
RemoveInterventionDocumentView, EditInterventionDocumentView
|
RemoveInterventionDocumentView, EditInterventionDocumentView
|
||||||
from intervention.views.intervention import index_view, new_view, new_id_view, detail_view, edit_view, remove_view
|
from intervention.views.intervention import new_view, new_id_view, detail_view, edit_view, remove_view, \
|
||||||
|
IndexInterventionView
|
||||||
from intervention.views.log import InterventionLogView
|
from intervention.views.log import InterventionLogView
|
||||||
from intervention.views.record import InterventionRecordView
|
from intervention.views.record import InterventionRecordView
|
||||||
from intervention.views.report import report_view
|
from intervention.views.report import report_view
|
||||||
@ -25,7 +26,7 @@ from intervention.views.share import InterventionShareFormView, InterventionShar
|
|||||||
|
|
||||||
app_name = "intervention"
|
app_name = "intervention"
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", index_view, name="index"),
|
path("", IndexInterventionView.as_view(), name="index"),
|
||||||
path('new/', new_view, name='new'),
|
path('new/', new_view, name='new'),
|
||||||
path('new/id', new_id_view, name='new-id'),
|
path('new/id', new_id_view, name='new-id'),
|
||||||
path('<id>', detail_view, name='detail'),
|
path('<id>', detail_view, name='detail'),
|
||||||
|
|||||||
@ -7,7 +7,7 @@ Created on: 19.08.22
|
|||||||
"""
|
"""
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.http import JsonResponse, HttpRequest
|
from django.http import JsonResponse, HttpRequest, HttpResponse
|
||||||
from django.shortcuts import get_object_or_404, render, redirect
|
from django.shortcuts import get_object_or_404, render, redirect
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
@ -25,40 +25,38 @@ from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
|||||||
from konova.utils.message_templates import DATA_CHECKED_PREVIOUSLY_TEMPLATE, RECORDED_BLOCKS_EDIT, \
|
from konova.utils.message_templates import DATA_CHECKED_PREVIOUSLY_TEMPLATE, RECORDED_BLOCKS_EDIT, \
|
||||||
CHECK_STATE_RESET, FORM_INVALID, IDENTIFIER_REPLACED, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, \
|
CHECK_STATE_RESET, FORM_INVALID, IDENTIFIER_REPLACED, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, \
|
||||||
GEOMETRIES_IGNORED_TEMPLATE
|
GEOMETRIES_IGNORED_TEMPLATE
|
||||||
|
from konova.views.index import AbstractIndexView
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class IndexInterventionView(AbstractIndexView):
|
||||||
@any_group_check
|
def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
|
||||||
def index_view(request: HttpRequest):
|
"""
|
||||||
"""
|
Renders the index view for Interventions
|
||||||
Renders the index view for Interventions
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
request (HttpRequest): The incoming request
|
request (HttpRequest): The incoming request
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A rendered view
|
A rendered view
|
||||||
"""
|
"""
|
||||||
template = "generic_index.html"
|
# Filtering by user access is performed in table filter inside InterventionTableFilter class
|
||||||
|
interventions = Intervention.objects.filter(
|
||||||
# Filtering by user access is performed in table filter inside InterventionTableFilter class
|
deleted=None, # not deleted
|
||||||
interventions = Intervention.objects.filter(
|
).select_related(
|
||||||
deleted=None, # not deleted
|
"legal"
|
||||||
).select_related(
|
).order_by(
|
||||||
"legal"
|
"-modified__timestamp"
|
||||||
).order_by(
|
)
|
||||||
"-modified__timestamp"
|
table = InterventionTable(
|
||||||
)
|
request=request,
|
||||||
table = InterventionTable(
|
queryset=interventions
|
||||||
request=request,
|
)
|
||||||
queryset=interventions
|
context = {
|
||||||
)
|
"table": table,
|
||||||
context = {
|
TAB_TITLE_IDENTIFIER: _("Interventions - Overview"),
|
||||||
"table": table,
|
}
|
||||||
TAB_TITLE_IDENTIFIER: _("Interventions - Overview"),
|
context = BaseContext(request, context).context
|
||||||
}
|
return render(request, self._TEMPLATE, context)
|
||||||
context = BaseContext(request, context).context
|
|
||||||
return render(request, template, context)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
23
konova/views/index.py
Normal file
23
konova/views/index.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Created on: 14.12.25
|
||||||
|
|
||||||
|
"""
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
from django.utils.decorators import method_decorator
|
||||||
|
from django.views import View
|
||||||
|
|
||||||
|
from konova.decorators import any_group_check
|
||||||
|
|
||||||
|
|
||||||
|
class AbstractIndexView(LoginRequiredMixin, View):
|
||||||
|
_TEMPLATE = "generic_index.html"
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
@method_decorator(login_required)
|
||||||
|
@method_decorator(any_group_check)
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
return super().dispatch(request, *args, **kwargs)
|
||||||
Loading…
x
Reference in New Issue
Block a user