Joey Hines 2018-12-10 15:06:37 -06:00
commit b1ac1a908b
6 changed files with 59 additions and 21 deletions

View File

@ -123,9 +123,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))
@ -151,7 +148,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:
@ -162,9 +158,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, 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**")
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)

View File

@ -52,7 +52,8 @@
{% endif %}
</tbody>
</table>
<br/>
<a class="btn btn-primary" href="{% url 'warning_add' %}?player={{ player.id }}">Add Warning</a>
<br/><br/>
<table class="table table-striped table-hover link-table">
<h4>IPs</h4>
<tbody>
@ -79,13 +80,5 @@
</table>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-md-4">
</div>
<div class="col-xs-12 col-md-8">
</div>
</div>
</div>
{% endblock section %}

View File

@ -1,9 +1,10 @@
{% extends "minecraft_manager/dashboard.html" %}
{% load csrf_html %}
{% load reverse_player %}
{% block title %}Ticket Info{% endblock %}
{% block section %}
<div id="content">
<h2 class="sub-header">Ticket Info ({{ ticket.issuer }}) <span {% if ticket.resolved is True %}class="label label-success"{% else %}class="label label-danger"{% endif %}>{{ ticket.resolved_label }}</span></h2>
<h2 class="sub-header">Ticket Info ({% player_reverse_id ticket.player.id %}) <span {% if ticket.resolved is True %}class="label label-success"{% else %}class="label label-danger"{% endif %}>{{ ticket.resolved_label }}</span></h2>
<div class="row">
<div class="col-xs-6 col-md-4">
<p>Message: </p>

View File

@ -1,9 +1,10 @@
{% extends "minecraft_manager/dashboard.html" %}
{% load csrf_html %}
{% load reverse_player %}
{% block title %}Warning Info{% endblock %}
{% block section %}
<div id="content">
<h2 class="sub-header">Warning Info ({{ warning.player.username }})</h2>
<h2 class="sub-header">Warning Info ({% player_reverse_id warning.player.id %})</h2>
<div class="row">
<div class="col-xs-6 col-md-4">
<!-- <p>Username: {{ application.username }}</p> -->

View File

@ -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('<a href="{}">{}</a>'.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('<a href="{}">{}</a>'.format(url, player.username))

View File

@ -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