Fix context menu
This commit is contained in:
parent
d8981378bd
commit
5530fd762c
|
@ -19,6 +19,64 @@ class DruidBackend(StorageBackend):
|
|||
# self.client = PyDruid("http://broker:8082", "druid/v2")
|
||||
pass # we use requests
|
||||
|
||||
def construct_context_query(
|
||||
self, index, net, channel, src, num, size, type=None, nicks=None
|
||||
):
|
||||
search_query = self.construct_query(None, size, index, blank=True)
|
||||
extra_must = []
|
||||
extra_should = []
|
||||
extra_should2 = []
|
||||
if num:
|
||||
extra_must.append({"num": num})
|
||||
if net:
|
||||
extra_must.append({"net": net})
|
||||
if channel:
|
||||
extra_must.append({"channel": channel})
|
||||
if nicks:
|
||||
for nick in nicks:
|
||||
extra_should2.append({"nick": nick})
|
||||
types = ["msg", "notice", "action", "kick", "topic", "mode"]
|
||||
|
||||
if index == "internal":
|
||||
if channel == "*status" or type == "znc":
|
||||
if {"channel": channel} in extra_must:
|
||||
extra_must.remove({"channel": channel})
|
||||
extra_should2 = []
|
||||
# Type is one of msg or notice
|
||||
# extra_should.append({"match": {"mtype": "msg"}})
|
||||
# extra_should.append({"match": {"mtype": "notice"}})
|
||||
extra_should.append({"type": "znc"})
|
||||
extra_should.append({"type": "self"})
|
||||
|
||||
extra_should2.append({"type": "znc"})
|
||||
extra_should2.append({"nick": channel})
|
||||
elif type == "auth":
|
||||
if {"match": {"channel": channel}} in extra_must:
|
||||
extra_must.remove({"channel": channel})
|
||||
extra_should2 = []
|
||||
extra_should2.append({"nick": channel})
|
||||
# extra_should2.append({"match": {"mtype": "msg"}})
|
||||
# extra_should2.append({"match": {"mtype": "notice"}})
|
||||
|
||||
extra_should.append({"type": "query"})
|
||||
extra_should2.append({"type": "self"})
|
||||
extra_should.append({"nick": channel})
|
||||
else:
|
||||
for ctype in types:
|
||||
extra_should.append({"mtype": ctype})
|
||||
else:
|
||||
for ctype in types:
|
||||
extra_should.append({"type": ctype})
|
||||
|
||||
if extra_must:
|
||||
self.add_type("and", search_query, extra_must)
|
||||
|
||||
if extra_should:
|
||||
self.add_type("or", search_query, extra_should)
|
||||
if extra_should2:
|
||||
self.add_type("or", search_query, extra_should2)
|
||||
return search_query
|
||||
|
||||
def construct_query(self, query, size, index, blank=False):
|
||||
search_query = {
|
||||
"limit": size,
|
||||
|
|
|
@ -12,7 +12,6 @@ from rest_framework.parsers import FormParser
|
|||
from rest_framework.views import APIView
|
||||
|
||||
from core.db.storage import db
|
||||
from core.lib.context import construct_query
|
||||
from core.lib.threshold import (
|
||||
annotate_num_chans,
|
||||
annotate_num_users,
|
||||
|
@ -361,9 +360,14 @@ class DrilldownContextModal(APIView):
|
|||
if query_params["type"] not in ["znc", "auth"]:
|
||||
annotate = True
|
||||
# Create the query with the context helper
|
||||
if query_params["num"].isdigit():
|
||||
query_params["num"] = int(query_params["num"])
|
||||
search_query = construct_query(
|
||||
if "num" in query_params:
|
||||
if query_params["num"]:
|
||||
if query_params["num"].isdigit():
|
||||
query_params["num"] = int(query_params["num"])
|
||||
else:
|
||||
return {"message": "Invalid num value", "class": "danger"}
|
||||
|
||||
search_query = db.construct_context_query(
|
||||
query_params["index"],
|
||||
query_params["net"],
|
||||
query_params["channel"],
|
||||
|
|
Loading…
Reference in New Issue