mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-15 07:20:17 +02:00
Admin status panel for dashboard (#903)
This commit is contained in:
parent
7fa45fa471
commit
57a26b90cb
@ -6,6 +6,9 @@
|
||||
|
||||
{% block content %}
|
||||
<h1 class="page-header text-center">{% trans "Dashboard" %}</h1>
|
||||
{% if user.is_staff %}
|
||||
{% include 'allianceauth/admin-status/include.html' %}
|
||||
{% endif %}
|
||||
<div class="col-sm-12">
|
||||
<div class="row vertical-flexbox-row">
|
||||
<div class="col-sm-6 text-center">
|
||||
|
@ -27,3 +27,18 @@
|
||||
#site-body-wrapper {
|
||||
margin-right:0;
|
||||
}
|
||||
|
||||
/* Horizontal list group */
|
||||
ul.list-group.list-group-horizontal {
|
||||
display: table;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
ul.list-group.list-group-horizontal > li.list-group-item {
|
||||
display: table-cell;
|
||||
max-width: 0;
|
||||
}
|
||||
|
||||
.flex-center-horizontal {
|
||||
justify-content: center;
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,3 @@
|
||||
{% load admin_status %}
|
||||
|
||||
{% status_overview %}
|
100
allianceauth/templates/allianceauth/admin-status/overview.html
Normal file
100
allianceauth/templates/allianceauth/admin-status/overview.html
Normal file
@ -0,0 +1,100 @@
|
||||
{% load i18n %}
|
||||
<div class="col-sm-12">
|
||||
<div class="row vertical-flexbox-row">
|
||||
<div class="col-sm-6">
|
||||
<div class="panel panel-primary" style="height:100%;position:relative;">
|
||||
<div class="panel-heading text-center"><h3 class="panel-title">{% trans "Alliance Auth Notifications" %}</h3></div>
|
||||
<div class="panel-body">
|
||||
<ul class="list-group">
|
||||
{% for notif in notifications %}
|
||||
<li class="list-group-item">
|
||||
{% if notif.state == 'open' %}
|
||||
<span class="label label-success">{% trans "Open" %}</span>
|
||||
{% else %}
|
||||
<span class="label label-danger">{% trans "Closed" %}</span>
|
||||
{% endif %}
|
||||
<a href="{{ notif.html_url }}" target="_blank">#{{ notif.number }} {{ notif.title }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="text-right" style="position:absolute;bottom:5px;right:5px;">
|
||||
<a href="https://github.com/allianceauth/allianceauth/issues"><span class="label label-default">
|
||||
<i class="fa fa-github" aria-hidden="true"></i> Powered by Github</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="panel panel-primary" style="height:50%;">
|
||||
<div class="panel-heading text-center"><h3 class="panel-title">{% trans "Software Version" %}</h3></div>
|
||||
<div class="panel-body flex-center-horizontal">
|
||||
<ul class="list-group list-group-horizontal" style="margin-bottom: 0;">
|
||||
<li class="list-group-item">
|
||||
<h4 class="list-group-item-heading">{% trans "Current" %}</h4>
|
||||
<p class="list-group-item-text">
|
||||
{{ current_version }}
|
||||
</p>
|
||||
</li>
|
||||
<li class="list-group-item list-group-item-{% if latest_major %}success{% else %}warning{% endif %}">
|
||||
<h4 class="list-group-item-heading">{% trans "Latest Major" %}</h4>
|
||||
<p class="list-group-item-text">
|
||||
<a href="{{ latest_major_url }}" style="color:#000"><i class="fa fa-github" aria-hidden="true"></i>
|
||||
{{ latest_major_version }}
|
||||
</a>
|
||||
{% if not latest_major %}<br>{% trans "Update available" %}{% endif %}
|
||||
</p>
|
||||
</li>
|
||||
<li class="list-group-item list-group-item-{% if latest_minor %}success{% else %}warning{% endif %}">
|
||||
<h4 class="list-group-item-heading">{% trans "Latest Minor" %}</h4>
|
||||
<p class="list-group-item-text">
|
||||
<a href="{{ latest_minor_url }}" style="color:#000"><i class="fa fa-github" aria-hidden="true"></i>
|
||||
{{ latest_minor_version }}
|
||||
</a>
|
||||
{% if not latest_minor %}<br>{% trans "Update available" %}{% endif %}
|
||||
</p>
|
||||
</li>
|
||||
<li class="list-group-item list-group-item-{% if latest_patch %}success{% else %}danger{% endif %}">
|
||||
<h4 class="list-group-item-heading">{% trans "Latest Patch" %}</h4>
|
||||
<p class="list-group-item-text">
|
||||
<a href="{{ latest_patch_url }}" style="color:#000"><i class="fa fa-github" aria-hidden="true"></i>
|
||||
{{ latest_patch_version }}
|
||||
</a>
|
||||
{% if not latest_patch %}<br>{% trans "Update available" %}{% endif %}
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-primary" style="height:50%;">
|
||||
<div class="panel-heading text-center"><h3 class="panel-title">{% trans "Task Queue" %}</h3></div>
|
||||
<div class="panel-body flex-center-horizontal">
|
||||
<div class="progress" style="height: 21px;">
|
||||
<div class="progress-bar
|
||||
{% if task_queue_length > 500 %}
|
||||
progress-bar-danger
|
||||
{% elif task_queue_length > 100 %}
|
||||
progress-bar-warning
|
||||
{% else %}
|
||||
progress-bar-success
|
||||
{% endif %}
|
||||
" role="progressbar" aria-valuenow="{% widthratio task_queue_length 500 100 %}"
|
||||
aria-valuemin="0" aria-valuemax="100"
|
||||
style="width: {% widthratio task_queue_length 500 100 %}%;">
|
||||
</div>
|
||||
</div>
|
||||
{% if task_queue_length < 0 %}
|
||||
{% trans "Error retrieving task queue length" %}
|
||||
{% else %}
|
||||
{% blocktrans count tasks=task_queue_length %}
|
||||
{{ tasks }} task
|
||||
{% plural %}
|
||||
{{ tasks }} tasks
|
||||
{% endblocktrans %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
0
allianceauth/templatetags/__init__.py
Normal file
0
allianceauth/templatetags/__init__.py
Normal file
130
allianceauth/templatetags/admin_status.py
Normal file
130
allianceauth/templatetags/admin_status.py
Normal file
@ -0,0 +1,130 @@
|
||||
import requests
|
||||
import logging
|
||||
import semantic_version as semver
|
||||
from django import template
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from celery.app import app_or_default
|
||||
from allianceauth import __version__
|
||||
|
||||
register = template.Library()
|
||||
|
||||
TAG_CACHE_TIME = 10800 # 3 hours
|
||||
NOTIFICATION_CACHE_TIME = 300 # 5 minutes
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_github_tags():
|
||||
request = requests.get('https://api.github.com/repos/allianceauth/allianceauth/releases')
|
||||
request.raise_for_status()
|
||||
return request.json()
|
||||
|
||||
|
||||
def get_github_notification_issues():
|
||||
# notification
|
||||
request = requests.get(
|
||||
'https://api.github.com/repos/allianceauth/allianceauth/issues?labels=announcement&state=all')
|
||||
request.raise_for_status()
|
||||
return request.json()
|
||||
|
||||
|
||||
@register.inclusion_tag('allianceauth/admin-status/overview.html', takes_context=True)
|
||||
def status_overview(context):
|
||||
response = {
|
||||
'notifications': list(),
|
||||
'latest_major': True,
|
||||
'latest_minor': True,
|
||||
'latest_patch': True,
|
||||
'current_version': __version__,
|
||||
'task_queue_length': -1,
|
||||
}
|
||||
|
||||
response.update(get_notifications())
|
||||
response.update(get_version_info())
|
||||
response.update({'task_queue_length': get_celery_queue_length()})
|
||||
|
||||
return response
|
||||
|
||||
|
||||
def get_celery_queue_length():
|
||||
try:
|
||||
app = app_or_default(None)
|
||||
with app.connection_or_acquire() as conn:
|
||||
return conn.default_channel.queue_declare(
|
||||
queue=getattr(settings, 'CELERY_DEFAULT_QUEUE', 'celery'), passive=True).message_count
|
||||
except Exception:
|
||||
logger.exception("Failed to get celery queue length")
|
||||
return -1
|
||||
|
||||
|
||||
def get_notifications():
|
||||
response = {
|
||||
'notifications': list(),
|
||||
}
|
||||
try:
|
||||
notifications = cache.get_or_set('github_notification_issues', get_github_notification_issues,
|
||||
NOTIFICATION_CACHE_TIME)
|
||||
# Limit notifications to those posted by repo owners and members
|
||||
response['notifications'] += [n for n in notifications if n['author_association'] in ['OWNER', 'MEMBER']][:5]
|
||||
except requests.RequestException:
|
||||
logger.exception('Error while getting github notifications')
|
||||
return response
|
||||
|
||||
|
||||
def get_version_info():
|
||||
response = {
|
||||
'latest_major': True,
|
||||
'latest_minor': True,
|
||||
'latest_patch': True,
|
||||
'current_version': __version__,
|
||||
}
|
||||
try:
|
||||
tags = cache.get_or_set('github_release_tags', get_github_tags, TAG_CACHE_TIME)
|
||||
current_ver = semver.Version(__version__, partial=True)
|
||||
|
||||
# Set them all to the current version to start
|
||||
# If the server has only earlier or the same version
|
||||
# then this will become the major/minor/patch versions
|
||||
latest_major = current_ver
|
||||
latest_minor = current_ver
|
||||
latest_patch = current_ver
|
||||
|
||||
response.update({
|
||||
'latest_major_version': str(latest_major),
|
||||
'latest_minor_version': str(latest_minor),
|
||||
'latest_patch_version': str(latest_patch),
|
||||
})
|
||||
|
||||
for tag in tags:
|
||||
tag_name = tag.get('tag_name')
|
||||
if tag_name[0] == 'v':
|
||||
# Strip 'v' off front of verison if it exists
|
||||
tag_name = tag_name[1:]
|
||||
tag_ver = semver.Version(tag_name, partial=True)
|
||||
if tag_ver > current_ver:
|
||||
if latest_major is None or tag_ver > latest_major:
|
||||
latest_major = tag_ver
|
||||
response['latest_major_version'] = tag_name
|
||||
response['latest_major_url'] = tag['html_url']
|
||||
if tag_ver.major > current_ver.major:
|
||||
response['latest_major'] = False
|
||||
elif tag_ver.major == current_ver.major:
|
||||
if latest_minor is None or tag_ver > latest_minor:
|
||||
latest_minor = tag_ver
|
||||
response['latest_minor_version'] = tag_name
|
||||
response['latest_minor_url'] = tag['html_url']
|
||||
if tag_ver.minor > current_ver.minor:
|
||||
response['latest_minor'] = False
|
||||
elif tag_ver.minor == current_ver.minor:
|
||||
if latest_patch is None or tag_ver > latest_patch:
|
||||
latest_patch = tag_ver
|
||||
response['latest_patch_version'] = tag_name
|
||||
response['latest_patch_url'] = tag['html_url']
|
||||
if tag_ver.patch > current_ver.patch:
|
||||
response['latest_patch'] = False
|
||||
|
||||
except requests.RequestException:
|
||||
logger.exception('Error while getting github release tags')
|
||||
return response
|
Loading…
x
Reference in New Issue
Block a user