mpeltriaux
85759a636a
* optimizes the db fetching for all index views and detail views * introduces usage of managers.py in all necessary apps for wrapping basic fetch settings * moves comment.html to comment_card.html under /konova/templates/konova/ * adds/updates translations * fixes document typos * drops comment rendering in public reports * opens public reports in new tabs if button is clicked from the detail view
133 lines
3.7 KiB
Python
133 lines
3.7 KiB
Python
"""
|
|
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.timezone import localtime
|
|
from django.utils.translation import gettext_lazy as _
|
|
from django.urls import reverse
|
|
|
|
import django_tables2 as tables
|
|
|
|
from konova.sub_settings.django_settings import DEFAULT_DATE_TIME_FORMAT
|
|
from konova.utils.tables import BaseTable
|
|
from ema.filters import EmaTableFilter
|
|
from ema.models import Ema
|
|
|
|
|
|
class EmaTable(BaseTable):
|
|
"""
|
|
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",
|
|
)
|
|
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,
|
|
accessor="modified__timestamp",
|
|
)
|
|
|
|
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,
|
|
)
|
|
super().__init__(request, self.filter, *args, **kwargs)
|
|
|
|
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")),
|
|
href=reverse("ema:detail", args=(record.id,)),
|
|
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:
|
|
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=recorded,
|
|
)
|
|
return format_html(html)
|
|
|
|
def render_e(self, value, record: Ema):
|
|
""" Renders the editable column for a EMA
|
|
|
|
Args:
|
|
value (str): The identifier value
|
|
record (Ema): The EMA record
|
|
|
|
Returns:
|
|
|
|
"""
|
|
html = ""
|
|
has_access = value.filter(
|
|
id=self.user.id
|
|
).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)
|