From 9bdacbca75473af56542110a02364853734d5618 Mon Sep 17 00:00:00 2001 From: Etzelia Date: Thu, 1 Jul 2021 03:07:45 +0000 Subject: [PATCH] Some changes (#9) Some changes Signed-off-by: Etzelia Reviewed-on: https://git.canopymc.net/Canopy/minecraft_manager/pulls/9 Co-Authored-By: Etzelia Co-Committed-By: Etzelia --- api/views.py | 30 ++++++----- bot/commands.py | 6 +-- bot/discord.py | 6 +-- external/views.py | 4 +- templates/minecraft_manager/application.html | 2 +- templates/minecraft_manager/ticket.html | 8 +++ urls.py | 8 +-- utils.py | 54 ++++++++++++-------- views.py | 50 ++++++++---------- 9 files changed, 92 insertions(+), 76 deletions(-) diff --git a/api/views.py b/api/views.py index d1798b5..fdba1eb 100644 --- a/api/views.py +++ b/api/views.py @@ -1,22 +1,23 @@ from __future__ import absolute_import -import logging, datetime -from django.contrib.auth.forms import PasswordChangeForm -from django.contrib.auth import update_session_auth_hash +import datetime +import logging + from django.apps import apps -from django.conf import settings +from django.contrib.auth import update_session_auth_hash +from django.contrib.auth.forms import PasswordChangeForm from django.contrib.auth.models import User +from django.forms import modelform_factory from django.http import JsonResponse, HttpResponse from django.utils import timezone from django.views.generic import View -from django.forms import modelform_factory -import minecraft_manager.forms as mcm_forms -from minecraft_manager.models import Player, UserSettings, Application, IP, Ticket, Note import minecraft_manager.api.api as mcm_api -from minecraft_manager.api.models import Token -import minecraft_manager.utils as mcm_utils import minecraft_manager.external.stats as mcm_stats +import minecraft_manager.forms as mcm_forms +import minecraft_manager.utils as mcm_utils +from minecraft_manager.api.models import Token +from minecraft_manager.models import Player, UserSettings, Application, IP, Ticket, Note logger = logging.getLogger(__name__) @@ -205,10 +206,11 @@ class PluginAPI(View): application.save() json['message'] = "Application was successfully {0}.".format( "accepted" if post['action'] == "True" else "denied") - mcm_api.discord_mcm("{0}'s application (#{1}) was {2} by {3}".format(application.username, + link = mcm_utils.full_reverse('application_info', application.id) + mcm_api.discord_mcm("{0}'s application ([#{1}]({4})) was {2} by {3}".format(application.username, application.id, "accepted" if post['action'] == "True" else "denied", - post['username'])) + post['username'], link)) mcm_api.plugin("accept" if post['action'] == "True" else "deny", application.username) else: json['status'] = False @@ -297,7 +299,7 @@ class PluginAPI(View): ticket = Ticket(player=player, message=post['message'], x=post['x'], y=post['y'], z=post['z'], world=post['world']) ticket.save() json['message'] = "Ticket submitted." - link = "{}".format(mcm_utils.url_path(settings.MCM_BASE_LINK, 'dashboard/ticket', ticket.id)) + link = mcm_utils.full_reverse('ticket_info', ticket.id) msg = mcm_utils.build_ticket(ticket, link) json['extra'] = {'id': ticket.id, 'link': link} mcm_api.discord_mcm(embed=msg, ping=True) @@ -311,7 +313,7 @@ class PluginAPI(View): warning = Note(player=player, message=post['message'], importance=post['severity'], staff=staff.auth_user) warning.save() json['message'] = "Warning issued." - link = "{}".format(mcm_utils.url_path(settings.MCM_BASE_LINK, 'dashboard/note', warning.id)) + link = mcm_utils.full_reverse('note_info', warning.id) msg = mcm_utils.build_warning(warning, link) mcm_api.discord_mcm(embed=msg) except Exception as ex: @@ -390,7 +392,7 @@ class ModelAPI(View): json = [] for value in objects: try: - link = "{}".format(mcm_utils.url_path(settings.MCM_BASE_LINK, 'dashboard', request_model, value['id'])) + link = mcm_utils.full_reverse(f"{request_model}_info", value['id']) value['link'] = link except: pass diff --git a/bot/commands.py b/bot/commands.py index dd7c2ec..28eb4f3 100644 --- a/bot/commands.py +++ b/bot/commands.py @@ -5,7 +5,7 @@ from django.db import close_old_connections from minecraft_manager.api import api from minecraft_manager.bot.utils import get_application -from minecraft_manager.utils import build_application +from minecraft_manager.utils import build_application, full_static from minecraft_manager.models import Application, Player @@ -44,8 +44,8 @@ class Commands(commands.Cog): async def help(self, ctx): embed = discord.Embed(colour=discord.Colour(0x417505)) embed.set_thumbnail( - url="https://cdn.discordapp.com/avatars/454457830918062081/b5792489bc43d9e17b8f657880a17dd4.png") - embed.add_field(name="Minecraft Manager Help", value="-----------------------------") + url=full_static('favicon.png')) + embed.title = "Minecraft Manager Help" embed.add_field(name="{}app search ".format(self.bot.prefix), value="Search for applications by partial or exact username.") embed.add_field(name="{}app info ".format(self.bot.prefix), diff --git a/bot/discord.py b/bot/discord.py index 2b57345..08de90d 100644 --- a/bot/discord.py +++ b/bot/discord.py @@ -7,7 +7,7 @@ from discord.ext import commands from django.conf import settings from minecraft_manager.models import Application, Ticket -from minecraft_manager.utils import url_path +from minecraft_manager.utils import full_reverse logger = logging.getLogger(__name__) @@ -46,11 +46,11 @@ class Discord(commands.Bot): content = "" unanswered_applications = Application.objects.filter(accepted=None) if len(unanswered_applications) > 0: - link = url_path(settings.MCM_BASE_LINK, 'dashboard/application') + link = full_reverse('application') content += "[Unanswered Applications: {}]({})".format(len(unanswered_applications), link) unclaimed_tickets = Ticket.objects.filter(staff=None, resolved=False) if len(unclaimed_tickets) > 0: - link = url_path(settings.MCM_BASE_LINK, 'dashboard/ticket') + link = full_reverse('ticket') if content: content += "\n\n" content += "[Unclaimed Tickets: {}]({})".format(len(unclaimed_tickets), link) diff --git a/external/views.py b/external/views.py index 6b5623a..1a657f6 100644 --- a/external/views.py +++ b/external/views.py @@ -1,5 +1,5 @@ from django.views.generic import View -from django.shortcuts import render +from django.shortcuts import render, reverse from django.conf import settings from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_exempt @@ -116,7 +116,7 @@ class Ticket(View): if valid and captcha.success: ticket = form.save() # Create the message to send to Discord - link = "{}".format(mcm_utils.url_path(settings.MCM_BASE_LINK, 'dashboard/ticket', ticket.id)) + link = mcm_utils.full_reverse('ticket_info', ticket.id) msg = mcm_utils.build_ticket(ticket, link) mcm_api.discord_mcm(message="New Ticket", embed=msg, ping=True) mcm_api.plugin("ticket", "{0} {1} {2}".format(username, ticket.id, link)) diff --git a/templates/minecraft_manager/application.html b/templates/minecraft_manager/application.html index 3509399..e60b729 100644 --- a/templates/minecraft_manager/application.html +++ b/templates/minecraft_manager/application.html @@ -34,7 +34,7 @@ {% endfor %} - Reference Report + Reference Report