Fix ZNC queries
This commit is contained in:
parent
c9fe1f0b73
commit
4be21cb488
|
@ -1,4 +1,4 @@
|
|||
def construct_query(index, net, channel, src, num, size, nicks=None):
|
||||
def construct_query(index, net, channel, src, num, size, type=None, nicks=None):
|
||||
# Get the initial query
|
||||
extra_must = []
|
||||
extra_should = []
|
||||
|
@ -26,8 +26,14 @@ def construct_query(index, net, channel, src, num, size, nicks=None):
|
|||
]
|
||||
if index == "int":
|
||||
fields.append("mtype")
|
||||
for ctype in types:
|
||||
extra_should.append({"match": {"mtype": ctype}})
|
||||
if channel == "*status" or type == "znc":
|
||||
if {"match": {"channel": channel}} in extra_must:
|
||||
extra_must.remove({"match": {"channel": channel}})
|
||||
extra_should2 = []
|
||||
extra_must.append({"match": {"type": "znc"}})
|
||||
else:
|
||||
for ctype in types:
|
||||
extra_should.append({"match": {"mtype": ctype}})
|
||||
else:
|
||||
for ctype in types:
|
||||
extra_should.append({"match": {"type": ctype}})
|
||||
|
@ -54,5 +60,4 @@ def construct_query(index, net, channel, src, num, size, nicks=None):
|
|||
"fields": fields,
|
||||
"_source": False,
|
||||
}
|
||||
|
||||
return query
|
||||
|
|
|
@ -104,15 +104,15 @@
|
|||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||
hx-post="{% url 'modal_context' %}"
|
||||
hx-vals='{"net": "{{ net }}",
|
||||
"num": "{{ relay.id }}",
|
||||
"src": "irc",
|
||||
"channel": "None",
|
||||
"time": "None",
|
||||
"date": "None",
|
||||
"index": "int",
|
||||
"type": "znc",
|
||||
"mtype": "None",
|
||||
"nick": "None"}'
|
||||
"num": "{{ relay.id }}",
|
||||
"src": "irc",
|
||||
"channel": "*status",
|
||||
"time": "None",
|
||||
"date": "None",
|
||||
"index": "int",
|
||||
"type": "znc",
|
||||
"mtype": "None",
|
||||
"nick": "*status"}'
|
||||
hx-target="#modals-here"
|
||||
hx-trigger="click"
|
||||
class="button is-small has-background-info has-text-white">
|
||||
|
@ -120,7 +120,7 @@
|
|||
<i class="fa-brands fa-unity" aria-hidden="true"></i>
|
||||
</span>
|
||||
</a>
|
||||
</td> {# actions-top #}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
|
@ -134,7 +134,7 @@
|
|||
<i class="fa-solid fa-xmark" aria-hidden="true"></i>
|
||||
</span>
|
||||
</a>
|
||||
</td> {# id #}
|
||||
</td>
|
||||
<td>
|
||||
<a
|
||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||
|
@ -146,7 +146,7 @@
|
|||
<i class="fa-solid fa-wrench" aria-hidden="true"></i>
|
||||
</span>
|
||||
</a>
|
||||
</td> {# reg #}
|
||||
</td>
|
||||
<td>
|
||||
<a
|
||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||
|
@ -158,8 +158,8 @@
|
|||
<i class="fa-solid fa-passport" aria-hidden="true"></i>
|
||||
</span>
|
||||
</a>
|
||||
</td> {# auth #}
|
||||
<td></td> {# conn #}
|
||||
</td>
|
||||
<td></td>
|
||||
<td>
|
||||
{% if relay.enabled %}
|
||||
<a
|
||||
|
@ -184,7 +184,7 @@
|
|||
</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
</td> {# on #}
|
||||
</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
|
@ -199,7 +199,7 @@
|
|||
<i class="fa-solid fa-signature" aria-hidden="true"></i>
|
||||
</span>
|
||||
</a>
|
||||
</td> {# actions-bottom #}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
@ -104,7 +104,7 @@ class ThresholdIRCNetworkRelays(SuperUserRequiredMixin, View):
|
|||
|
||||
def get(self, request, net):
|
||||
relays = threshold.get_irc_relays(net)
|
||||
context = {"relays": relays["relays"]}
|
||||
context = {"net": net, "relays": relays["relays"]}
|
||||
return render(request, self.template_name, context)
|
||||
|
||||
|
||||
|
|
|
@ -253,7 +253,7 @@ class DrilldownContextModal(APIView):
|
|||
size = 20
|
||||
nicks = None
|
||||
# Create the query params from the POST arguments
|
||||
mandatory = ["net", "channel", "num", "src", "index", "nick"]
|
||||
mandatory = ["net", "channel", "num", "src", "index", "nick", "type"]
|
||||
invalid = [None, False, "—", "None"]
|
||||
query_params = {k: v for k, v in request.data.items() if v}
|
||||
for key in query_params:
|
||||
|
@ -275,6 +275,13 @@ class DrilldownContextModal(APIView):
|
|||
and not query_params["type"] == "query"
|
||||
):
|
||||
query_params["index"] = "main"
|
||||
|
||||
type = None
|
||||
if "type" in query_params:
|
||||
type = query_params["type"]
|
||||
if type == "znc":
|
||||
query_params["channel"] = "*status"
|
||||
|
||||
# Create the query with the context helper
|
||||
search_query = construct_query(
|
||||
query_params["index"],
|
||||
|
@ -283,10 +290,16 @@ class DrilldownContextModal(APIView):
|
|||
query_params["src"],
|
||||
query_params["num"],
|
||||
size,
|
||||
type=type,
|
||||
nicks=nicks,
|
||||
)
|
||||
annotate = False
|
||||
if query_params["src"] == "irc":
|
||||
if query_params["type"] in ["query", "notice", "msg", "highlight"]:
|
||||
annotate = True
|
||||
|
||||
results = query_results(
|
||||
request, query_params, annotate=True, custom_query=search_query
|
||||
request, query_params, annotate=annotate, custom_query=search_query
|
||||
)
|
||||
if "message" in results:
|
||||
return render(request, self.template_name, results)
|
||||
|
|
Loading…
Reference in New Issue