Filter shown fields and add some icons to boolean values

This commit is contained in:
Mark Veidemanis 2022-08-11 07:22:22 +01:00
parent 86ec95ab6c
commit f7b82147c7
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
3 changed files with 42 additions and 9 deletions

View File

@ -13,7 +13,7 @@
<tr> <tr>
{% for column in table.columns %} {% for column in table.columns %}
{% if column.name not in hide %} {% if column.name in show and not column.name in hide %}
{% block table.thead.th %} {% block table.thead.th %}
<th {% render_attrs column.attrs.th class="" %}> <th {% render_attrs column.attrs.th class="" %}>
{% if column.orderable %} {% if column.orderable %}
@ -68,7 +68,7 @@
has-background-info-light has-background-info-light
{% endif %}"> {% endif %}">
{% for column, cell in row.items %} {% for column, cell in row.items %}
{% if column.name not in hide %} {% if column.name in show and not column.name in hide %}
{% block table.tbody.td %} {% block table.tbody.td %}
{% if column.name == 'src' %} {% if column.name == 'src' %}
<td> <td>
@ -206,6 +206,18 @@
{{ cell }} {{ cell }}
</a> </a>
</td> </td>
{% elif cell == True or cell == False %}
<td>
{% if cell == True %}
<span class="icon has-text-success">
<i class="fa-solid fa-check"></i>
</span>
{% else %}
<span class="icon">
<i class="fa-solid fa-xmark"></i>
</span>
{% endif %}
</td>
{% else %} {% else %}
<td> <td>
{{ cell }} {{ cell }}

View File

@ -171,6 +171,15 @@ class DrilldownTableView(SingleTableView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.object_list = self.get_queryset(request) self.object_list = self.get_queryset(request)
show = []
if len(self.object_list) > 0:
first = self.object_list[0]
fields = first.keys()
for field in fields:
values_present = all([x[field] is not None for x in self.object_list])
if values_present:
if field not in show:
show.append(field)
allow_empty = self.get_allow_empty() allow_empty = self.get_allow_empty()
if not allow_empty: if not allow_empty:
@ -190,8 +199,18 @@ class DrilldownTableView(SingleTableView):
for k, v in self.context.items(): for k, v in self.context.items():
if k not in context: if k not in context:
context[k] = v context[k] = v
context["hide"] = ["date", "time", "id", "num", "channel_nsfw", "num_users", "num_chans", "exemption", "version_sentiment"] context["hide"] = [
"date",
"time",
"id",
"num",
"channel_nsfw",
"num_users",
"num_chans",
"exemption",
"version_sentiment",
]
context["show"] = show
if request.method == "GET": if request.method == "GET":
if not request.htmx: if not request.htmx:
self.template_name = "ui/drilldown/drilldown.html" self.template_name = "ui/drilldown/drilldown.html"

View File

@ -5,6 +5,7 @@ from django_tables2.columns.base import BoundColumn
# Make the table column headings lowercase # Make the table column headings lowercase
orig_Column_header = BoundColumn.header orig_Column_header = BoundColumn.header
@property @property
def format_header(self): def format_header(self):
header = orig_Column_header.__get__(self) header = orig_Column_header.__get__(self)
@ -19,6 +20,7 @@ def format_header(self):
return header return header
BoundColumn.header = format_header BoundColumn.header = format_header