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
|
|
|
|
|
|
|
|
"""
|
2021-07-22 10:00:59 +02:00
|
|
|
from django.http import HttpRequest
|
2021-07-01 13:36:07 +02:00
|
|
|
from django.urls import reverse
|
|
|
|
from django.utils.html import format_html
|
2021-07-21 15:40:34 +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-07-22 10:00:59 +02:00
|
|
|
from intervention.filters import InterventionTableFilter
|
2021-07-01 13:36:07 +02:00
|
|
|
from intervention.models import Intervention
|
2021-08-26 15:02:34 +02:00
|
|
|
from konova.sub_settings.django_settings import DEFAULT_DATE_TIME_FORMAT, DEFAULT_DATE_FORMAT
|
2021-07-01 13:36:07 +02:00
|
|
|
from konova.utils.tables import BaseTable
|
|
|
|
import django_tables2 as tables
|
|
|
|
|
|
|
|
|
|
|
|
class InterventionTable(BaseTable):
|
|
|
|
id = tables.Column(
|
|
|
|
verbose_name=_("Identifier"),
|
|
|
|
orderable=True,
|
|
|
|
accessor="identifier",
|
|
|
|
)
|
|
|
|
t = tables.Column(
|
|
|
|
verbose_name=_("Title"),
|
|
|
|
orderable=True,
|
|
|
|
accessor="title",
|
|
|
|
)
|
2021-07-20 14:23:16 +02:00
|
|
|
c = tables.Column(
|
|
|
|
verbose_name=_("Checked"),
|
|
|
|
orderable=True,
|
2021-07-21 15:40:34 +02:00
|
|
|
empty_values=[],
|
2021-07-29 15:49:19 +02:00
|
|
|
accessor="checked",
|
2021-07-20 14:23:16 +02:00
|
|
|
)
|
|
|
|
r = tables.Column(
|
2021-07-22 13:19:14 +02:00
|
|
|
verbose_name=_("Recorded"),
|
2021-07-20 14:23:16 +02:00
|
|
|
orderable=True,
|
2021-07-21 15:40:34 +02:00
|
|
|
empty_values=[],
|
2021-07-29 15:49:19 +02:00
|
|
|
accessor="recorded",
|
2021-07-20 14:23:16 +02:00
|
|
|
)
|
2021-08-26 15:02:34 +02:00
|
|
|
rev = tables.Column(
|
|
|
|
verbose_name=_("Revocation"),
|
|
|
|
orderable=True,
|
|
|
|
empty_values=[],
|
|
|
|
accessor="legal__revocation",
|
|
|
|
)
|
2021-07-22 10:00:59 +02:00
|
|
|
e = tables.Column(
|
|
|
|
verbose_name=_("Editable"),
|
|
|
|
orderable=True,
|
|
|
|
empty_values=[],
|
|
|
|
accessor="users",
|
|
|
|
)
|
2021-07-20 14:23:16 +02:00
|
|
|
lm = tables.Column(
|
|
|
|
verbose_name=_("Last edit"),
|
2021-07-01 13:36:07 +02:00
|
|
|
orderable=True,
|
2021-08-19 13:02:31 +02:00
|
|
|
accessor="modified__timestamp",
|
2021-07-01 13:36:07 +02:00
|
|
|
)
|
2021-07-20 14:23:16 +02:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
2021-07-21 15:40:34 +02:00
|
|
|
template_name = "django_tables2/bootstrap4.html"
|
2021-07-01 13:36:07 +02:00
|
|
|
|
2021-07-22 10:00:59 +02:00
|
|
|
def __init__(self, request: HttpRequest, *args, **kwargs):
|
2021-07-01 13:36:07 +02:00
|
|
|
self.title = _("Interventions")
|
|
|
|
self.add_new_url = reverse("intervention:new")
|
2021-07-22 10:00:59 +02:00
|
|
|
qs = kwargs.get("queryset", None)
|
|
|
|
self.filter = InterventionTableFilter(
|
|
|
|
user=request.user,
|
|
|
|
data=request.GET,
|
|
|
|
queryset=qs,
|
|
|
|
)
|
|
|
|
super().__init__(request, self.filter, *args, **kwargs)
|
2021-07-01 13:36:07 +02:00
|
|
|
|
|
|
|
def render_id(self, value, record: Intervention):
|
|
|
|
""" Renders the id column for an intervention
|
|
|
|
|
|
|
|
Args:
|
|
|
|
value (str): The identifier value
|
|
|
|
record (Intervention): The intervention record
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
html = ""
|
|
|
|
html += self.render_link(
|
|
|
|
tooltip=_("Open {}").format(_("Intervention")),
|
2021-10-13 09:26:46 +02:00
|
|
|
href=reverse("intervention:detail", args=(record.id,)),
|
2021-07-01 13:36:07 +02:00
|
|
|
txt=value,
|
|
|
|
new_tab=False,
|
|
|
|
)
|
|
|
|
return format_html(html)
|
|
|
|
|
2021-07-21 15:40:34 +02:00
|
|
|
def render_c(self, value, record: Intervention):
|
|
|
|
""" Renders the checked column for an intervention
|
|
|
|
|
|
|
|
Args:
|
|
|
|
value (str): The identifier value
|
|
|
|
record (Intervention): The intervention record
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
html = ""
|
|
|
|
checked = value is not None
|
|
|
|
tooltip = _("Not checked yet")
|
|
|
|
if checked:
|
2021-07-29 15:49:19 +02:00
|
|
|
value = value.timestamp
|
2021-07-21 15:40:34 +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.checked.user)
|
2021-07-21 15:40:34 +02:00
|
|
|
html += self.render_checked_star(
|
|
|
|
tooltip=tooltip,
|
|
|
|
icn_filled=checked,
|
|
|
|
)
|
|
|
|
return format_html(html)
|
|
|
|
|
|
|
|
def render_r(self, value, record: Intervention):
|
2021-10-14 14:12:33 +02:00
|
|
|
""" Renders the recorded column for an intervention
|
2021-07-21 15:40:34 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
value (str): The identifier value
|
|
|
|
record (Intervention): The intervention record
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
html = ""
|
|
|
|
checked = value is not None
|
2021-08-03 13:13:01 +02:00
|
|
|
tooltip = _("Not recorded yet")
|
2021-07-21 15:40:34 +02:00
|
|
|
if checked:
|
2021-07-29 15:49:19 +02:00
|
|
|
value = value.timestamp
|
2021-07-21 15:40:34 +02:00
|
|
|
value = localtime(value)
|
2021-07-29 10:51:14 +02:00
|
|
|
on = value.strftime(DEFAULT_DATE_TIME_FORMAT)
|
2021-08-03 13:13:01 +02:00
|
|
|
tooltip = _("Recorded on {} by {}").format(on, record.recorded.user)
|
2021-07-21 15:40:34 +02:00
|
|
|
html += self.render_bookmark(
|
|
|
|
tooltip=tooltip,
|
|
|
|
icn_filled=checked,
|
|
|
|
)
|
|
|
|
return format_html(html)
|
|
|
|
|
2021-07-22 10:00:59 +02:00
|
|
|
def render_e(self, value, record: Intervention):
|
2021-10-14 14:12:33 +02:00
|
|
|
""" Renders the editable column for an intervention
|
2021-07-22 10:00:59 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
value (str): The identifier value
|
|
|
|
record (Intervention): The intervention record
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
html = ""
|
|
|
|
has_access = value.filter(
|
2021-10-14 14:12:33 +02:00
|
|
|
id=self.user.id
|
2021-07-22 10:00:59 +02:00
|
|
|
).exists()
|
|
|
|
|
|
|
|
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",
|
|
|
|
)
|
|
|
|
return format_html(html)
|
2021-08-26 15:02:34 +02:00
|
|
|
|
|
|
|
def render_rev(self, value, record: Intervention):
|
|
|
|
""" Renders the revocation column for an intervention
|
|
|
|
|
|
|
|
Args:
|
|
|
|
value (str): The revocation value
|
|
|
|
record (Intervention): The intervention record
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
html = ""
|
|
|
|
exists = value is not None
|
|
|
|
tooltip = _("No revocation")
|
|
|
|
if exists:
|
|
|
|
_date = value.date
|
|
|
|
added_ts = localtime(value.created.timestamp)
|
|
|
|
added_ts = added_ts.strftime(DEFAULT_DATE_TIME_FORMAT)
|
|
|
|
on = _date.strftime(DEFAULT_DATE_FORMAT)
|
|
|
|
tooltip = _("Revocation from {}, added on {} by {}").format(on, added_ts, value.created.user)
|
|
|
|
html += self.render_stop(
|
|
|
|
tooltip=tooltip,
|
|
|
|
icn_filled=exists,
|
|
|
|
)
|
|
|
|
return format_html(html)
|
|
|
|
|