From f7b82147c74425454b01134b99e1154ee8840e2f Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 11 Aug 2022 07:22:22 +0100 Subject: [PATCH] Filter shown fields and add some icons to boolean values --- .../ui/drilldown/table_results_partial.html | 26 ++++++++++++++----- core/views/ui/drilldown.py | 23 ++++++++++++++-- core/views/ui/tables.py | 2 ++ 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/core/templates/ui/drilldown/table_results_partial.html b/core/templates/ui/drilldown/table_results_partial.html index 2da0314..9c13551 100644 --- a/core/templates/ui/drilldown/table_results_partial.html +++ b/core/templates/ui/drilldown/table_results_partial.html @@ -13,7 +13,7 @@ {% 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 %} {% if column.orderable %} @@ -68,12 +68,12 @@ has-background-info-light {% endif %}"> {% 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 %} {% if column.name == 'src' %} + onclick="populateSearch('src', '{{ cell|escapejs }}')"> {% if row.cells.src == 'irc' %} @@ -93,7 +93,7 @@ {% elif column.name == 'type' %} + onclick="populateSearch('type', '{{ cell|escapejs }}')"> {% if row.cells.type == 'msg' %} @@ -136,7 +136,7 @@ {% elif column.name == 'host' %} + onclick="populateSearch('host', '{{ cell|escapejs }}')"> {{ cell }} @@ -187,7 +187,7 @@
+ onclick="populateSearch('channel', '{{ cell|escapejs }}')"> {{ cell }} {% if row.cells.num_users is not None %} @@ -202,10 +202,22 @@ {% elif column.name == 'net' %} + onclick="populateSearch('net', '{{ cell|escapejs }}')"> {{ cell }} + {% elif cell == True or cell == False %} + + {% if cell == True %} + + + + {% else %} + + + + {% endif %} + {% else %} {{ cell }} diff --git a/core/views/ui/drilldown.py b/core/views/ui/drilldown.py index 829c28c..723cc64 100644 --- a/core/views/ui/drilldown.py +++ b/core/views/ui/drilldown.py @@ -171,6 +171,15 @@ class DrilldownTableView(SingleTableView): def get(self, request, *args, **kwargs): 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() if not allow_empty: @@ -190,8 +199,18 @@ class DrilldownTableView(SingleTableView): for k, v in self.context.items(): if k not in context: 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 not request.htmx: self.template_name = "ui/drilldown/drilldown.html" diff --git a/core/views/ui/tables.py b/core/views/ui/tables.py index 2d2f0a7..4b61661 100644 --- a/core/views/ui/tables.py +++ b/core/views/ui/tables.py @@ -5,6 +5,7 @@ from django_tables2.columns.base import BoundColumn # Make the table column headings lowercase orig_Column_header = BoundColumn.header + @property def format_header(self): header = orig_Column_header.__get__(self) @@ -19,6 +20,7 @@ def format_header(self): return header + BoundColumn.header = format_header