Properly implement queries
This commit is contained in:
parent
1d2f37f588
commit
6af8e94336
|
@ -220,6 +220,11 @@ urlpatterns = [
|
||||||
ThresholdIRCSendMessage.as_view(),
|
ThresholdIRCSendMessage.as_view(),
|
||||||
name="threshold_irc_msg",
|
name="threshold_irc_msg",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"manage/threshold/irc/msg/<str:net>/<int:num>/<str:channel>/<str:nick>/",
|
||||||
|
ThresholdIRCSendMessage.as_view(),
|
||||||
|
name="threshold_irc_msg",
|
||||||
|
),
|
||||||
##
|
##
|
||||||
path("api/chans/", ThresholdChans.as_view(), name="chans"),
|
path("api/chans/", ThresholdChans.as_view(), name="chans"),
|
||||||
path("api/users/", ThresholdUsers.as_view(), name="users"),
|
path("api/users/", ThresholdUsers.as_view(), name="users"),
|
||||||
|
|
|
@ -195,9 +195,11 @@ def get_irc_alerts(user):
|
||||||
return results_parsed
|
return results_parsed
|
||||||
|
|
||||||
|
|
||||||
def send_irc_message(net, num, channel, msg):
|
def send_irc_message(net, num, channel, msg, nick=None):
|
||||||
channel = urllib.parse.quote(channel, safe="")
|
channel = urllib.parse.quote(channel, safe="")
|
||||||
url = f"irc/msg/{net}/{num}/{channel}"
|
url = f"irc/msg/{net}/{num}/{channel}"
|
||||||
payload = {"msg": msg}
|
payload = {"msg": msg}
|
||||||
|
if nick:
|
||||||
|
payload["nick"] = nick
|
||||||
messaged = threshold_request(url, payload, method="PUT")
|
messaged = threshold_request(url, payload, method="PUT")
|
||||||
return messaged
|
return messaged
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
id="search"
|
id="search"
|
||||||
class="button is-info is-fullwidth"
|
class="button is-info is-fullwidth"
|
||||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
hx-put="{% url 'threshold_irc_msg' net num channel %}"
|
hx-put="{% url 'threshold_irc_msg' net num channel nick %}"
|
||||||
hx-trigger="click"
|
hx-trigger="click"
|
||||||
hx-target="#context-input"
|
hx-target="#context-input"
|
||||||
hx-swap="outerHTML">
|
hx-swap="outerHTML">
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
"date": "{{ date }}",
|
"date": "{{ date }}",
|
||||||
"index": "{{ index }}",
|
"index": "{{ index }}",
|
||||||
"type": "{{ type }}",
|
"type": "{{ type }}",
|
||||||
"mtype": "{{ mtype }}"}'
|
"mtype": "{{ mtype }}",
|
||||||
|
"nick": "{{ nick }}"}'
|
||||||
hx-target="#modal-context-table"
|
hx-target="#modal-context-table"
|
||||||
hx-trigger="every 5s">
|
hx-trigger="every 5s">
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -225,7 +225,8 @@
|
||||||
"date": "{{ row.cells.date|escapejs }}",
|
"date": "{{ row.cells.date|escapejs }}",
|
||||||
"index": "{{ params.index }}",
|
"index": "{{ params.index }}",
|
||||||
"type": "{{ row.cells.type }}",
|
"type": "{{ row.cells.type }}",
|
||||||
"mtype": "{{ row.cells.mtype }}"}'
|
"mtype": "{{ row.cells.mtype }}",
|
||||||
|
"nick": "{{ row.cells.nick|escapejs }}"}'
|
||||||
hx-target="#modals-here"
|
hx-target="#modals-here"
|
||||||
hx-trigger="click">
|
hx-trigger="click">
|
||||||
{{ row.cells.msg }}
|
{{ row.cells.msg }}
|
||||||
|
|
|
@ -448,7 +448,7 @@ class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView):
|
||||||
parser_classes = [FormParser]
|
parser_classes = [FormParser]
|
||||||
template_name = "partials/context-input.html"
|
template_name = "partials/context-input.html"
|
||||||
|
|
||||||
def put(self, request, net, num, channel):
|
def put(self, request, net, num, channel, nick=None):
|
||||||
"""
|
"""
|
||||||
Send a message
|
Send a message
|
||||||
"""
|
"""
|
||||||
|
@ -460,8 +460,15 @@ class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView):
|
||||||
self.template_name,
|
self.template_name,
|
||||||
{"message": message, "class": message_class},
|
{"message": message, "class": message_class},
|
||||||
)
|
)
|
||||||
|
print("IRC", nick)
|
||||||
messaged = threshold.send_irc_message(net, num, channel, request.data["msg"])
|
if nick:
|
||||||
|
messaged = threshold.send_irc_message(
|
||||||
|
net, num, channel, request.data["msg"], nick=nick
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
messaged = threshold.send_irc_message(
|
||||||
|
net, num, channel, request.data["msg"]
|
||||||
|
)
|
||||||
if not messaged:
|
if not messaged:
|
||||||
message = "Failed to send message"
|
message = "Failed to send message"
|
||||||
message_class = "danger"
|
message_class = "danger"
|
||||||
|
@ -471,6 +478,7 @@ class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView):
|
||||||
else:
|
else:
|
||||||
message = messaged["reason"]
|
message = messaged["reason"]
|
||||||
message_class = "danger"
|
message_class = "danger"
|
||||||
|
print("ERROR", message)
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"net": net,
|
"net": net,
|
||||||
|
|
|
@ -245,7 +245,7 @@ class DrilldownContextModal(APIView):
|
||||||
|
|
||||||
size = 20
|
size = 20
|
||||||
# Create the query params from the POST arguments
|
# Create the query params from the POST arguments
|
||||||
mandatory = ["net", "channel", "num", "src", "index"]
|
mandatory = ["net", "channel", "num", "src", "index", "nick"]
|
||||||
invalid = [None, False, "—", "None"]
|
invalid = [None, False, "—", "None"]
|
||||||
query_params = {k: v for k, v in request.data.items() if v}
|
query_params = {k: v for k, v in request.data.items() if v}
|
||||||
for key in query_params:
|
for key in query_params:
|
||||||
|
@ -258,7 +258,11 @@ class DrilldownContextModal(APIView):
|
||||||
if "mtype" not in query_params:
|
if "mtype" not in query_params:
|
||||||
query_params["mtype"] = None
|
query_params["mtype"] = None
|
||||||
query_params["sorting"] = "desc"
|
query_params["sorting"] = "desc"
|
||||||
if query_params["index"] == "int" and query_params["mtype"] == "msg":
|
if (
|
||||||
|
query_params["index"] == "int"
|
||||||
|
and query_params["mtype"] == "msg"
|
||||||
|
and not query_params["type"] == "query"
|
||||||
|
):
|
||||||
query_params["index"] = "main"
|
query_params["index"] = "main"
|
||||||
# Create the query with the context helper
|
# Create the query with the context helper
|
||||||
search_query = construct_query(
|
search_query = construct_query(
|
||||||
|
@ -292,6 +296,7 @@ class DrilldownContextModal(APIView):
|
||||||
"num": query_params["num"],
|
"num": query_params["num"],
|
||||||
"type": query_params["type"],
|
"type": query_params["type"],
|
||||||
"mtype": query_params["mtype"],
|
"mtype": query_params["mtype"],
|
||||||
|
"nick": query_params["nick"],
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, self.template_name, context)
|
return render(request, self.template_name, context)
|
||||||
|
|
Loading…
Reference in New Issue