2015-03-03 09:34:09 +00:00
|
|
|
from django.shortcuts import render
|
|
|
|
from django.http import HttpResponseRedirect
|
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from logs.models import Logs
|
2016-03-23 09:38:33 +00:00
|
|
|
from django.conf import settings
|
2015-03-03 09:34:09 +00:00
|
|
|
|
|
|
|
|
2015-05-18 19:00:30 +00:00
|
|
|
def addlogmsg(user, instance, message):
|
2015-03-18 13:48:29 +00:00
|
|
|
"""
|
|
|
|
:param request:
|
|
|
|
:return:
|
|
|
|
"""
|
2015-05-18 19:00:30 +00:00
|
|
|
add_log_msg = Logs(user=user, instance=instance, message=message)
|
2015-03-18 13:48:29 +00:00
|
|
|
add_log_msg.save()
|
|
|
|
|
|
|
|
|
2016-03-23 09:38:33 +00:00
|
|
|
def showlogs(request, page=1):
|
2015-03-16 13:46:44 +00:00
|
|
|
"""
|
|
|
|
:param request:
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
|
|
|
|
if not request.user.is_authenticated():
|
|
|
|
return HttpResponseRedirect(reverse('index'))
|
|
|
|
|
|
|
|
if not request.user.is_superuser:
|
|
|
|
return HttpResponseRedirect(reverse('index'))
|
|
|
|
|
2016-03-23 09:38:33 +00:00
|
|
|
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
|
2015-03-16 13:46:44 +00:00
|
|
|
|
2015-04-02 13:20:46 +00:00
|
|
|
return render(request, 'showlogs.html', locals())
|