1
0
Fork 0
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:
Real-Gecko 2020-05-27 18:24:06 +06:00
parent 38befa4362
commit 27f62dff6c
38 changed files with 933 additions and 742 deletions

View file

@ -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">
<h1 class="page-header">{% trans "Logs" %}</h1>
</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">&times;</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>#</th>
<th>{% trans "Date" %}</th>
<th>{% trans "User" %}</th>
<th>{% trans "Instance" %}</th>
<th>{% 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 %}

View file

@ -2,7 +2,5 @@ from django.urls import path, re_path
from . import views
urlpatterns = [
path('', views.showlogs, name='showlogs'),
re_path(r'^(?P<page>[0-9]+)/$', views.showlogs, name='showlogspage'),
re_path(r'^vm_logs/(?P<vname>[\w\-\.]+)/$', views.vm_logs, name='vm_logs'),
]

View file

@ -1,10 +1,13 @@
from django.shortcuts import render
import json
from django.conf import settings
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from django.urls import reverse
from admin.decorators import superuser_only
from instances.models import Instance
from logs.models import Logs
from django.conf import settings
import json
def addlogmsg(user, instance, message):
@ -18,35 +21,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)
limit_from = (page-1)*settings.LOGS_PER_PAGE
limit_to = page*settings.LOGS_PER_PAGE
logs = Logs.objects.all().order_by('-date')[limit_from:limit_to+1]
has_next_page = logs.count() > settings.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')
@ -58,5 +39,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))