konova/intervention/tables.py
mipel 881edaeba6 Compensation detail view
* adds compensation detail view (WIP)
* adds includes dir for related objects, similar to interventions
* adds functionality for
   * adding/removing before_states
   * adding/removing after_states
   * adding/removing deadlines
   * adding/removing documents
* refactors usage of BaseModalForm
   * holds now process_request() in base class for generic usage anywhere
* adds __str__() method for some models
* compensation__action is blank=True now
* renamed tooltips
* adds new routes for state/deadline/document handling inside of compensation/urls.py
* adds precalculation of before/after_states for detail view, so users will see directly if there are missing states
* removes unnecessary link for intervention detail payment
* adds missing tooltips for check and record icon on detail views
* refactors DeadlineTypeEnum into DeadlineType in konova/models.py, just as the django 3.x documentation suggests for model enumerations
* UuidModel id field is not editable anymore in the admin interface
* adds/updates translations
2021-08-03 13:13:01 +02:00

187 lines
5.4 KiB
Python

"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 01.12.20
"""
from django.http import HttpRequest
from django.urls import reverse
from django.utils.html import format_html
from django.utils.timezone import localtime
from django.utils.translation import gettext_lazy as _
from intervention.filters import InterventionTableFilter
from intervention.models import Intervention
from konova.sub_settings.django_settings import DEFAULT_DATE_TIME_FORMAT
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",
)
c = tables.Column(
verbose_name=_("Checked"),
orderable=True,
empty_values=[],
accessor="checked",
)
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="created__timestamp",
)
"""
# ToDo: Decide to keep actions column or to dismiss them
ac = tables.Column(
verbose_name=_("Actions"),
orderable=False,
empty_values=[],
attrs={"td": {"class": "action-col"}}
)
"""
class Meta(BaseTable.Meta):
template_name = "django_tables2/bootstrap4.html"
def __init__(self, request: HttpRequest, *args, **kwargs):
self.title = _("Interventions")
self.add_new_url = reverse("intervention:new")
qs = kwargs.get("queryset", None)
self.filter = InterventionTableFilter(
user=request.user,
data=request.GET,
queryset=qs,
)
super().__init__(request, self.filter, *args, **kwargs)
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")),
href=reverse("intervention:open", args=(record.id,)),
txt=value,
new_tab=False,
)
return format_html(html)
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:
value = value.timestamp
value = localtime(value)
checked_on = value.strftime(DEFAULT_DATE_TIME_FORMAT)
tooltip = _("Checked on {} by {}").format(checked_on, record.checked.user)
html += self.render_checked_star(
tooltip=tooltip,
icn_filled=checked,
)
return format_html(html)
def render_r(self, value, record: Intervention):
""" Renders the registered column for an intervention
Args:
value (str): The identifier value
record (Intervention): The intervention record
Returns:
"""
html = ""
checked = value is not None
tooltip = _("Not recorded yet")
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,
)
return format_html(html)
def render_e(self, value, record: Intervention):
""" Renders the registered column for an intervention
Args:
value (str): The identifier value
record (Intervention): The intervention record
Returns:
"""
html = ""
has_access = value.filter(
username=self.user.username
).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)
def render_ac(self, value, record):
"""
Renders possible actions for this record, such as delete.
"""
intervention = _("Intervention")
html = ""
html += self.render_open_btn(
_("Open {}").format(intervention),
reverse("intervention:open", args=(record.id,))
)
html += self.render_edit_btn(
_("Edit {}").format(intervention),
reverse("intervention:edit", args=(record.id,)),
)
html += self.render_delete_btn(
_("Delete {}").format(intervention),
reverse("intervention:remove", args=(record.id,)),
)
return format_html(html)