mirror of
https://github.com/retspen/webvirtcloud
synced 2025-07-31 12:41:08 +00:00
Added admin application
- Manage users - Manage groups - Manage logs
This commit is contained in:
parent
713d565a2d
commit
fec59b1dd7
37 changed files with 1106 additions and 517 deletions
|
|
@ -1,54 +0,0 @@
|
|||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Logs" %}{% endblock %}
|
||||
{% block content %}
|
||||
<!-- Page Heading -->
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<h2 class="page-header">{% trans "Logs" %}</h2>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.row -->
|
||||
|
||||
{% include 'errors_block.html' %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
{% if not logs %}
|
||||
<div class="col-lg-12">
|
||||
<div class="alert alert-warning alert-dismissable">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning" %}:</strong> {% trans "You don't have any Logs" %}
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
{% include "paging.html" %}
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">{% trans "Date" %}</th>
|
||||
<th scope="col">{% trans "User" %}</th>
|
||||
<th scope="col">{% trans "Instance" %}</th>
|
||||
<th scope="col">{% trans "Message" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for log in logs %}
|
||||
<tr>
|
||||
<td>{{ log.id }}</td>
|
||||
<td style="width:130px;">{{ log.date|date:"M d H:i:s" }}</td>
|
||||
<td>{{ log.user }}</td>
|
||||
<td>{{ log.instance }}</td>
|
||||
<td>{{ log.message }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% include "paging.html" %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -2,7 +2,5 @@ from django.urls import path, re_path
|
|||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.showlogs, name='showlogs'),
|
||||
path('<int:page>/', views.showlogs, name='showlogspage'),
|
||||
path('vm_logs/<vname>/', views.vm_logs, name='vm_logs'),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import json
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse
|
||||
from appsettings.models import AppSettings
|
||||
|
||||
from admin.decorators import superuser_only
|
||||
from instances.models import Instance
|
||||
from logs.models import Logs
|
||||
|
||||
|
|
@ -18,36 +19,13 @@ def addlogmsg(user, instance, message):
|
|||
add_log_msg.save()
|
||||
|
||||
|
||||
def showlogs(request, page=1):
|
||||
"""
|
||||
:param request:
|
||||
:param page:
|
||||
:return:
|
||||
"""
|
||||
|
||||
if not request.user.is_superuser:
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
|
||||
page = int(page)
|
||||
logs_per_page = int(AppSettings.objects.get(key="LOGS_PER_PAGE").value)
|
||||
limit_from = (page-1) * logs_per_page
|
||||
limit_to = page * logs_per_page
|
||||
logs = Logs.objects.all().order_by('-date')[limit_from:limit_to+1]
|
||||
has_next_page = logs.count() > logs_per_page
|
||||
# TODO: remove last element from queryset, but do not affect database
|
||||
|
||||
return render(request, 'showlogs.html', locals())
|
||||
|
||||
|
||||
@superuser_only
|
||||
def vm_logs(request, vname):
|
||||
"""
|
||||
:param request:
|
||||
:param vname:
|
||||
:return:
|
||||
"""
|
||||
|
||||
if not request.user.is_superuser:
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
|
||||
vm = Instance.objects.get(name=vname)
|
||||
logs_ = Logs.objects.filter(instance=vm.name, date__gte=vm.created).order_by('-date')
|
||||
|
|
@ -59,5 +37,5 @@ def vm_logs(request, vname):
|
|||
log['message'] = l.message
|
||||
log['date'] = l.date.strftime('%x %X')
|
||||
logs.append(log)
|
||||
|
||||
|
||||
return HttpResponse(json.dumps(logs))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue