Improve modal and implement deduplication
This commit is contained in:
@@ -196,7 +196,6 @@ def send_irc_message(net, num, channel, msg, nick=None):
|
||||
payload = {"msg": msg, "channel": channel}
|
||||
if nick:
|
||||
payload["nick"] = nick
|
||||
print("SEND", payload)
|
||||
messaged = threshold_request(url, payload, method="PUT")
|
||||
return messaged
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ from opensearchpy import OpenSearch
|
||||
from opensearchpy.exceptions import NotFoundError, RequestError
|
||||
|
||||
from core.lib.threshold import annotate_num_chans, annotate_num_users, annotate_online
|
||||
from core.views.helpers import dedup_list
|
||||
|
||||
|
||||
def initialise_opensearch():
|
||||
@@ -49,7 +50,9 @@ def annotate_results(results_parsed):
|
||||
[
|
||||
x["nick"]
|
||||
for x in results_parsed
|
||||
if x["src"] == "irc" and x["net"] == net and "nick" in x
|
||||
if {"nick", "src", "net"}.issubset(x)
|
||||
and x["src"] == "irc"
|
||||
and x["net"] == net
|
||||
]
|
||||
)
|
||||
)
|
||||
@@ -58,7 +61,9 @@ def annotate_results(results_parsed):
|
||||
[
|
||||
x["channel"]
|
||||
for x in results_parsed
|
||||
if x["src"] == "irc" and x["net"] == net and "channel" in x
|
||||
if {"channel", "src", "net"}.issubset(x)
|
||||
and x["src"] == "irc"
|
||||
and x["net"] == net
|
||||
]
|
||||
)
|
||||
)
|
||||
@@ -244,7 +249,16 @@ def parse_results(results):
|
||||
return results_parsed
|
||||
|
||||
|
||||
def query_results(request, query_params, size=None, annotate=True, custom_query=False):
|
||||
def query_results(
|
||||
request,
|
||||
query_params,
|
||||
size=None,
|
||||
annotate=True,
|
||||
custom_query=False,
|
||||
reverse=False,
|
||||
dedup=False,
|
||||
dedup_fields=None,
|
||||
):
|
||||
"""
|
||||
API helper to alter the OpenSearch return format into something
|
||||
a bit better to parse.
|
||||
@@ -403,8 +417,24 @@ def query_results(request, query_params, size=None, annotate=True, custom_query=
|
||||
return {"message": message, "class": message_class}
|
||||
|
||||
results_parsed = parse_results(results)
|
||||
|
||||
if annotate:
|
||||
annotate_results(results_parsed)
|
||||
if "dedup" in query_params:
|
||||
if query_params["dedup"] == "on":
|
||||
dedup = True
|
||||
else:
|
||||
dedup = False
|
||||
else:
|
||||
dedup = False
|
||||
|
||||
if reverse:
|
||||
results_parsed = results_parsed[::-1]
|
||||
|
||||
if dedup:
|
||||
if not dedup_fields:
|
||||
dedup_fields = ["msg", "nick", "ident", "host", "net", "channel"]
|
||||
results_parsed = dedup_list(results_parsed, dedup_fields)
|
||||
|
||||
context = {
|
||||
"object_list": results_parsed,
|
||||
|
||||
Reference in New Issue
Block a user