From 489012c0162e3309431a8b1e2398fe57049826dd Mon Sep 17 00:00:00 2001 From: Etzelia Date: Sat, 8 Dec 2018 23:30:56 -0600 Subject: [PATCH 1/5] Various Fixes/Improvements Fixes #2 Added links to player profiles from tickets/warnings Increased app searches in Discord to also search players if no applications are found If the plugin needs to be able to run advanced searches, may need to update the Model API --- api/bot.py | 20 ++++++++++++++++-- templates/minecraft_manager/player_info.html | 11 ++-------- templates/minecraft_manager/ticket_info.html | 3 ++- templates/minecraft_manager/warning_info.html | 3 ++- templatetags/reverse_player.py | 21 +++++++++++++++++++ views.py | 18 ++++++++++++---- 6 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 templatetags/reverse_player.py diff --git a/api/bot.py b/api/bot.py index 9acde65..785a650 100644 --- a/api/bot.py +++ b/api/bot.py @@ -116,9 +116,25 @@ class Discord(discord.Client): for app in applications: info += "\n{0} - {1} ({2})".format(app.id, app.username.replace("_", "\\_"), app.status) if count > 10: - info += "\n**This is only 10 applications out of {0} found. Please narrow your search if possible.**".format(len(applications)) + info += "\n**This is only 10 applications out of {0} found. Please narrow your search if possible.**".format( + len(applications)) else: - info = "No applications matched that search." + players = Player.objects.filter(username__icontains=search)[:10] + count = Player.objects.filter(username__icontains=search).count() + if count > 0: + if count == 1: + yield from self.discord_message(message.channel, "No applications matched, however there is a player match.") + info = self.build_info(players[0].application) + else: + info = "No applications matched, however there are player matches." + for player in players: + app = player.application + info += "\n{0} - {1} AKA {2} ({3})".format(app.id, app.username.replace("_", "\\_"), player.username.replace("_", "\\_"), app.status) + if count > 10: + info += "\n**This is only 10 players out of {0} found. Please narrow your search if possible.**".format( + len(players)) + else: + info = "No applications matched that search." yield from self.discord_message(message.channel, info) # DEMOTE A PLAYER TO MEMBER match = re.match("[{0}]demote (\w+)$".format(self.prefix), message.content) diff --git a/templates/minecraft_manager/player_info.html b/templates/minecraft_manager/player_info.html index 0569b20..318453e 100644 --- a/templates/minecraft_manager/player_info.html +++ b/templates/minecraft_manager/player_info.html @@ -52,7 +52,8 @@ {% endif %} -
+ Add Warning +

IPs

@@ -79,13 +80,5 @@ -
-
- -
-
- -
-
{% endblock section %} diff --git a/templates/minecraft_manager/ticket_info.html b/templates/minecraft_manager/ticket_info.html index 0f338a4..17ea83f 100644 --- a/templates/minecraft_manager/ticket_info.html +++ b/templates/minecraft_manager/ticket_info.html @@ -1,9 +1,10 @@ {% extends "minecraft_manager/dashboard.html" %} {% load csrf_html %} +{% load reverse_player %} {% block title %}Ticket Info{% endblock %} {% block section %}
-

Ticket Info ({{ ticket.issuer }}) {{ ticket.resolved_label }}

+

Ticket Info ({% player_reverse_id ticket.player.id %}) {{ ticket.resolved_label }}

Message:

diff --git a/templates/minecraft_manager/warning_info.html b/templates/minecraft_manager/warning_info.html index ed9c99d..742004b 100644 --- a/templates/minecraft_manager/warning_info.html +++ b/templates/minecraft_manager/warning_info.html @@ -1,9 +1,10 @@ {% extends "minecraft_manager/dashboard.html" %} {% load csrf_html %} +{% load reverse_player %} {% block title %}Warning Info{% endblock %} {% block section %}
-

Warning Info ({{ warning.player.username }})

+

Warning Info ({% player_reverse_id warning.player.id %})

diff --git a/templatetags/reverse_player.py b/templatetags/reverse_player.py new file mode 100644 index 0000000..b4f9cf1 --- /dev/null +++ b/templatetags/reverse_player.py @@ -0,0 +1,21 @@ +from django.template import Library + +from minecraft_manager.models import Player +from django.urls import reverse +from django.utils.html import mark_safe + +register = Library() + + +@register.simple_tag(name="player_reverse_name") +def reverse_name(username): + player = Player.objects.get(username=username) + url = "{}{}".format(reverse('player'), player.id) + return mark_safe('{}'.format(url, player.username)) + + +@register.simple_tag(name="player_reverse_id") +def reverse_id(player_id): + player = Player.objects.get(id=player_id) + url = "{}{}".format(reverse('player'), player.id) + return mark_safe('{}'.format(url, player.username)) diff --git a/views.py b/views.py index 46be592..e04b457 100644 --- a/views.py +++ b/views.py @@ -12,6 +12,7 @@ from django.utils.decorators import method_decorator from django.conf import settings from django.views.generic import View from django.contrib.auth.models import User +from django.forms.widgets import HiddenInput from minecraft_manager.models import Application as AppModel, Player as PlayerModel, Ticket as TicketModel, Warning as WarningModel, IP as IPModel, Alert as AlertModel, Note as NoteModel, UserSettings as UserSettingsModel from minecraft_manager.forms import WarningForm, NoteForm from minecraft_manager.overview import overview_data @@ -199,11 +200,17 @@ class PlayerInfo(View): tickets = TicketModel.objects.filter(player=player) warnings = WarningModel.objects.filter(player=player) form = {'ips': ips, 'tickets': tickets, 'warnings': warnings} - return render(request, 'minecraft_manager/player_info.html', {'current_app': 'player', 'player': player, 'form': form}) + return render(request, 'minecraft_manager/player_info.html', + {'current_app': 'player', 'player': player, 'form': form}) def post(self, request, player_id): player = PlayerModel.objects.get(id=player_id) - return render(request, 'minecraft_manager/player_info.html', {'current_app': 'player', 'player': player}) + ips = IPModel.api.filter(player=player) + tickets = TicketModel.objects.filter(player=player) + warnings = WarningModel.objects.filter(player=player) + form = {'ips': ips, 'tickets': tickets, 'warnings': warnings} + return render(request, 'minecraft_manager/player_info.html', + {'current_app': 'player', 'player': player, 'form': form}) class Ticket(View): @@ -337,9 +344,12 @@ class WarningAdd(View): @method_decorator(csrf_protect) def get(self, request): - form = WarningForm().as_p() + get = request.GET + form = WarningForm() + if 'player' in get: + form.initial = {'player': get['player']} return render(request, 'minecraft_manager/warning_add.html', - {'current_app': 'warning', 'form': form}) + {'current_app': 'warning', 'form': form.as_p()}) def post(self, request): post = request.POST From b91078a4a7dd2ac5f519ad0275fa06afd46ac7ea Mon Sep 17 00:00:00 2001 From: Etzelia Date: Sat, 8 Dec 2018 23:35:29 -0600 Subject: [PATCH 2/5] Only query players with a valid application in the bot --- api/bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/bot.py b/api/bot.py index 785a650..e3c5794 100644 --- a/api/bot.py +++ b/api/bot.py @@ -119,8 +119,8 @@ class Discord(discord.Client): info += "\n**This is only 10 applications out of {0} found. Please narrow your search if possible.**".format( len(applications)) else: - players = Player.objects.filter(username__icontains=search)[:10] - count = Player.objects.filter(username__icontains=search).count() + players = Player.objects.filter(username__icontains=search, application__isnull=False)[:10] + count = Player.objects.filter(username__icontains=search, application__isnull=False).count() if count > 0: if count == 1: yield from self.discord_message(message.channel, "No applications matched, however there is a player match.") From 111aa9eaa346ee0c67f5d94251b2c7f00ff6997a Mon Sep 17 00:00:00 2001 From: Etzelia Date: Sat, 8 Dec 2018 23:38:30 -0600 Subject: [PATCH 3/5] Formatting consistency --- api/bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/bot.py b/api/bot.py index e3c5794..b897e89 100644 --- a/api/bot.py +++ b/api/bot.py @@ -123,10 +123,10 @@ class Discord(discord.Client): count = Player.objects.filter(username__icontains=search, application__isnull=False).count() if count > 0: if count == 1: - yield from self.discord_message(message.channel, "No applications matched, however there is a player match.") + yield from self.discord_message(message.channel, "**No applications matched, however there is a player match**") info = self.build_info(players[0].application) else: - info = "No applications matched, however there are player matches." + info = "**No applications matched, however there are player matches**" for player in players: app = player.application info += "\n{0} - {1} AKA {2} ({3})".format(app.id, app.username.replace("_", "\\_"), player.username.replace("_", "\\_"), app.status) From 007b4d9319b2bacba8d1ca99246ab044e1f18a6e Mon Sep 17 00:00:00 2001 From: Etzelia Date: Sat, 8 Dec 2018 23:40:08 -0600 Subject: [PATCH 4/5] Remove "searching for..." message as results are returned too quickly to matter. --- api/bot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/api/bot.py b/api/bot.py index b897e89..a9d7278 100644 --- a/api/bot.py +++ b/api/bot.py @@ -105,7 +105,6 @@ class Discord(discord.Client): match = re.match("[{0}](?:app )?(?:search|info) (\S+)?$".format(self.prefix), message.content) if match: search = match.group(1) - yield from self.discord_message(message.channel, "Searching for applications whose username contains '{0}'".format(search)) applications = Application.objects.filter(username__icontains=search)[:10] count = Application.objects.filter(username__icontains=search).count() if count > 0: From 80f2ad6de8973d2ebab8b9284eaab744044ff5ef Mon Sep 17 00:00:00 2001 From: Etzelia Date: Mon, 10 Dec 2018 21:43:54 +0100 Subject: [PATCH 5/5] Remove pre-retrieve status message from MCM bot actions The results are fast enough that a status message is just spam. --- api/bot.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/api/bot.py b/api/bot.py index a9d7278..b9825ce 100644 --- a/api/bot.py +++ b/api/bot.py @@ -77,9 +77,6 @@ class Discord(discord.Client): if match.group(1) and match.group(2): action = match.group(1)[:1] action_display = "accept" if action == "a" else "deny" if action == "d" else "" - yield from self.discord_message(message.channel, "{0} App ID **{1}**".format( - "Retrieving info for" if action == "i" else "{0}ing".format(action_display.capitalize()), - match.group(2))) application = None try: application = Application.objects.get(id=match.group(2))