mirror of
https://gitlab.crans.org/mediatek/med.git
synced 2024-11-30 10:13:03 +00:00
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
# -*- mode: python; coding: utf-8 -*-
|
|
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
from django.contrib.admin.views.decorators import staff_member_required
|
|
from django.contrib.auth.decorators import login_required
|
|
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
|
|
from django.db.models import Count
|
|
from django.shortcuts import render
|
|
from django.template.context_processors import csrf
|
|
from reversion.models import Revision
|
|
|
|
from med.settings import PAGINATION_NUMBER
|
|
from users.models import User
|
|
|
|
|
|
def form(ctx, template, request):
|
|
c = ctx
|
|
c.update(csrf(request))
|
|
return render(request, template, c)
|
|
|
|
|
|
@login_required
|
|
@staff_member_required
|
|
def index(request):
|
|
revisions = Revision.objects.all().order_by(
|
|
'date_created').reverse().select_related('user').prefetch_related(
|
|
'version_set__object')
|
|
paginator = Paginator(revisions, PAGINATION_NUMBER)
|
|
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:
|
|
# If page is out of range (e.g. 9999), deliver last page of results.
|
|
revisions = paginator.page(paginator.num_pages)
|
|
return render(request, 'logs/index.html', {'revisions_list': revisions})
|
|
|
|
|
|
@login_required
|
|
@staff_member_required
|
|
def stats_actions(request):
|
|
stats = {
|
|
'Utilisateur': {
|
|
'Action': User.objects.annotate(num=Count('revision')).order_by(
|
|
'-num')[:40],
|
|
},
|
|
}
|
|
return render(request, 'logs/stats_users.html', {'stats_list': stats})
|