39 lines
2.6 KiB
Python
39 lines
2.6 KiB
Python
from django.template import Library
|
|
from django.urls import reverse
|
|
from minecraft_manager.models import Alert
|
|
from django.conf import settings
|
|
|
|
register = Library()
|
|
|
|
|
|
@register.simple_tag
|
|
def get_sidebar(current_app, request):
|
|
|
|
# Get unseen Alerts
|
|
unseen_alerts = Alert.objects.filter(user=request.user, seen=False)
|
|
unseen_html = ""
|
|
if len(unseen_alerts) > 0:
|
|
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-ban-circle"></span> Bans</a></li>'.format('class="active"' if current_app == 'ban' else '', reverse('ban'))
|
|
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-inbox"></span> Alerts{}</a></li>'.format('class="active"' if current_app == 'alert' else '', reverse('alert'), unseen_html)
|
|
|
|
# Models
|
|
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-file"></span> Applications</a></li>'.format('class="active"' if current_app == 'application' else '', reverse('application'))
|
|
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-user"></span> Players</a></li>'.format('class="active"' if current_app == 'player' else '', reverse('player'))
|
|
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-tags"></span> Tickets</a></li>'.format('class="active"' if current_app == 'ticket' else '', reverse('ticket'))
|
|
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-warning-sign"></span> Warnings</a></li>'.format('class="active"' if current_app == 'warning' else '', reverse('warning'))
|
|
|
|
# Split up MCM and "other"
|
|
ret += "<hr/>"
|
|
|
|
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
|
|
if show_chat and request.user.has_perm('auth.chat'):
|
|
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-comment"></span> Chat</a></li>'.format('class="active"' if current_app == 'chat' else '', reverse('chat'))
|
|
if request.user.has_perm('auth.bots'):
|
|
ret += '<li {}><a href="{}"><span class="glyphicon glyphicon-flash"></span> Bots</a></li>'.format('class="active"' if current_app == 'bots' else '', reverse('bots'))
|
|
return ret
|