mirror of
https://github.com/retspen/webvirtcloud
synced 2025-01-23 13:45:21 +00:00
logs view adds paging ability
settings.LOGS_PER_PAGE controls logs count per page
This commit is contained in:
parent
317c2a85ae
commit
6afcd00e2e
6 changed files with 35 additions and 7 deletions
12
logs/templates/paging.html
Normal file
12
logs/templates/paging.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
<center>
|
||||
{% if page > 1 %}
|
||||
<a href="{% url 'showlogspage' page|add:"-1" %}">←</a>
|
||||
{% else %}
|
||||
|
||||
{% endif %}
|
||||
{% if has_next_page %}
|
||||
<a href="{% url 'showlogspage' page|add:"1" %}">→</a>
|
||||
{% else %}
|
||||
|
||||
{% endif %}
|
||||
</center>
|
|
@ -22,31 +22,33 @@
|
|||
</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>
|
||||
<th>{% trans "Date" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for log in logs %}
|
||||
<tr>
|
||||
<td>{{ forloop.counter }}</td>
|
||||
<td>{{ log.id }}</td>
|
||||
<td style="width:130px;">{{ log.date|date:"M d H:i:s" }}</td>
|
||||
<td>{{ log.user }}</a></td>
|
||||
<td>{{ log.instance }}</a></td>
|
||||
<td>{{ log.message }}</td>
|
||||
<td style="width:130px;">{{ log.date|date:"M d H:i:s" }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% include "paging.html" %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
|
7
logs/urls.py
Normal file
7
logs/urls.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from django.conf.urls import url
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.showlogs, name='showlogs'),
|
||||
url(r'^(?P<page>[0-9]+)/$', views.showlogs, name='showlogspage'),
|
||||
]
|
|
@ -2,6 +2,7 @@ from django.shortcuts import render
|
|||
from django.http import HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse
|
||||
from logs.models import Logs
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
def addlogmsg(user, instance, message):
|
||||
|
@ -13,7 +14,7 @@ def addlogmsg(user, instance, message):
|
|||
add_log_msg.save()
|
||||
|
||||
|
||||
def showlogs(request):
|
||||
def showlogs(request, page=1):
|
||||
"""
|
||||
:param request:
|
||||
:return:
|
||||
|
@ -25,6 +26,11 @@ def showlogs(request):
|
|||
if not request.user.is_superuser:
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
|
||||
logs = Logs.objects.all()
|
||||
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())
|
||||
|
|
|
@ -114,3 +114,4 @@ LIBVIRT_KEEPALIVE_COUNT = 5
|
|||
|
||||
ALLOW_INSTANCE_MULTIPLE_OWNER = True
|
||||
CLONE_INSTANCE_DEFAULT_PREFIX = 'ourea'
|
||||
LOGS_PER_PAGE = 100
|
||||
|
|
|
@ -8,6 +8,7 @@ urlpatterns = patterns('',
|
|||
url(r'^instance/', include('instances.urls')),
|
||||
url(r'^accounts/', include('accounts.urls')),
|
||||
url(r'^computes/', include('computes.urls')),
|
||||
url(r'^logs/', include('logs.urls')),
|
||||
|
||||
url(r'^compute/(?P<compute_id>[0-9]+)/storages/$',
|
||||
'storages.views.storages', name='storages'),
|
||||
|
@ -27,6 +28,5 @@ urlpatterns = patterns('',
|
|||
'create.views.create_instance', name='create_instance'),
|
||||
|
||||
url(r'^console/$', 'console.views.console', name='console'),
|
||||
url(r'^logs/$', 'logs.views.showlogs', name='showlogs'),
|
||||
# (r'^admin/', include(admin.site.urls)),
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue