|
|
|
@ -7,7 +7,7 @@ from django.views import View
|
|
|
|
|
from rest_framework.parsers import FormParser
|
|
|
|
|
from rest_framework.views import APIView
|
|
|
|
|
|
|
|
|
|
from core.db.druid import query_single_result
|
|
|
|
|
from core.db.storage import db
|
|
|
|
|
from core.lib.meta import get_meta
|
|
|
|
|
from core.lib.nicktrace import get_nicks
|
|
|
|
|
from core.lib.threshold import (
|
|
|
|
@ -23,8 +23,9 @@ class Insights(LoginRequiredMixin, PermissionRequiredMixin, View):
|
|
|
|
|
template_name = "ui/insights/insights.html"
|
|
|
|
|
permission_required = "use_insights"
|
|
|
|
|
|
|
|
|
|
def get(self, request):
|
|
|
|
|
return render(request, self.template_name)
|
|
|
|
|
def get(self, request, index):
|
|
|
|
|
context = {"index": index}
|
|
|
|
|
return render(request, self.template_name, context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InsightsSearch(LoginRequiredMixin, PermissionRequiredMixin, View):
|
|
|
|
@ -32,13 +33,16 @@ class InsightsSearch(LoginRequiredMixin, PermissionRequiredMixin, View):
|
|
|
|
|
template_name = "ui/insights/info.html"
|
|
|
|
|
permission_required = "use_insights"
|
|
|
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
|
def post(self, request, index):
|
|
|
|
|
query_params = request.POST.dict()
|
|
|
|
|
if "query_full" in query_params:
|
|
|
|
|
query_params["query_full"] = "nick: " + query_params["query_full"]
|
|
|
|
|
context = query_single_result(request, query_params)
|
|
|
|
|
if "query" in query_params:
|
|
|
|
|
query_params["query"] = "nick: " + query_params["query"]
|
|
|
|
|
query_params["source"] = "all"
|
|
|
|
|
query_params["index"] = index
|
|
|
|
|
context = db.query_single_result(request, query_params)
|
|
|
|
|
if not context:
|
|
|
|
|
return HttpResponseForbidden()
|
|
|
|
|
context["index"] = index
|
|
|
|
|
return render(request, self.template_name, context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -47,7 +51,7 @@ class InsightsChannels(LoginRequiredMixin, PermissionRequiredMixin, APIView):
|
|
|
|
|
template_name = "ui/insights/channels.html"
|
|
|
|
|
permission_required = "use_insights"
|
|
|
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
|
def post(self, request, index):
|
|
|
|
|
if "net" not in request.data:
|
|
|
|
|
return HttpResponse("No net")
|
|
|
|
|
if "nick" not in request.data:
|
|
|
|
@ -58,7 +62,13 @@ class InsightsChannels(LoginRequiredMixin, PermissionRequiredMixin, APIView):
|
|
|
|
|
num_users = annotate_num_users(net, chans)
|
|
|
|
|
if not chans:
|
|
|
|
|
return HttpResponseForbidden()
|
|
|
|
|
context = {"net": net, "nick": nick, "chans": chans, "num_users": num_users}
|
|
|
|
|
context = {
|
|
|
|
|
"net": net,
|
|
|
|
|
"nick": nick,
|
|
|
|
|
"chans": chans,
|
|
|
|
|
"num_users": num_users,
|
|
|
|
|
"index": index,
|
|
|
|
|
}
|
|
|
|
|
return render(request, self.template_name, context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -67,7 +77,7 @@ class InsightsNicks(LoginRequiredMixin, PermissionRequiredMixin, APIView):
|
|
|
|
|
template_name = "ui/insights/nicks.html"
|
|
|
|
|
permission_required = "use_insights"
|
|
|
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
|
def post(self, request, index):
|
|
|
|
|
if "net" not in request.data:
|
|
|
|
|
return HttpResponse("No net")
|
|
|
|
|
if "nick" not in request.data:
|
|
|
|
@ -82,7 +92,13 @@ class InsightsNicks(LoginRequiredMixin, PermissionRequiredMixin, APIView):
|
|
|
|
|
online = annotate_online(net, nicks)
|
|
|
|
|
if not nicks:
|
|
|
|
|
return HttpResponseForbidden()
|
|
|
|
|
context = {"net": net, "nick": nick, "nicks": nicks, "online": online}
|
|
|
|
|
context = {
|
|
|
|
|
"net": net,
|
|
|
|
|
"nick": nick,
|
|
|
|
|
"nicks": nicks,
|
|
|
|
|
"online": online,
|
|
|
|
|
"index": index,
|
|
|
|
|
}
|
|
|
|
|
return render(request, self.template_name, context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -91,7 +107,7 @@ class InsightsMeta(LoginRequiredMixin, PermissionRequiredMixin, APIView):
|
|
|
|
|
template_name = "ui/insights/meta.html"
|
|
|
|
|
permission_required = "use_insights"
|
|
|
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
|
def post(self, request, index):
|
|
|
|
|
if "net" not in request.data:
|
|
|
|
|
return HttpResponse("No net")
|
|
|
|
|
if "nicks" not in request.data:
|
|
|
|
@ -99,6 +115,10 @@ class InsightsMeta(LoginRequiredMixin, PermissionRequiredMixin, APIView):
|
|
|
|
|
net = request.data["net"]
|
|
|
|
|
nicks = request.data["nicks"]
|
|
|
|
|
nicks = literal_eval(nicks)
|
|
|
|
|
|
|
|
|
|
# Check the user has permissions to use the meta index
|
|
|
|
|
if not request.user.has_perm("core.index_meta"):
|
|
|
|
|
return HttpResponseForbidden()
|
|
|
|
|
meta = get_meta(request, net, nicks)
|
|
|
|
|
unique_values = {}
|
|
|
|
|
# Create a map of unique values for each key for each nick
|
|
|
|
@ -122,7 +142,7 @@ class InsightsMeta(LoginRequiredMixin, PermissionRequiredMixin, APIView):
|
|
|
|
|
meta_dedup[k].add(v)
|
|
|
|
|
unique_values[nick][k].remove(v)
|
|
|
|
|
|
|
|
|
|
context = {"net": net, "nicks": nicks, "meta": meta_dedup}
|
|
|
|
|
context = {"net": net, "nicks": nicks, "meta": meta_dedup, "index": index}
|
|
|
|
|
return render(request, self.template_name, context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -131,7 +151,7 @@ class InsightsInfoModal(LoginRequiredMixin, PermissionRequiredMixin, APIView):
|
|
|
|
|
template_name = "modals/drilldown.html"
|
|
|
|
|
permission_required = "use_insights"
|
|
|
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
|
def post(self, request, index):
|
|
|
|
|
if "net" not in request.data:
|
|
|
|
|
return JsonResponse({"success": False})
|
|
|
|
|
if "nick" not in request.data:
|
|
|
|
@ -163,5 +183,6 @@ class InsightsInfoModal(LoginRequiredMixin, PermissionRequiredMixin, APIView):
|
|
|
|
|
"inter_users": inter_users,
|
|
|
|
|
"num_users": num_users,
|
|
|
|
|
"num_chans": num_chans,
|
|
|
|
|
"index": index,
|
|
|
|
|
}
|
|
|
|
|
return render(request, self.template_name, context)
|
|
|
|
|