Intervention tables and model adjustments
* adds user access relation to certain models * adds pagination to tables * adds checked_on/_by attributes to intervention model * adds custom column rendering for checked and registered columns * adds first simple index filtering of default interventions for user * adds translations
This commit is contained in:
@@ -7,9 +7,11 @@ Created on: 01.12.20
|
||||
"""
|
||||
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.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
|
||||
|
||||
@@ -28,11 +30,13 @@ class InterventionTable(BaseTable):
|
||||
c = tables.Column(
|
||||
verbose_name=_("Checked"),
|
||||
orderable=True,
|
||||
accessor="recorded_on",
|
||||
empty_values=[],
|
||||
accessor="checked_on",
|
||||
)
|
||||
r = tables.Column(
|
||||
verbose_name=_("Registered"),
|
||||
orderable=True,
|
||||
empty_values=[],
|
||||
accessor="recorded_on",
|
||||
)
|
||||
lm = tables.Column(
|
||||
@@ -52,7 +56,7 @@ class InterventionTable(BaseTable):
|
||||
"""
|
||||
|
||||
class Meta(BaseTable.Meta):
|
||||
pass
|
||||
template_name = "django_tables2/bootstrap4.html"
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
@@ -78,6 +82,52 @@ class InterventionTable(BaseTable):
|
||||
)
|
||||
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 = localtime(value)
|
||||
checked_on = value.strftime(DEFAULT_DATE_TIME_FORMAT)
|
||||
tooltip = _("Checked on {} by {}").format(checked_on, record.checked_by)
|
||||
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 registered yet")
|
||||
if checked:
|
||||
value = localtime(value)
|
||||
checked_on = value.strftime(DEFAULT_DATE_TIME_FORMAT)
|
||||
tooltip = _("Registered on {} by {}").format(checked_on, record.checked_by)
|
||||
html += self.render_bookmark(
|
||||
tooltip=tooltip,
|
||||
icn_filled=checked,
|
||||
)
|
||||
return format_html(html)
|
||||
|
||||
def render_ac(self, value, record):
|
||||
"""
|
||||
Renders possible actions for this record, such as delete.
|
||||
|
||||
Reference in New Issue
Block a user