# Detail View
* refactors detail view methods into classes * introduces AbstractDetailView
This commit is contained in:
@@ -14,8 +14,8 @@ from intervention.views.deduction import NewInterventionDeductionView, EditInter
|
||||
RemoveInterventionDeductionView
|
||||
from intervention.views.document import NewInterventionDocumentView, GetInterventionDocumentView, \
|
||||
RemoveInterventionDocumentView, EditInterventionDocumentView
|
||||
from intervention.views.intervention import new_view, new_id_view, detail_view, edit_view, remove_view, \
|
||||
IndexInterventionView
|
||||
from intervention.views.intervention import new_view, new_id_view, edit_view, remove_view, \
|
||||
IndexInterventionView, DetailInterventionView
|
||||
from intervention.views.log import InterventionLogView
|
||||
from intervention.views.record import InterventionRecordView
|
||||
from intervention.views.report import report_view
|
||||
@@ -29,7 +29,7 @@ urlpatterns = [
|
||||
path("", IndexInterventionView.as_view(), name="index"),
|
||||
path('new/', new_view, name='new'),
|
||||
path('new/id', new_id_view, name='new-id'),
|
||||
path('<id>', detail_view, name='detail'),
|
||||
path('<id>', DetailInterventionView.as_view(), name='detail'),
|
||||
path('<id>/log', InterventionLogView.as_view(), name='log'),
|
||||
path('<id>/edit', edit_view, name='edit'),
|
||||
path('<id>/remove', remove_view, name='remove'),
|
||||
|
||||
@@ -25,6 +25,7 @@ from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
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, \
|
||||
GEOMETRIES_IGNORED_TEMPLATE
|
||||
from konova.views.detail import AbstractDetailView
|
||||
from konova.views.index import AbstractIndexView
|
||||
|
||||
|
||||
@@ -134,79 +135,67 @@ def new_id_view(request: HttpRequest):
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@any_group_check
|
||||
@uuid_required
|
||||
def detail_view(request: HttpRequest, id: str):
|
||||
""" Renders a detail view for viewing an intervention's data
|
||||
class DetailInterventionView(AbstractDetailView):
|
||||
_TEMPLATE = "intervention/detail/view.html"
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The intervention's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
template = "intervention/detail/view.html"
|
||||
|
||||
# Fetch data, filter out deleted related data
|
||||
intervention = get_object_or_404(
|
||||
Intervention.objects.select_related(
|
||||
"geometry",
|
||||
"legal",
|
||||
"responsible",
|
||||
).prefetch_related(
|
||||
"legal__revocations",
|
||||
),
|
||||
id=id,
|
||||
deleted=None
|
||||
)
|
||||
compensations = intervention.compensations.filter(
|
||||
deleted=None,
|
||||
)
|
||||
_user = request.user
|
||||
is_data_shared = intervention.is_shared_with(user=_user)
|
||||
|
||||
geom_form = SimpleGeomForm(
|
||||
instance=intervention,
|
||||
)
|
||||
last_checked = intervention.get_last_checked_action()
|
||||
last_checked_tooltip = ""
|
||||
if last_checked:
|
||||
last_checked_tooltip = DATA_CHECKED_PREVIOUSLY_TEMPLATE.format(
|
||||
last_checked.get_timestamp_str_formatted(),
|
||||
last_checked.user
|
||||
def get(self, request, id: str, *args, **kwargs) -> HttpResponse:
|
||||
# Fetch data, filter out deleted related data
|
||||
intervention = get_object_or_404(
|
||||
Intervention.objects.select_related(
|
||||
"geometry",
|
||||
"legal",
|
||||
"responsible",
|
||||
).prefetch_related(
|
||||
"legal__revocations",
|
||||
),
|
||||
id=id,
|
||||
deleted=None
|
||||
)
|
||||
|
||||
has_payment_without_document = intervention.payments.exists() and not intervention.get_documents()[1].exists()
|
||||
|
||||
requesting_user_is_only_shared_user = intervention.is_only_shared_with(_user)
|
||||
if requesting_user_is_only_shared_user:
|
||||
messages.info(
|
||||
request,
|
||||
DO_NOT_FORGET_TO_SHARE
|
||||
compensations = intervention.compensations.filter(
|
||||
deleted=None,
|
||||
)
|
||||
_user = request.user
|
||||
is_data_shared = intervention.is_shared_with(user=_user)
|
||||
|
||||
context = {
|
||||
"obj": intervention,
|
||||
"last_checked": last_checked,
|
||||
"last_checked_tooltip": last_checked_tooltip,
|
||||
"compensations": compensations,
|
||||
"is_entry_shared": is_data_shared,
|
||||
"geom_form": geom_form,
|
||||
"is_default_member": _user.in_group(DEFAULT_GROUP),
|
||||
"is_zb_member": _user.in_group(ZB_GROUP),
|
||||
"is_ets_member": _user.in_group(ETS_GROUP),
|
||||
"LANIS_LINK": intervention.get_LANIS_link(),
|
||||
"has_payment_without_document": has_payment_without_document,
|
||||
TAB_TITLE_IDENTIFIER: f"{intervention.identifier} - {intervention.title}",
|
||||
}
|
||||
geom_form = SimpleGeomForm(
|
||||
instance=intervention,
|
||||
)
|
||||
last_checked = intervention.get_last_checked_action()
|
||||
last_checked_tooltip = ""
|
||||
if last_checked:
|
||||
last_checked_tooltip = DATA_CHECKED_PREVIOUSLY_TEMPLATE.format(
|
||||
last_checked.get_timestamp_str_formatted(),
|
||||
last_checked.user
|
||||
)
|
||||
|
||||
request = intervention.set_status_messages(request)
|
||||
has_payment_without_document = intervention.payments.exists() and not intervention.get_documents()[1].exists()
|
||||
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
requesting_user_is_only_shared_user = intervention.is_only_shared_with(_user)
|
||||
if requesting_user_is_only_shared_user:
|
||||
messages.info(
|
||||
request,
|
||||
DO_NOT_FORGET_TO_SHARE
|
||||
)
|
||||
|
||||
context = {
|
||||
"obj": intervention,
|
||||
"last_checked": last_checked,
|
||||
"last_checked_tooltip": last_checked_tooltip,
|
||||
"compensations": compensations,
|
||||
"is_entry_shared": is_data_shared,
|
||||
"geom_form": geom_form,
|
||||
"is_default_member": _user.in_group(DEFAULT_GROUP),
|
||||
"is_zb_member": _user.in_group(ZB_GROUP),
|
||||
"is_ets_member": _user.in_group(ETS_GROUP),
|
||||
"LANIS_LINK": intervention.get_LANIS_link(),
|
||||
"has_payment_without_document": has_payment_without_document,
|
||||
TAB_TITLE_IDENTIFIER: f"{intervention.identifier} - {intervention.title}",
|
||||
}
|
||||
|
||||
request = intervention.set_status_messages(request)
|
||||
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, self._TEMPLATE, context)
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
|
||||
Reference in New Issue
Block a user