1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2024-11-30 12:13:03 +00:00
med/logs/views.py

52 lines
1.7 KiB
Python
Raw Normal View History

2019-08-02 12:57:53 +00:00
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
2017-07-04 00:21:31 +00:00
2019-08-08 17:16:54 +00:00
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.decorators import login_required
2019-08-02 12:57:53 +00:00
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
2017-07-04 00:21:31 +00:00
from django.db.models import Count
2019-08-08 14:18:15 +00:00
from django.shortcuts import render
2019-08-02 12:57:53 +00:00
from django.template.context_processors import csrf
2017-07-04 00:21:31 +00:00
from reversion.models import Revision
2019-08-09 21:22:20 +00:00
from med.settings import PAGINATION_NUMBER
2019-08-02 12:57:53 +00:00
from users.models import User
2017-07-04 00:21:31 +00:00
def form(ctx, template, request):
c = ctx
c.update(csrf(request))
return render(request, template, c)
2019-08-02 12:57:53 +00:00
2017-07-04 00:21:31 +00:00
@login_required
2019-08-08 17:16:54 +00:00
@staff_member_required
2017-07-04 00:21:31 +00:00
def index(request):
2019-08-08 14:18:15 +00:00
revisions = Revision.objects.all().order_by(
'date_created').reverse().select_related('user').prefetch_related(
2019-08-02 12:57:53 +00:00
'version_set__object')
2019-08-09 21:22:20 +00:00
paginator = Paginator(revisions, PAGINATION_NUMBER)
2017-07-04 00:21:31 +00:00
page = request.GET.get('page')
try:
revisions = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
revisions = paginator.page(1)
except EmptyPage:
2019-08-02 12:57:53 +00:00
# If page is out of range (e.g. 9999), deliver last page of results.
2017-07-04 00:21:31 +00:00
revisions = paginator.page(paginator.num_pages)
return render(request, 'logs/index.html', {'revisions_list': revisions})
2019-08-02 12:57:53 +00:00
2017-07-04 00:46:20 +00:00
@login_required
2019-08-08 17:16:54 +00:00
@staff_member_required
2017-07-04 00:46:20 +00:00
def stats_actions(request):
stats = {
2019-08-02 12:57:53 +00:00
'Utilisateur': {
2019-08-08 14:18:15 +00:00
'Action': User.objects.annotate(num=Count('revision')).order_by(
'-num')[:40],
2019-08-02 12:57:53 +00:00
},
2017-07-04 00:46:20 +00:00
}
return render(request, 'logs/stats_users.html', {'stats_list': stats})