forked from Minecraft/minecraft_manager
Merge branch 'master' of https://git.etztech.xyz/Etzelia/MinecraftManagerDjango
commit
b1ac1a908b
22
api/bot.py
22
api/bot.py
|
@ -123,9 +123,6 @@ class Discord(discord.Client):
|
||||||
if match.group(1) and match.group(2):
|
if match.group(1) and match.group(2):
|
||||||
action = match.group(1)[:1]
|
action = match.group(1)[:1]
|
||||||
action_display = "accept" if action == "a" else "deny" if action == "d" else ""
|
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
|
application = None
|
||||||
try:
|
try:
|
||||||
application = Application.objects.get(id=match.group(2))
|
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)
|
match = re.match("[{0}](?:app )?(?:search|info) (\S+)?$".format(self.prefix), message.content)
|
||||||
if match:
|
if match:
|
||||||
search = match.group(1)
|
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]
|
applications = Application.objects.filter(username__icontains=search)[:10]
|
||||||
count = Application.objects.filter(username__icontains=search).count()
|
count = Application.objects.filter(username__icontains=search).count()
|
||||||
if count > 0:
|
if count > 0:
|
||||||
|
@ -162,7 +158,23 @@ class Discord(discord.Client):
|
||||||
for app in applications:
|
for app in applications:
|
||||||
info += "\n{0} - {1} ({2})".format(app.id, app.username.replace("_", "\\_"), app.status)
|
info += "\n{0} - {1} ({2})".format(app.id, app.username.replace("_", "\\_"), app.status)
|
||||||
if count > 10:
|
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:
|
||||||
|
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:
|
else:
|
||||||
info = "No applications matched that search."
|
info = "No applications matched that search."
|
||||||
yield from self.discord_message(message.channel, info)
|
yield from self.discord_message(message.channel, info)
|
||||||
|
|
|
@ -52,7 +52,8 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</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">
|
<table class="table table-striped table-hover link-table">
|
||||||
<h4>IPs</h4>
|
<h4>IPs</h4>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -79,13 +80,5 @@
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</div>
|
||||||
{% endblock section %}
|
{% endblock section %}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
{% extends "minecraft_manager/dashboard.html" %}
|
{% extends "minecraft_manager/dashboard.html" %}
|
||||||
{% load csrf_html %}
|
{% load csrf_html %}
|
||||||
|
{% load reverse_player %}
|
||||||
{% block title %}Ticket Info{% endblock %}
|
{% block title %}Ticket Info{% endblock %}
|
||||||
{% block section %}
|
{% block section %}
|
||||||
<div id="content">
|
<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="row">
|
||||||
<div class="col-xs-6 col-md-4">
|
<div class="col-xs-6 col-md-4">
|
||||||
<p>Message: </p>
|
<p>Message: </p>
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
{% extends "minecraft_manager/dashboard.html" %}
|
{% extends "minecraft_manager/dashboard.html" %}
|
||||||
{% load csrf_html %}
|
{% load csrf_html %}
|
||||||
|
{% load reverse_player %}
|
||||||
{% block title %}Warning Info{% endblock %}
|
{% block title %}Warning Info{% endblock %}
|
||||||
{% block section %}
|
{% block section %}
|
||||||
<div id="content">
|
<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="row">
|
||||||
<div class="col-xs-6 col-md-4">
|
<div class="col-xs-6 col-md-4">
|
||||||
<!-- <p>Username: {{ application.username }}</p> -->
|
<!-- <p>Username: {{ application.username }}</p> -->
|
||||||
|
|
|
@ -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))
|
18
views.py
18
views.py
|
@ -12,6 +12,7 @@ from django.utils.decorators import method_decorator
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.views.generic import View
|
from django.views.generic import View
|
||||||
from django.contrib.auth.models import User
|
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.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.forms import WarningForm, NoteForm
|
||||||
from minecraft_manager.overview import overview_data
|
from minecraft_manager.overview import overview_data
|
||||||
|
@ -199,11 +200,17 @@ class PlayerInfo(View):
|
||||||
tickets = TicketModel.objects.filter(player=player)
|
tickets = TicketModel.objects.filter(player=player)
|
||||||
warnings = WarningModel.objects.filter(player=player)
|
warnings = WarningModel.objects.filter(player=player)
|
||||||
form = {'ips': ips, 'tickets': tickets, 'warnings': warnings}
|
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):
|
def post(self, request, player_id):
|
||||||
player = PlayerModel.objects.get(id=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):
|
class Ticket(View):
|
||||||
|
@ -337,9 +344,12 @@ class WarningAdd(View):
|
||||||
|
|
||||||
@method_decorator(csrf_protect)
|
@method_decorator(csrf_protect)
|
||||||
def get(self, request):
|
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',
|
return render(request, 'minecraft_manager/warning_add.html',
|
||||||
{'current_app': 'warning', 'form': form})
|
{'current_app': 'warning', 'form': form.as_p()})
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
post = request.POST
|
post = request.POST
|
||||||
|
|
Loading…
Reference in New Issue