diff --git a/logs/templates/paging.html b/logs/templates/paging.html new file mode 100644 index 0000000..2cf8f48 --- /dev/null +++ b/logs/templates/paging.html @@ -0,0 +1,12 @@ +
+ {% if page > 1 %} + + {% else %} +   + {% endif %} + {% if has_next_page %} + + {% else %} +   + {% endif %} +
diff --git a/logs/templates/showlogs.html b/logs/templates/showlogs.html index 1aa98da..13d0e34 100644 --- a/logs/templates/showlogs.html +++ b/logs/templates/showlogs.html @@ -22,31 +22,33 @@ {% else %} + {% include "paging.html" %}
+ - {% for log in logs %} - + + - {% endfor %}
#{% trans "Date" %} {% trans "User" %} {% trans "Instance" %} {% trans "Message" %}{% trans "Date" %}
{{ forloop.counter }}{{ log.id }}{{ log.date|date:"M d H:i:s" }} {{ log.user }} {{ log.instance }} {{ log.message }}{{ log.date|date:"M d H:i:s" }}
+ {% include "paging.html" %} {% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/logs/urls.py b/logs/urls.py new file mode 100644 index 0000000..e579387 --- /dev/null +++ b/logs/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls import url +from . import views + +urlpatterns = [ + url(r'^$', views.showlogs, name='showlogs'), + url(r'^(?P[0-9]+)/$', views.showlogs, name='showlogspage'), +] diff --git a/logs/views.py b/logs/views.py index cb408ca..830925e 100644 --- a/logs/views.py +++ b/logs/views.py @@ -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()) diff --git a/webvirtcloud/settings.py b/webvirtcloud/settings.py index 2b70b02..9181cf6 100644 --- a/webvirtcloud/settings.py +++ b/webvirtcloud/settings.py @@ -114,3 +114,4 @@ LIBVIRT_KEEPALIVE_COUNT = 5 ALLOW_INSTANCE_MULTIPLE_OWNER = True CLONE_INSTANCE_DEFAULT_PREFIX = 'ourea' +LOGS_PER_PAGE = 100 diff --git a/webvirtcloud/urls.py b/webvirtcloud/urls.py index 2acb208..6cb32e7 100644 --- a/webvirtcloud/urls.py +++ b/webvirtcloud/urls.py @@ -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[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)), )