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 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. Get all related nicknames of the given nickname by tracking nickname changes.
""" """
print("GET NICKS INIT", net, nick, iter)
# Get the initial query # Get the initial query
query = {} query = {
results = set() "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"] # nicks = query["nicks"]
# for nick in nicks: # for nick in nicks:
# if nick not in results: # if nick not in results:

View File

@ -1,16 +1,19 @@
<div id="channels"> <div id="channels">
{% for chan in chans %} <div class="content">
<span class="panel-icon"> <ol type="1">
<i class="fa-solid fa-hashtag" aria-hidden="true"></i> {% for chan in chans %}
</span> <li>
<span <span
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'modal_drilldown' %}" hx-post="{% url 'modal_drilldown' %}"
hx-vals='{"net": "{{ net }}", "nick": "{{ nick }}", "channel": "{{ chan }}"}' hx-vals='{"net": "{{ net }}", "nick": "{{ nick }}", "channel": "{{ chan }}"}'
hx-target="#modals-here" hx-target="#modals-here"
hx-trigger="click" hx-trigger="click"
class="button is-small"> class="button is-small">
{{ chan }} {{ chan }}
</span> </span>
{% endfor %} </li>
{% endfor %}
</ol>
</div>
</div> </div>

View File

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

View File

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