Implement nicks output on Insights
This commit is contained in:
parent
9f808c43ee
commit
ce3a871c46
|
@ -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:
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<div id="channels">
|
<div id="channels">
|
||||||
|
<div class="content">
|
||||||
|
<ol type="1">
|
||||||
{% for chan in chans %}
|
{% for chan in chans %}
|
||||||
<span class="panel-icon">
|
<li>
|
||||||
<i class="fa-solid fa-hashtag" aria-hidden="true"></i>
|
|
||||||
</span>
|
|
||||||
<span
|
<span
|
||||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
hx-post="{% url 'modal_drilldown' %}"
|
hx-post="{% url 'modal_drilldown' %}"
|
||||||
|
@ -12,5 +12,8 @@
|
||||||
class="button is-small">
|
class="button is-small">
|
||||||
{{ chan }}
|
{{ chan }}
|
||||||
</span>
|
</span>
|
||||||
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
|
@ -1,7 +1,8 @@
|
||||||
<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 %}
|
||||||
|
<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' %}"
|
||||||
|
@ -9,6 +10,10 @@
|
||||||
hx-target="#modals-here"
|
hx-target="#modals-here"
|
||||||
hx-trigger="click"
|
hx-trigger="click"
|
||||||
class="button is-small">
|
class="button is-small">
|
||||||
aaa
|
{{ nick }}
|
||||||
</span>
|
</span>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
|
@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue