Group items in meta by field

This commit is contained in:
Mark Veidemanis 2022-07-21 13:53:02 +01:00
parent 8710c66e05
commit 70a6221b0c
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 10 additions and 55 deletions

View File

@ -1,63 +1,19 @@
<div id="meta">
<div class="content" style="max-height: 30em; overflow: auto;">
<div class="table-container">
{% for item in meta %}
<table class="table is-striped is-fullwidth is-hoverable">
{% for key,items in meta.items %}
<th><strong>{{ key }}</strong></th>
<table class="table is-fullwidth is-hoverable">
<tbody>
{% if 'ts' in item %}
{% for item in items %}
<tr>
<th>ts</th>
<td>
<p>{{ item.date }}</p>
<p>{{ item.time }}</p>
{{ item }}
</td>
</tr>
{% endif %}
{% if 'nick' in item %}
<tr>
<th>nick</th>
<td>{{ item.nick }}</td>
</tr>
{% endif %}
{% if 'ident' in item %}
<tr>
<th>ident</th>
<td>{{ item.ident }}</td>
</tr>
{% endif %}
{% if 'host' in item %}
<tr>
<th>host</th>
<td>{{ item.host }}</td>
</tr>
{% endif %}
{% if 'realname' in item %}
<tr>
<th>realname</th>
<td>{{ item.realname }}</td>
</tr>
{% endif %}
{% if 'status' in item %}
<tr>
<th>status</th>
<td>{{ item.status }}</td>
</tr>
{% endif %}
{% if 'server' in item %}
<tr>
<th>server</th>
<td>{{ item.server }}</td>
</tr>
{% endif %}
{% if 'channel' in item %}
<tr>
<th>channel</th>
<td>{{ item.channel }}</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
<hr/>
{% endfor %}
</div>
</div>

View File

@ -107,16 +107,15 @@ class InsightsMeta(LoginRequiredMixin, APIView):
if k in ["ts", "time", "date", "id"]:
continue
unique_values[nick][k].add(v)
meta_dedup = []
meta_dedup = {}
for x in meta:
nick = x["nick"]
meta_l2 = {}
for k, v in x.items():
if v in unique_values[nick][k]:
meta_l2[k] = v
if k not in meta_dedup:
meta_dedup[k] = set()
meta_dedup[k].add(v)
unique_values[nick][k].remove(v)
if not set(meta_l2.keys()).issubset(set(["ts", "time", "date", "id"])):
meta_dedup.append(meta_l2)
context = {"net": net, "nicks": nicks, "meta": meta_dedup}
return render(request, self.template_name, context)