2021-07-01 13:36:07 +02:00
|
|
|
"""
|
|
|
|
Author: Michel Peltriaux
|
|
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
2022-08-18 10:24:11 +02:00
|
|
|
Contact: ksp-servicestelle@sgdnord.rlp.de
|
|
|
|
Created on: 18.08.22
|
2021-07-01 13:36:07 +02:00
|
|
|
|
|
|
|
"""
|
2021-07-29 10:51:14 +02:00
|
|
|
from django.http import HttpRequest
|
2021-08-09 14:16:54 +02:00
|
|
|
from django.template.loader import render_to_string
|
2021-07-01 13:36:07 +02:00
|
|
|
from django.urls import reverse
|
|
|
|
from django.utils.html import format_html
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
2022-08-18 13:19:04 +02:00
|
|
|
from compensation.filters.compensation import CompensationTableFilter
|
2022-08-18 10:24:11 +02:00
|
|
|
from compensation.models import Compensation
|
|
|
|
from konova.utils.message_templates import DATA_IS_UNCHECKED, DATA_CHECKED_ON_TEMPLATE, DATA_CHECKED_PREVIOUSLY_TEMPLATE
|
2022-01-12 10:11:47 +01:00
|
|
|
from konova.utils.tables import BaseTable, TableRenderMixin
|
2021-07-01 13:36:07 +02:00
|
|
|
import django_tables2 as tables
|
|
|
|
|
|
|
|
|
2022-01-12 10:11:47 +01:00
|
|
|
class CompensationTable(BaseTable, TableRenderMixin):
|
2021-07-01 13:36:07 +02:00
|
|
|
id = tables.Column(
|
|
|
|
verbose_name=_("Identifier"),
|
|
|
|
orderable=True,
|
|
|
|
accessor="identifier",
|
|
|
|
)
|
|
|
|
t = tables.Column(
|
|
|
|
verbose_name=_("Title"),
|
|
|
|
orderable=True,
|
|
|
|
accessor="title",
|
|
|
|
)
|
2022-02-08 15:25:44 +01:00
|
|
|
d = tables.Column(
|
|
|
|
verbose_name=_("Parcel gmrkng"),
|
|
|
|
orderable=True,
|
|
|
|
accessor="geometry",
|
|
|
|
)
|
2021-07-29 10:51:14 +02:00
|
|
|
c = tables.Column(
|
|
|
|
verbose_name=_("Checked"),
|
2021-07-01 13:36:07 +02:00
|
|
|
orderable=True,
|
2021-07-29 10:51:14 +02:00
|
|
|
empty_values=[],
|
2021-07-29 15:49:19 +02:00
|
|
|
accessor="intervention__checked",
|
2021-07-01 13:36:07 +02:00
|
|
|
)
|
2021-07-29 10:51:14 +02:00
|
|
|
r = tables.Column(
|
|
|
|
verbose_name=_("Recorded"),
|
|
|
|
orderable=True,
|
|
|
|
empty_values=[],
|
2021-07-29 15:49:19 +02:00
|
|
|
accessor="intervention__recorded",
|
2021-07-29 10:51:14 +02:00
|
|
|
)
|
|
|
|
e = tables.Column(
|
|
|
|
verbose_name=_("Editable"),
|
|
|
|
orderable=True,
|
2021-07-01 13:36:07 +02:00
|
|
|
empty_values=[],
|
2021-07-29 10:51:14 +02:00
|
|
|
accessor="intervention__users",
|
|
|
|
)
|
|
|
|
lm = tables.Column(
|
|
|
|
verbose_name=_("Last edit"),
|
|
|
|
orderable=True,
|
2021-08-19 13:02:31 +02:00
|
|
|
accessor="modified__timestamp",
|
2021-07-01 13:36:07 +02:00
|
|
|
)
|
|
|
|
|
2021-07-21 14:17:18 +02:00
|
|
|
class Meta(BaseTable.Meta):
|
2021-07-29 10:51:14 +02:00
|
|
|
template_name = "django_tables2/bootstrap4.html"
|
2021-07-21 14:17:18 +02:00
|
|
|
|
2021-08-09 14:16:54 +02:00
|
|
|
def __init__(self, request: HttpRequest, *args, **kwargs):
|
2021-07-01 13:36:07 +02:00
|
|
|
self.title = _("Compensations")
|
|
|
|
self.add_new_url = reverse("compensation:new")
|
2021-07-29 10:51:14 +02:00
|
|
|
qs = kwargs.get("queryset", None)
|
|
|
|
self.filter = CompensationTableFilter(
|
|
|
|
user=request.user,
|
|
|
|
data=request.GET,
|
|
|
|
queryset=qs,
|
|
|
|
)
|
2022-01-11 14:28:34 +01:00
|
|
|
kwargs["queryset"] = self.filter.qs
|
|
|
|
super().__init__(request, *args, **kwargs)
|
2021-07-29 10:51:14 +02:00
|
|
|
|
|
|
|
def render_id(self, value, record: Compensation):
|
|
|
|
""" Renders the id column for a compensation
|
|
|
|
|
|
|
|
Args:
|
|
|
|
value (str): The identifier value
|
|
|
|
record (Compensation): The compensation record
|
|
|
|
|
|
|
|
Returns:
|
2021-07-01 13:36:07 +02:00
|
|
|
|
|
|
|
"""
|
2022-02-08 15:25:44 +01:00
|
|
|
context = {
|
|
|
|
"tooltip": _("Open {}").format(_("Intervention")),
|
|
|
|
"content": value,
|
|
|
|
"url": reverse("compensation:detail", args=(record.id,)),
|
|
|
|
"has_revocations": record.intervention.legal.revocations.exists()
|
|
|
|
}
|
|
|
|
html = render_to_string(
|
|
|
|
"table/revocation_warning_col.html",
|
|
|
|
context
|
2021-07-29 10:51:14 +02:00
|
|
|
)
|
2022-02-08 15:25:44 +01:00
|
|
|
return html
|
2021-07-29 10:51:14 +02:00
|
|
|
|
|
|
|
def render_c(self, value, record: Compensation):
|
|
|
|
""" Renders the checked column for a compensation
|
|
|
|
|
2021-07-29 15:49:19 +02:00
|
|
|
checked is set by the main object Intervention
|
2021-07-29 10:51:14 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
value (str): The identifier value
|
|
|
|
record (Compensation): The compensation record
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
2021-07-01 13:36:07 +02:00
|
|
|
"""
|
|
|
|
html = ""
|
2021-07-29 10:51:14 +02:00
|
|
|
checked = value is not None
|
2022-05-30 10:26:34 +02:00
|
|
|
tooltip = DATA_IS_UNCHECKED
|
|
|
|
previously_checked = record.intervention.get_last_checked_action()
|
2021-07-29 10:51:14 +02:00
|
|
|
if checked:
|
2022-05-30 10:26:34 +02:00
|
|
|
checked_on = value.get_timestamp_str_formatted()
|
|
|
|
tooltip = DATA_CHECKED_ON_TEMPLATE.format(checked_on, record.intervention.checked.user)
|
2021-07-29 10:51:14 +02:00
|
|
|
html += self.render_checked_star(
|
|
|
|
tooltip=tooltip,
|
|
|
|
icn_filled=checked,
|
2021-07-01 13:36:07 +02:00
|
|
|
)
|
2022-05-30 10:26:34 +02:00
|
|
|
if previously_checked and not checked:
|
|
|
|
checked_on = previously_checked.get_timestamp_str_formatted()
|
|
|
|
tooltip = DATA_CHECKED_PREVIOUSLY_TEMPLATE.format(checked_on, previously_checked.user)
|
|
|
|
html += self.render_previously_checked_star(
|
|
|
|
tooltip=tooltip,
|
|
|
|
)
|
2021-07-29 10:51:14 +02:00
|
|
|
return format_html(html)
|
|
|
|
|
2022-02-08 15:25:44 +01:00
|
|
|
def render_d(self, value, record: Compensation):
|
|
|
|
""" Renders the parcel district column for a compensation
|
|
|
|
|
|
|
|
Args:
|
|
|
|
value (str): The geometry
|
|
|
|
record (Compensation): The compensation record
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
2022-02-09 09:30:37 +01:00
|
|
|
parcels = value.get_underlying_parcels().values_list(
|
2022-04-11 10:23:28 +02:00
|
|
|
"parcel_group__name",
|
2022-02-08 15:25:44 +01:00
|
|
|
flat=True
|
|
|
|
).distinct()
|
|
|
|
html = render_to_string(
|
|
|
|
"table/gmrkng_col.html",
|
|
|
|
{
|
|
|
|
"entries": parcels
|
|
|
|
}
|
|
|
|
)
|
|
|
|
return html
|
|
|
|
|
2021-07-29 10:51:14 +02:00
|
|
|
def render_r(self, value, record: Compensation):
|
|
|
|
""" Renders the registered column for a compensation
|
|
|
|
|
|
|
|
Args:
|
|
|
|
value (str): The identifier value
|
|
|
|
record (Compensation): The compensation record
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
html = ""
|
2021-08-19 13:02:31 +02:00
|
|
|
recorded = value is not None
|
2021-08-03 13:13:01 +02:00
|
|
|
tooltip = _("Not recorded yet")
|
2021-08-19 13:02:31 +02:00
|
|
|
if recorded:
|
2022-05-30 10:26:34 +02:00
|
|
|
on = value.get_timestamp_str_formatted()
|
2021-08-03 13:13:01 +02:00
|
|
|
tooltip = _("Recorded on {} by {}").format(on, record.intervention.recorded.user)
|
2021-07-29 10:51:14 +02:00
|
|
|
html += self.render_bookmark(
|
|
|
|
tooltip=tooltip,
|
2021-08-19 13:02:31 +02:00
|
|
|
icn_filled=recorded,
|
2021-07-01 13:36:07 +02:00
|
|
|
)
|
2021-07-29 10:51:14 +02:00
|
|
|
return format_html(html)
|
|
|
|
|
|
|
|
def render_e(self, value, record: Compensation):
|
2021-08-19 13:02:31 +02:00
|
|
|
""" Renders the editable column for a compensation
|
2021-07-29 10:51:14 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
value (str): The identifier value
|
|
|
|
record (Compensation): The compensation record
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
2022-04-13 14:18:32 +02:00
|
|
|
has_access = record.is_shared_with(self.user)
|
2021-07-29 10:51:14 +02:00
|
|
|
|
2021-10-14 14:12:33 +02:00
|
|
|
html = self.render_icn(
|
2021-07-29 10:51:14 +02:00
|
|
|
tooltip=_("Full access granted") if has_access else _("Access not granted"),
|
|
|
|
icn_class="fas fa-edit rlp-r-inv" if has_access else "far fa-edit",
|
2021-07-01 13:36:07 +02:00
|
|
|
)
|
|
|
|
return format_html(html)
|