forked from Minecraft/minecraft_manager
Cleanup
Added resolve_application and resolve_player utilities, need to update usage as needed Replaced Search Player back-end logic with resolve_playerreminder
parent
229bfffb58
commit
8b69c72d5a
|
@ -1,10 +1,9 @@
|
||||||
import discord, logging, re, sys, traceback, asyncio, datetime, os, time
|
import discord, logging, re, sys, traceback, asyncio
|
||||||
from minecraft_manager.models import Application, Player
|
from minecraft_manager.models import Application, Player
|
||||||
from minecraft_manager.api import api
|
from minecraft_manager.api import api
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import close_old_connections
|
from django.db import close_old_connections
|
||||||
from threading import Thread
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
|
@ -18,12 +18,6 @@
|
||||||
<nav class="navbar navbar-inverse">
|
<nav class="navbar navbar-inverse">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="navbar-header">
|
<div class="navbar-header">
|
||||||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
|
|
||||||
<span class="sr-only">Toggle navigation</span>
|
|
||||||
<span class="icon-bar"></span>
|
|
||||||
<span class="icon-bar"></span>
|
|
||||||
<span class="icon-bar"></span>
|
|
||||||
</button>
|
|
||||||
{% template_settings 'DASHBOARD_TITLE' as DASHBOARD_TITLE %}
|
{% template_settings 'DASHBOARD_TITLE' as DASHBOARD_TITLE %}
|
||||||
<a class="navbar-brand" style="color:inherit;cursor:default;">{% if DASHBOARD_TITLE %}{{ DASHBOARD_TITLE }}{% else %}Minecraft Manager{% endif %}</a>
|
<a class="navbar-brand" style="color:inherit;cursor:default;">{% if DASHBOARD_TITLE %}{{ DASHBOARD_TITLE }}{% else %}Minecraft Manager{% endif %}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
{% if form.notes %}
|
{% if form.notes %}
|
||||||
{% for note in form.notes %}
|
{% for note in form.notes %}
|
||||||
<tr {% if note.importance == 'L' %}class="info"{% endif %}{% if note.importance == 'M' %}class="note"{% endif %}{% if note.importance == 'H' %}class="danger"{% endif %} data-id="{{ note.id }}" data-url="{% url "note" %}">
|
<tr {% if note.importance == 'L' %}class="info"{% endif %}{% if note.importance == 'M' %}class="warning"{% endif %}{% if note.importance == 'H' %}class="danger"{% endif %} data-id="{{ note.id }}" data-url="{% url "note" %}">
|
||||||
<!-- {{ note.id }} -->
|
<!-- {{ note.id }} -->
|
||||||
<td>{{ note.snippet }}</td>
|
<td>{{ note.snippet }}</td>
|
||||||
<td>{{ note.importance_display }}</td>
|
<td>{{ note.importance_display }}</td>
|
||||||
|
|
|
@ -16,7 +16,6 @@ def get_sidebar(current_app, request):
|
||||||
unseen_html = " <span class='badge badge-light'>" + str(len(unseen_alerts)) + "</span>"
|
unseen_html = " <span class='badge badge-light'>" + str(len(unseen_alerts)) + "</span>"
|
||||||
|
|
||||||
ret = '<li {}><a href="{}"><span class="glyphicon glyphicon-home"></span> Overview</a></li>'.format('class="active"' if current_app == 'overview' else "", reverse('overview'))
|
ret = '<li {}><a href="{}"><span class="glyphicon glyphicon-home"></span> Overview</a></li>'.format('class="active"' if current_app == 'overview' else "", reverse('overview'))
|
||||||
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-ban-circle"></span> Bans</a></li>'.format('class="active"' if current_app == 'ban' else '', reverse('ban'))
|
|
||||||
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-bell"></span> Alerts{}</a></li>'.format('class="active"' if current_app == 'alert' else '', reverse('alert'), unseen_html)
|
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-bell"></span> Alerts{}</a></li>'.format('class="active"' if current_app == 'alert' else '', reverse('alert'), unseen_html)
|
||||||
|
|
||||||
# Models
|
# Models
|
||||||
|
@ -28,6 +27,7 @@ def get_sidebar(current_app, request):
|
||||||
# Split up MCM and "other"
|
# Split up MCM and "other"
|
||||||
ret += "<hr/>"
|
ret += "<hr/>"
|
||||||
|
|
||||||
|
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-ban-circle"></span> Bans</a></li>'.format('class="active"' if current_app == 'ban' else '', reverse('ban'))
|
||||||
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-wrench"></span> Report</a></li>'.format('class="active"' if current_app == 'report' else '', reverse('report'))
|
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-wrench"></span> Report</a></li>'.format('class="active"' if current_app == 'report' else '', reverse('report'))
|
||||||
|
|
||||||
show_chat = True if getattr(settings, 'GLOBAL_LOG', None) is not None else False
|
show_chat = True if getattr(settings, 'GLOBAL_LOG', None) is not None else False
|
||||||
|
|
20
utils.py
20
utils.py
|
@ -1,5 +1,25 @@
|
||||||
import discord, requests
|
import discord, requests
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from minecraft_manager.models import Player, Application
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_player(username):
|
||||||
|
if Player.objects.filter(username__iexact=username).exists():
|
||||||
|
return Player.objects.get(username__iexact=username)
|
||||||
|
if Application.objects.filter(username__iexact=username).exists():
|
||||||
|
application = Application.objects.get(username__iexact=username)
|
||||||
|
if Player.objects.filter(application=application).exists():
|
||||||
|
return Player.objects.get(application=application)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_application(username):
|
||||||
|
if Application.objects.filter(username__iexact=username).exists():
|
||||||
|
return Application.objects.get(username__iexact=username)
|
||||||
|
if Player.objects.filter(username__iexact=username, application__isnull=False).exists():
|
||||||
|
player = Player.objects.get(username__iexact=username)
|
||||||
|
return player.application
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def build_application(application):
|
def build_application(application):
|
||||||
|
|
13
views.py
13
views.py
|
@ -12,10 +12,10 @@ 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, TicketNote as TicketNoteModel, Note as NoteModel, IP as IPModel, Alert as AlertModel, UserSettings as UserSettingsModel
|
from minecraft_manager.models import Application as AppModel, Player as PlayerModel, Ticket as TicketModel, TicketNote as TicketNoteModel, Note as NoteModel, IP as IPModel, Alert as AlertModel, UserSettings as UserSettingsModel
|
||||||
from minecraft_manager.forms import TicketNoteForm, NoteForm
|
from minecraft_manager.forms import TicketNoteForm, NoteForm
|
||||||
from minecraft_manager.overview import overview_data
|
from minecraft_manager.overview import overview_data
|
||||||
|
from minecraft_manager.utils import resolve_player
|
||||||
import minecraft_manager.api.api as API
|
import minecraft_manager.api.api as API
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -173,14 +173,11 @@ class Player(View):
|
||||||
get = request.GET
|
get = request.GET
|
||||||
if 'search' in get:
|
if 'search' in get:
|
||||||
search = get['search']
|
search = get['search']
|
||||||
results = PlayerModel.objects.filter(username__icontains=search)
|
player = resolve_player(search)
|
||||||
if len(results) == 1:
|
if player:
|
||||||
return redirect('{}{}/'.format(reverse('player'), results[0].id))
|
return redirect('{}{}/'.format(reverse('player'), player.id))
|
||||||
else:
|
else:
|
||||||
for result in results:
|
players = PlayerModel.objects.filter(username__icontains=search)
|
||||||
if search.lower() == result.username.lower():
|
|
||||||
return redirect('{}{}/'.format(reverse('player'), result.id))
|
|
||||||
players = results
|
|
||||||
else:
|
else:
|
||||||
players = PlayerModel.objects.all()
|
players = PlayerModel.objects.all()
|
||||||
ban_file = os.path.join(settings.MINECRAFT_BASE_DIR, 'banned-players.json')
|
ban_file = os.path.join(settings.MINECRAFT_BASE_DIR, 'banned-players.json')
|
||||||
|
|
Loading…
Reference in New Issue