2021-08-19 13:02:31 +02:00
|
|
|
"""
|
|
|
|
Author: Michel Peltriaux
|
|
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
|
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
|
|
|
Created on: 19.08.21
|
|
|
|
|
|
|
|
"""
|
|
|
|
from django.http import HttpRequest
|
|
|
|
from django.utils.html import format_html
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from django.urls import reverse
|
|
|
|
|
|
|
|
import django_tables2 as tables
|
|
|
|
|
2022-10-12 10:01:23 +02:00
|
|
|
from konova.utils.tables import BaseTable, TableRenderMixin, TableOrderMixin
|
2021-08-19 13:02:31 +02:00
|
|
|
from ema.filters import EmaTableFilter
|
|
|
|
from ema.models import Ema
|
|
|
|
|
|
|
|
|
2022-10-12 10:01:23 +02:00
|
|
|
class EmaTable(BaseTable, TableRenderMixin, TableOrderMixin):
|
2021-08-19 13:02:31 +02:00
|
|
|
"""
|
|
|
|
Since EMA and compensation are basically the same, we can reuse CompensationTableFilter and extend the EMA filter
|
|
|
|
in the future by inheriting.
|
|
|
|
"""
|
|
|
|
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"),
|
2022-10-12 10:01:23 +02:00
|
|
|
orderable=False,
|
2022-02-08 15:25:44 +01:00
|
|
|
accessor="geometry",
|
|
|
|
)
|
2021-08-19 13:02:31 +02:00
|
|
|
r = tables.Column(
|
|
|
|
verbose_name=_("Recorded"),
|
|
|
|
orderable=True,
|
|
|
|
empty_values=[],
|
|
|
|
accessor="recorded",
|
|
|
|
)
|
|
|
|
e = tables.Column(
|
|
|
|
verbose_name=_("Editable"),
|
|
|
|
orderable=True,
|
|
|
|
empty_values=[],
|
|
|
|
accessor="users",
|
|
|
|
)
|
|
|
|
lm = tables.Column(
|
|
|
|
verbose_name=_("Last edit"),
|
|
|
|
orderable=True,
|
2021-10-14 14:12:33 +02:00
|
|
|
accessor="modified__timestamp",
|
2021-08-19 13:02:31 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
template_name = "django_tables2/bootstrap4.html"
|
|
|
|
|
|
|
|
def __init__(self, request: HttpRequest, *args, **kwargs):
|
|
|
|
self.title = _("Payment funded compensations")
|
|
|
|
self.subtitle = _("EMA explanation")
|
|
|
|
self.add_new_url = reverse("ema:new")
|
|
|
|
qs = kwargs.get("queryset", None)
|
|
|
|
self.filter = EmaTableFilter(
|
|
|
|
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-19 13:02:31 +02:00
|
|
|
|
|
|
|
def render_id(self, value, record: Ema):
|
|
|
|
""" Renders the id column for a EMA
|
|
|
|
|
|
|
|
Args:
|
|
|
|
value (str): The identifier value
|
|
|
|
record (EMA): The EMA record
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
html = ""
|
|
|
|
html += self.render_link(
|
|
|
|
tooltip=_("Open {}").format(_("EMA")),
|
2021-10-13 09:26:46 +02:00
|
|
|
href=reverse("ema:detail", args=(record.id,)),
|
2021-08-19 13:02:31 +02:00
|
|
|
txt=value,
|
|
|
|
new_tab=False,
|
|
|
|
)
|
|
|
|
return format_html(html)
|
|
|
|
|
|
|
|
def render_r(self, value, record: Ema):
|
|
|
|
""" Renders the registered column for a EMA
|
|
|
|
|
|
|
|
Args:
|
|
|
|
value (str): The identifier value
|
|
|
|
record (Ema): The EMA record
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
html = ""
|
|
|
|
recorded = value is not None
|
|
|
|
tooltip = _("Not recorded yet")
|
|
|
|
if recorded:
|
2022-05-30 10:26:34 +02:00
|
|
|
on = value.get_timestamp_str_formatted()
|
2021-08-19 13:02:31 +02:00
|
|
|
tooltip = _("Recorded on {} by {}").format(on, record.recorded.user)
|
|
|
|
html += self.render_bookmark(
|
|
|
|
tooltip=tooltip,
|
|
|
|
icn_filled=recorded,
|
|
|
|
)
|
|
|
|
return format_html(html)
|