Implement nicks output on Insights

This commit is contained in:
Mark Veidemanis 2022-07-21 13:52:20 +01:00
parent 9f808c43ee
commit ce3a871c46
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
4 changed files with 98 additions and 39 deletions

View File

@ -1,13 +1,68 @@
from core.lib.opensearch import client, run_main_query
def get_nicks(request, net, nick):
def get_nicks(request, net, nick, iter=0):
"""
Get all related nicknames of the given nickname by tracking nickname changes.
"""
print("GET NICKS INIT", net, nick, iter)
# Get the initial query
query = {}
results = set()
query = {
"size": 10000,
"query": {
"bool": {
"must": [
{"match": {"net": net}},
{"match": {"type": "nick"}},
{
"bool": {
"should": [
{"match": {"nick": nick}},
{"match": {"user": nick}},
]
}
},
]
}
},
}
results = run_main_query(client, request.user, query, custom_query=True)
nicks = []
if "hits" in results.keys():
if "hits" in results["hits"]:
for item in results["hits"]["hits"]:
element = item["_source"]
element["id"] = item["_id"]
# Split the timestamp into date and time
ts = element["ts"]
ts_spl = ts.split("T")
date = ts_spl[0]
time = ts_spl[1]
element["date"] = date
element["time"] = time
if element["nick"] not in nicks:
nicks.append(element["nick"])
if element["user"] not in nicks:
nicks.append(element["user"])
# if iter < 2:
# iter += 1
# collect_nicks = []
# for x in nicks:
# nicks_2 = get_nicks(request, net, x, iter)
# print("NICKS_2", nicks_2)
# for y in nicks_2:
# if y not in collect_nicks:
# collect_nicks.append(y)
# print("RETURN NICKS", nick, collect_nicks)
# for x in collect_nicks:
# if x not in nicks:
# nicks.append(x)
# else:
# print("ABORTING SEARCH")
return nicks
# results = set()
# nicks = query["nicks"]
# for nick in nicks:
# if nick not in results:

View File

@ -1,8 +1,8 @@
<div id="channels">
<div class="content">
<ol type="1">
{% for chan in chans %}
<span class="panel-icon">
<i class="fa-solid fa-hashtag" aria-hidden="true"></i>
</span>
<li>
<span
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'modal_drilldown' %}"
@ -12,5 +12,8 @@
class="button is-small">
{{ chan }}
</span>
</li>
{% endfor %}
</ol>
</div>
</div>

View File

@ -1,7 +1,8 @@
<div id="nicks">
<span class="panel-icon">
<i class="fa-solid fa-hashtag" aria-hidden="true"></i>
</span>
<div class="content">
<ol type="1">
{% for nick in nicks %}
<li>
<span
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'modal_drilldown' %}"
@ -9,6 +10,10 @@
hx-target="#modals-here"
hx-trigger="click"
class="button is-small">
aaa
{{ nick }}
</span>
</li>
{% endfor %}
</ol>
</div>
</div>

View File

@ -26,10 +26,7 @@ class InsightsSearch(LoginRequiredMixin, View):
results, context = query_single_result(request)
if not context:
return HttpResponseForbidden()
if context:
return render(request, self.template_name, context)
else:
return HttpResponse("No results")
class InsightsChannels(LoginRequiredMixin, APIView):
@ -52,10 +49,7 @@ class InsightsChannels(LoginRequiredMixin, APIView):
if not chans:
return HttpResponseForbidden()
context = {"net": net, "nick": nick, "chans": chans}
if chans:
return render(request, self.template_name, context)
else:
return HttpResponse("No results")
class InsightsNicks(LoginRequiredMixin, APIView):
@ -72,8 +66,10 @@ class InsightsNicks(LoginRequiredMixin, APIView):
return HttpResponse("No nick")
net = request.data["net"]
nick = request.data["nick"]
context = {"net": net, "nick": nick}
nicks = get_nicks(request, net, nick)
if not nicks:
return HttpResponseForbidden()
context = {"net": net, "nick": nick, "nicks": nicks}
return render(request, self.template_name, context)