1
0
Fork 0
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:
Jan Krcmar 2016-03-23 10:38:33 +01:00
parent 317c2a85ae
commit 6afcd00e2e
6 changed files with 35 additions and 7 deletions

View file

@ -0,0 +1,12 @@
<center>
{% if page > 1 %}
<a href="{% url 'showlogspage' page|add:"-1" %}">&larr;</a>
{% else %}
&nbsp;
{% endif %}
{% if has_next_page %}
<a href="{% url 'showlogspage' page|add:"1" %}">&rarr;</a>
{% else %}
&nbsp;
{% endif %}
</center>

View file

@ -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
View 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'),
]

View file

@ -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())

View file

@ -114,3 +114,4 @@ LIBVIRT_KEEPALIVE_COUNT = 5
ALLOW_INSTANCE_MULTIPLE_OWNER = True
CLONE_INSTANCE_DEFAULT_PREFIX = 'ourea'
LOGS_PER_PAGE = 100

View file

@ -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)),
)