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