2021-07-01 13:36:07 +02:00
|
|
|
"""
|
|
|
|
Author: Michel Peltriaux
|
|
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
|
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
|
|
|
Created on: 01.12.20
|
|
|
|
|
|
|
|
"""
|
2022-01-12 12:56:22 +01:00
|
|
|
from user.models import User
|
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
|
2021-07-29 10:51:14 +02:00
|
|
|
from django.utils.timezone import localtime
|
2021-07-01 13:36:07 +02:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
2021-08-09 14:16:54 +02:00
|
|
|
from compensation.filters import CompensationTableFilter, EcoAccountTableFilter
|
|
|
|
from compensation.models import Compensation, EcoAccount
|
2021-07-29 10:51:14 +02:00
|
|
|
from konova.sub_settings.django_settings import DEFAULT_DATE_TIME_FORMAT
|
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
|
|
|
|
tooltip = _("Not checked yet")
|
|
|
|
if checked:
|
2021-07-29 15:49:19 +02:00
|
|
|
value = value.timestamp
|
2021-07-29 10:51:14 +02:00
|
|
|
value = localtime(value)
|
|
|
|
checked_on = value.strftime(DEFAULT_DATE_TIME_FORMAT)
|
2021-07-29 15:49:19 +02:00
|
|
|
tooltip = _("Checked on {} by {}").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
|
|
|
)
|
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:
|
2021-07-29 15:49:19 +02:00
|
|
|
value = value.timestamp
|
2021-07-29 10:51:14 +02:00
|
|
|
value = localtime(value)
|
|
|
|
on = value.strftime(DEFAULT_DATE_TIME_FORMAT)
|
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:
|
|
|
|
|
|
|
|
"""
|
2021-09-27 13:57:56 +02:00
|
|
|
if value is None:
|
|
|
|
value = User.objects.none()
|
2021-07-29 10:51:14 +02:00
|
|
|
has_access = value.filter(
|
2021-10-14 14:12:33 +02:00
|
|
|
id=self.user.id
|
2021-07-29 10:51:14 +02:00
|
|
|
).exists()
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2022-01-12 10:11:47 +01:00
|
|
|
class EcoAccountTable(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-08-09 14:16:54 +02:00
|
|
|
av = tables.Column(
|
|
|
|
verbose_name=_("Available"),
|
2021-07-01 13:36:07 +02:00
|
|
|
orderable=True,
|
2021-08-09 14:16:54 +02:00
|
|
|
empty_values=[],
|
2022-02-08 15:25:44 +01:00
|
|
|
attrs={
|
|
|
|
"th": {
|
|
|
|
"class": "w-20",
|
|
|
|
}
|
|
|
|
}
|
2021-08-09 14:16:54 +02:00
|
|
|
)
|
|
|
|
r = tables.Column(
|
|
|
|
verbose_name=_("Recorded"),
|
|
|
|
orderable=True,
|
|
|
|
empty_values=[],
|
|
|
|
accessor="recorded",
|
2021-07-01 13:36:07 +02:00
|
|
|
)
|
2021-08-09 14:16:54 +02:00
|
|
|
e = tables.Column(
|
|
|
|
verbose_name=_("Editable"),
|
|
|
|
orderable=True,
|
2021-07-01 13:36:07 +02:00
|
|
|
empty_values=[],
|
2021-08-09 14:16:54 +02:00
|
|
|
accessor="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-08-09 14:16:54 +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 = _("Eco Accounts")
|
2022-02-02 11:26:02 +01:00
|
|
|
self.add_new_url = reverse("compensation:acc:new")
|
2021-08-09 14:16:54 +02:00
|
|
|
qs = kwargs.get("queryset", None)
|
|
|
|
self.filter = EcoAccountTableFilter(
|
|
|
|
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-08-09 14:16:54 +02:00
|
|
|
|
|
|
|
def render_id(self, value, record: EcoAccount):
|
|
|
|
""" Renders the id column for an eco account
|
|
|
|
|
|
|
|
Args:
|
|
|
|
value (str): The identifier value
|
|
|
|
record (EcoAccount): The eco account record
|
|
|
|
|
|
|
|
Returns:
|
2021-07-01 13:36:07 +02:00
|
|
|
|
|
|
|
"""
|
|
|
|
html = ""
|
2021-08-09 14:16:54 +02:00
|
|
|
html += self.render_link(
|
|
|
|
tooltip=_("Open {}").format(_("Eco-account")),
|
2022-02-02 11:26:02 +01:00
|
|
|
href=reverse("compensation:acc:detail", args=(record.id,)),
|
2021-08-09 14:16:54 +02:00
|
|
|
txt=value,
|
|
|
|
new_tab=False,
|
2021-07-01 13:36:07 +02:00
|
|
|
)
|
2021-08-09 14:16:54 +02:00
|
|
|
return format_html(html)
|
|
|
|
|
|
|
|
def render_av(self, value, record: EcoAccount):
|
|
|
|
""" Renders the available column for an eco account
|
|
|
|
|
|
|
|
Args:
|
|
|
|
value (str): The identifier value
|
|
|
|
record (EcoAccount): The eco account record
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
2021-10-05 16:35:24 +02:00
|
|
|
value_total, value_relative = record.get_available_rest()
|
2021-10-06 16:15:40 +02:00
|
|
|
html = render_to_string("konova/widgets/progressbar.html", {"value": value_relative})
|
2021-08-09 14:16:54 +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-08-09 14:16:54 +02:00
|
|
|
def render_r(self, value, record: EcoAccount):
|
2021-10-14 14:12:33 +02:00
|
|
|
""" Renders the recorded column for an eco account
|
2021-08-09 14:16:54 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
value (str): The identifier value
|
|
|
|
record (EcoAccount): The eco account record
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
html = ""
|
|
|
|
checked = value is not None
|
2021-08-30 11:29:15 +02:00
|
|
|
tooltip = _("Not recorded yet. Can not be used for deductions, yet.")
|
2021-08-09 14:16:54 +02:00
|
|
|
if checked:
|
|
|
|
value = value.timestamp
|
|
|
|
value = localtime(value)
|
|
|
|
on = value.strftime(DEFAULT_DATE_TIME_FORMAT)
|
|
|
|
tooltip = _("Recorded on {} by {}").format(on, record.recorded.user)
|
|
|
|
html += self.render_bookmark(
|
|
|
|
tooltip=tooltip,
|
|
|
|
icn_filled=checked,
|
2021-07-01 13:36:07 +02:00
|
|
|
)
|
2021-08-09 14:16:54 +02:00
|
|
|
return format_html(html)
|
|
|
|
|
|
|
|
def render_e(self, value, record: EcoAccount):
|
2021-10-14 14:12:33 +02:00
|
|
|
""" Renders the editable column for an eco account
|
2021-08-09 14:16:54 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
value (str): The identifier value
|
|
|
|
record (EcoAccount): The eco account record
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
html = ""
|
2021-10-14 14:12:33 +02:00
|
|
|
# Do not use value in here, since value does use unprefetched 'users' manager, where record has already
|
|
|
|
# prefetched users data
|
|
|
|
has_access = self.user in record.users.all()
|
2021-08-09 14:16:54 +02:00
|
|
|
html += self.render_icn(
|
|
|
|
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)
|