From 3d91c4164e9bbf9fa2a32875cb2ee44315b092ef Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Wed, 27 Jul 2022 13:12:16 +0100 Subject: [PATCH] Refactor code into fewer files, removing dynamic folders --- app/urls.py | 32 +++++++++---------- .../threshold/irc/network/channels.html | 0 .../threshold/irc/network/edit-network.html | 0 .../manage/threshold/irc/network/info.html | 0 .../threshold/irc/{ => network}/network.html | 0 .../manage/threshold/irc/network/relays.html | 0 .../threshold/irc/overview/networks.html | 0 .../irc/{ => overview}/overview.html | 0 .../manage/threshold/irc/overview/stats.html | 0 core/ui/views/drilldown.py | 17 ---------- core/ui/views/insights.py | 13 -------- core/views/dynamic/__init__.py | 0 .../{dynamic => }/manage/threshold/irc.py | 14 ++++---- .../views/manage/{ => threshold}/threshold.py | 4 +-- core/views/{dynamic => ui}/drilldown.py | 20 +++++++++--- core/views/{dynamic => ui}/insights.py | 16 +++++++--- 16 files changed, 53 insertions(+), 63 deletions(-) rename core/templates/{dynamic => }/manage/threshold/irc/network/channels.html (100%) rename core/templates/{dynamic => }/manage/threshold/irc/network/edit-network.html (100%) rename core/templates/{dynamic => }/manage/threshold/irc/network/info.html (100%) rename core/templates/manage/threshold/irc/{ => network}/network.html (100%) rename core/templates/{dynamic => }/manage/threshold/irc/network/relays.html (100%) rename core/templates/{dynamic => }/manage/threshold/irc/overview/networks.html (100%) rename core/templates/manage/threshold/irc/{ => overview}/overview.html (100%) rename core/templates/{dynamic => }/manage/threshold/irc/overview/stats.html (100%) delete mode 100644 core/ui/views/drilldown.py delete mode 100644 core/ui/views/insights.py delete mode 100644 core/views/dynamic/__init__.py rename core/views/{dynamic => }/manage/threshold/irc.py (84%) rename core/views/manage/{ => threshold}/threshold.py (77%) rename core/views/{dynamic => ui}/drilldown.py (86%) rename core/views/{dynamic => ui}/insights.py (95%) diff --git a/app/urls.py b/app/urls.py index 706758b..dea5db9 100644 --- a/app/urls.py +++ b/app/urls.py @@ -21,23 +21,9 @@ from django.views.generic import TemplateView # Threshold API stuff from core.api.views.threshold import ThresholdChans, ThresholdOnline, ThresholdUsers - -# Main tool pages -from core.ui.views.drilldown import Drilldown -from core.ui.views.insights import Insights from core.views import Billing, Cancel, Home, Order, Portal, Signup from core.views.callbacks import Callback - -# Dynamic elements -from core.views.dynamic.drilldown import DrilldownSearch, ThresholdInfoModal -from core.views.dynamic.insights import ( - InsightsChannels, - InsightsInfoModal, - InsightsMeta, - InsightsNicks, - InsightsSearch, -) -from core.views.dynamic.manage.threshold.irc import ( +from core.views.manage.threshold.irc import ( ThresholdIRCNetworkChannels, ThresholdIRCNetworkInfo, ThresholdIRCNetworkInfoEdit, @@ -47,7 +33,21 @@ from core.views.dynamic.manage.threshold.irc import ( ) # Management stuff -from core.views.manage.threshold import ThresholdIRCNetwork, ThresholdIRCOverview +from core.views.manage.threshold.threshold import ( + ThresholdIRCNetwork, + ThresholdIRCOverview, +) + +# Main tool pages +from core.views.ui.drilldown import Drilldown, DrilldownSearch, ThresholdInfoModal +from core.views.ui.insights import ( + Insights, + InsightsChannels, + InsightsInfoModal, + InsightsMeta, + InsightsNicks, + InsightsSearch, +) urlpatterns = [ path("", Home.as_view(), name="home"), diff --git a/core/templates/dynamic/manage/threshold/irc/network/channels.html b/core/templates/manage/threshold/irc/network/channels.html similarity index 100% rename from core/templates/dynamic/manage/threshold/irc/network/channels.html rename to core/templates/manage/threshold/irc/network/channels.html diff --git a/core/templates/dynamic/manage/threshold/irc/network/edit-network.html b/core/templates/manage/threshold/irc/network/edit-network.html similarity index 100% rename from core/templates/dynamic/manage/threshold/irc/network/edit-network.html rename to core/templates/manage/threshold/irc/network/edit-network.html diff --git a/core/templates/dynamic/manage/threshold/irc/network/info.html b/core/templates/manage/threshold/irc/network/info.html similarity index 100% rename from core/templates/dynamic/manage/threshold/irc/network/info.html rename to core/templates/manage/threshold/irc/network/info.html diff --git a/core/templates/manage/threshold/irc/network.html b/core/templates/manage/threshold/irc/network/network.html similarity index 100% rename from core/templates/manage/threshold/irc/network.html rename to core/templates/manage/threshold/irc/network/network.html diff --git a/core/templates/dynamic/manage/threshold/irc/network/relays.html b/core/templates/manage/threshold/irc/network/relays.html similarity index 100% rename from core/templates/dynamic/manage/threshold/irc/network/relays.html rename to core/templates/manage/threshold/irc/network/relays.html diff --git a/core/templates/dynamic/manage/threshold/irc/overview/networks.html b/core/templates/manage/threshold/irc/overview/networks.html similarity index 100% rename from core/templates/dynamic/manage/threshold/irc/overview/networks.html rename to core/templates/manage/threshold/irc/overview/networks.html diff --git a/core/templates/manage/threshold/irc/overview.html b/core/templates/manage/threshold/irc/overview/overview.html similarity index 100% rename from core/templates/manage/threshold/irc/overview.html rename to core/templates/manage/threshold/irc/overview/overview.html diff --git a/core/templates/dynamic/manage/threshold/irc/overview/stats.html b/core/templates/manage/threshold/irc/overview/stats.html similarity index 100% rename from core/templates/dynamic/manage/threshold/irc/overview/stats.html rename to core/templates/manage/threshold/irc/overview/stats.html diff --git a/core/ui/views/drilldown.py b/core/ui/views/drilldown.py deleted file mode 100644 index 686ce50..0000000 --- a/core/ui/views/drilldown.py +++ /dev/null @@ -1,17 +0,0 @@ -from django.conf import settings -from django.contrib.auth.mixins import LoginRequiredMixin -from django.shortcuts import render -from django.views import View - - -class Drilldown(LoginRequiredMixin, View): - template_name = "ui/drilldown/drilldown.html" - plan_name = "drilldown" - - def get(self, request): - if not request.user.has_plan(self.plan_name): - return render(request, "denied.html") - context = { - "sizes": settings.OPENSEARCH_MAIN_SIZES, - } - return render(request, self.template_name, context) diff --git a/core/ui/views/insights.py b/core/ui/views/insights.py deleted file mode 100644 index c4cc23e..0000000 --- a/core/ui/views/insights.py +++ /dev/null @@ -1,13 +0,0 @@ -from django.contrib.auth.mixins import LoginRequiredMixin -from django.shortcuts import render -from django.views import View - - -class Insights(LoginRequiredMixin, View): - template_name = "ui/insights/insights.html" - plan_name = "drilldown" - - def get(self, request): - if not request.user.has_plan(self.plan_name): - return render(request, "denied.html") - return render(request, self.template_name) diff --git a/core/views/dynamic/__init__.py b/core/views/dynamic/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/core/views/dynamic/manage/threshold/irc.py b/core/views/manage/threshold/irc.py similarity index 84% rename from core/views/dynamic/manage/threshold/irc.py rename to core/views/manage/threshold/irc.py index 8353cd9..14da424 100644 --- a/core/views/dynamic/manage/threshold/irc.py +++ b/core/views/manage/threshold/irc.py @@ -15,7 +15,7 @@ from core.views.manage.permissions import SuperUserRequiredMixin class ThresholdIRCStats(SuperUserRequiredMixin, View): - stats_template = "dynamic/manage/threshold/irc/overview/stats.html" + stats_template = "manage/threshold/irc/overview/stats.html" def post(self, request): stats = get_irc_stats() @@ -24,7 +24,7 @@ class ThresholdIRCStats(SuperUserRequiredMixin, View): class ThresholdIRCNetworks(SuperUserRequiredMixin, View): - template_name = "dynamic/manage/threshold/irc/overview/networks.html" + template_name = "manage/threshold/irc/overview/networks.html" def post(self, request): networks = get_irc_networks() @@ -33,7 +33,7 @@ class ThresholdIRCNetworks(SuperUserRequiredMixin, View): class ThresholdIRCNetworkInfo(SuperUserRequiredMixin, View): - template_name = "dynamic/manage/threshold/irc/network/info.html" + template_name = "manage/threshold/irc/network/info.html" def post(self, request, net): network = get_irc_network(net) @@ -42,7 +42,7 @@ class ThresholdIRCNetworkInfo(SuperUserRequiredMixin, View): class ThresholdIRCNetworkInfoEdit(SuperUserRequiredMixin, APIView): - template_name = "dynamic/manage/threshold/irc/network/edit-network.html" + template_name = "manage/threshold/irc/network/edit-network.html" parser_classes = [FormParser] def get(self, request, net): @@ -62,7 +62,7 @@ class ThresholdIRCNetworkInfoEdit(SuperUserRequiredMixin, APIView): Actually edit the network. Returns the info pane with a message about the success. """ - template_name = "dynamic/manage/threshold/irc/network/info.html" + template_name = "manage/threshold/irc/network/info.html" edited = edit_irc_network(net, request.data) if edited["success"]: message = "Successfully edited!" @@ -79,7 +79,7 @@ class ThresholdIRCNetworkInfoEdit(SuperUserRequiredMixin, APIView): class ThresholdIRCNetworkRelays(SuperUserRequiredMixin, View): - template_name = "dynamic/manage/threshold/irc/network/relays.html" + template_name = "manage/threshold/irc/network/relays.html" def post(self, request, net): relays = get_irc_relays(net) @@ -88,7 +88,7 @@ class ThresholdIRCNetworkRelays(SuperUserRequiredMixin, View): class ThresholdIRCNetworkChannels(SuperUserRequiredMixin, View): - template_name = "dynamic/manage/threshold/irc/network/channels.html" + template_name = "manage/threshold/irc/network/channels.html" def post(self, request, net): channels = get_irc_channels(net) diff --git a/core/views/manage/threshold.py b/core/views/manage/threshold/threshold.py similarity index 77% rename from core/views/manage/threshold.py rename to core/views/manage/threshold/threshold.py index 2a93cb6..6209de7 100644 --- a/core/views/manage/threshold.py +++ b/core/views/manage/threshold/threshold.py @@ -5,14 +5,14 @@ from core.views.manage.permissions import SuperUserRequiredMixin class ThresholdIRCOverview(SuperUserRequiredMixin, View): - template_name = "manage/threshold/irc/overview.html" + template_name = "manage/threshold/irc/overview/overview.html" def get(self, request): return render(request, self.template_name) class ThresholdIRCNetwork(SuperUserRequiredMixin, View): - template_name = "manage/threshold/irc/network.html" + template_name = "manage/threshold/irc/network/network.html" def get(self, request, net): context = {"net": net} diff --git a/core/views/dynamic/drilldown.py b/core/views/ui/drilldown.py similarity index 86% rename from core/views/dynamic/drilldown.py rename to core/views/ui/drilldown.py index 41d3765..d62d33c 100644 --- a/core/views/dynamic/drilldown.py +++ b/core/views/ui/drilldown.py @@ -1,13 +1,14 @@ -import json - +from django.conf import settings from django.contrib.auth.mixins import LoginRequiredMixin -from django.http import HttpResponse, HttpResponseForbidden, JsonResponse from django.shortcuts import render from django.views import View +from django.http import HttpResponse, HttpResponseForbidden, JsonResponse from rest_framework.parsers import FormParser from rest_framework.views import APIView - +import json from core.lib.opensearch import query_results + + from core.lib.threshold import ( annotate_num_chans, annotate_num_users, @@ -15,6 +16,17 @@ from core.lib.threshold import ( get_users, ) +class Drilldown(LoginRequiredMixin, View): + template_name = "ui/drilldown/drilldown.html" + plan_name = "drilldown" + + def get(self, request): + if not request.user.has_plan(self.plan_name): + return render(request, "denied.html") + context = { + "sizes": settings.OPENSEARCH_MAIN_SIZES, + } + return render(request, self.template_name, context) class DrilldownSearch(LoginRequiredMixin, View): # parser_classes = [JSONParser] diff --git a/core/views/dynamic/insights.py b/core/views/ui/insights.py similarity index 95% rename from core/views/dynamic/insights.py rename to core/views/ui/insights.py index a177329..4efbbc3 100644 --- a/core/views/dynamic/insights.py +++ b/core/views/ui/insights.py @@ -1,12 +1,10 @@ -from ast import literal_eval - from django.contrib.auth.mixins import LoginRequiredMixin -from django.http import HttpResponse, HttpResponseForbidden, JsonResponse from django.shortcuts import render from django.views import View from rest_framework.parsers import FormParser -from rest_framework.views import APIView +from django.http import HttpResponse, HttpResponseForbidden, JsonResponse +from rest_framework.views import APIView from core.lib.meta import get_meta from core.lib.nicktrace import get_nicks from core.lib.opensearch import query_single_result @@ -17,8 +15,18 @@ from core.lib.threshold import ( get_chans, get_users, ) +from ast import literal_eval +class Insights(LoginRequiredMixin, View): + template_name = "ui/insights/insights.html" + plan_name = "drilldown" + + def get(self, request): + if not request.user.has_plan(self.plan_name): + return render(request, "denied.html") + return render(request, self.template_name) + class InsightsSearch(LoginRequiredMixin, View): # parser_classes = [JSONParser] template_name = "ui/insights/info.html"