From 131c56fc418cd9065c9dc1e64051bc7c71ce464d Mon Sep 17 00:00:00 2001 From: Med Date: Tue, 4 Jul 2017 02:21:31 +0200 Subject: [PATCH] Page de statistiques --- logs/__init__.py | 0 logs/admin.py | 3 ++ logs/apps.py | 5 ++ logs/migrations/__init__.py | 0 logs/models.py | 3 ++ logs/templates/logs/aff_actions.html | 61 +++++++++++++++++++++ logs/templates/logs/delete.html | 40 ++++++++++++++ logs/templates/logs/index.html | 36 +++++++++++++ logs/templates/logs/sidebar.html | 34 ++++++++++++ logs/templatetags/logs_extra.py | 29 ++++++++++ logs/tests.py | 3 ++ logs/urls.py | 30 +++++++++++ logs/views.py | 79 ++++++++++++++++++++++++++++ med/settings.py | 3 +- med/urls.py | 1 + templates/base.html | 3 ++ 16 files changed, 329 insertions(+), 1 deletion(-) create mode 100644 logs/__init__.py create mode 100644 logs/admin.py create mode 100644 logs/apps.py create mode 100644 logs/migrations/__init__.py create mode 100644 logs/models.py create mode 100644 logs/templates/logs/aff_actions.html create mode 100644 logs/templates/logs/delete.html create mode 100644 logs/templates/logs/index.html create mode 100644 logs/templates/logs/sidebar.html create mode 100644 logs/templatetags/logs_extra.py create mode 100644 logs/tests.py create mode 100644 logs/urls.py create mode 100644 logs/views.py diff --git a/logs/__init__.py b/logs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/logs/admin.py b/logs/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/logs/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/logs/apps.py b/logs/apps.py new file mode 100644 index 0000000..7f3a755 --- /dev/null +++ b/logs/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class LogsConfig(AppConfig): + name = 'logs' diff --git a/logs/migrations/__init__.py b/logs/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/logs/models.py b/logs/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/logs/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/logs/templates/logs/aff_actions.html b/logs/templates/logs/aff_actions.html new file mode 100644 index 0000000..3550414 --- /dev/null +++ b/logs/templates/logs/aff_actions.html @@ -0,0 +1,61 @@ +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% if revisions_list.paginator %} +{% include "pagination.html" with list=revisions_list %} +{% endif %} + +{% load logs_extra %} + + + + + + + + + + + + + {% for revision in revisions_list %} + {% for reversion in revision.version_set.all %} + + + + + + + {% if is_bureau %} + + {% endif %} + + {% endfor %} + {% endfor %} +
Objet modifiéType de l'objetModification parDate de modificationCommentaire
{{ reversion.object|truncatechars:20 }}{{ reversion.object|classname }}{{ revision.user }}{{ revision.date_created }}{{ revision.comment }} + + + Annuler + +
diff --git a/logs/templates/logs/delete.html b/logs/templates/logs/delete.html new file mode 100644 index 0000000..8bda7cb --- /dev/null +++ b/logs/templates/logs/delete.html @@ -0,0 +1,40 @@ +{% extends "logs/sidebar.html" %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% load bootstrap3 %} + +{% block title %}Supression d'action{% endblock %} + +{% block content %} + +
+ {% csrf_token %} +

Attention, voulez-vous vraiment annuler cette action {{ objet_name }} ( {{ objet }} ) ?

+ {% bootstrap_button "Confirmer" button_type="submit" icon="trash" %} +
+
+
+
+{% endblock %} diff --git a/logs/templates/logs/index.html b/logs/templates/logs/index.html new file mode 100644 index 0000000..0255672 --- /dev/null +++ b/logs/templates/logs/index.html @@ -0,0 +1,36 @@ +{% extends "logs/sidebar.html" %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% load bootstrap3 %} + +{% block title %}Statistiques{% endblock %} + +{% block content %} +

Actions effectuées

+ {% include "logs/aff_actions.html" with revisions_list=revisions_list %} +
+
+
+ {% endblock %} diff --git a/logs/templates/logs/sidebar.html b/logs/templates/logs/sidebar.html new file mode 100644 index 0000000..23845e4 --- /dev/null +++ b/logs/templates/logs/sidebar.html @@ -0,0 +1,34 @@ +{% extends "base.html" %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + + +{% block sidebar %} + {% if is_med %} + + + Évènements + + {% endif %} +{% endblock %} diff --git a/logs/templatetags/logs_extra.py b/logs/templatetags/logs_extra.py new file mode 100644 index 0000000..3ea14bf --- /dev/null +++ b/logs/templatetags/logs_extra.py @@ -0,0 +1,29 @@ +# Re2o est un logiciel d'administration développé initiallement au rezometz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2017 Gabriel Détraz +# Copyright © 2017 Goulven Kermarec +# Copyright © 2017 Augustin Lemesle +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +from django import template + +register = template.Library() + +@register.filter +def classname(obj): + return obj.__class__.__name__ diff --git a/logs/tests.py b/logs/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/logs/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/logs/urls.py b/logs/urls.py new file mode 100644 index 0000000..c8286b7 --- /dev/null +++ b/logs/urls.py @@ -0,0 +1,30 @@ +# Re2o est un logiciel d'administration développé initiallement au rezometz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2017 Gabriel Détraz +# Copyright © 2017 Goulven Kermarec +# Copyright © 2017 Augustin Lemesle +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +from django.conf.urls import url + +from . import views + +urlpatterns = [ + url(r'^$', views.index, name='index'), + url(r'^revert_action/(?P[0-9]+)$', views.revert_action, name='revert-action'), +] diff --git a/logs/views.py b/logs/views.py new file mode 100644 index 0000000..cc3d13d --- /dev/null +++ b/logs/views.py @@ -0,0 +1,79 @@ +# Re2o est un logiciel d'administration développé initiallement au rezometz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2017 Gabriel Détraz +# Copyright © 2017 Goulven Kermarec +# Copyright © 2017 Augustin Lemesle +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# App de gestion des statistiques pour re2o +# Gabriel Détraz +# Gplv2 +from django.http import HttpResponse +from django.shortcuts import render, redirect +from django.shortcuts import get_object_or_404 +from django.template.context_processors import csrf +from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger +from django.template import Context, RequestContext, loader +from django.contrib import messages +from django.contrib.auth.decorators import login_required, permission_required +from django.db.models import ProtectedError +from django.forms import ValidationError +from django.db import transaction +from django.db.models import Count + +from reversion.models import Revision +from reversion.models import Version + +from med.settings import PAGINATION_NUMBER as pagination_number + +from django.utils import timezone + +def form(ctx, template, request): + c = ctx + c.update(csrf(request)) + return render(request, template, c) + +@login_required +@permission_required('perm') +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 +@permission_required('bureau') +def revert_action(request, revision_id): + """ Annule l'action en question """ + try: + revision = Revision.objects.get(id=revision_id) + except Revision.DoesNotExist: + messages.error(request, u"Revision inexistante" ) + if request.method == "POST": + revision.revert() + messages.success(request, "L'action a été supprimée") + return redirect("/logs/") + return form({'objet': revision, 'objet_name': revision.__class__.__name__ }, 'logs/delete.html', request) diff --git a/med/settings.py b/med/settings.py index 38c18a6..5aa1037 100644 --- a/med/settings.py +++ b/med/settings.py @@ -68,7 +68,8 @@ INSTALLED_APPS = ( 'med', 'media', 'search', - 'reversion' + 'reversion', + 'logs' ) MIDDLEWARE_CLASSES = ( diff --git a/med/urls.py b/med/urls.py index bc073ce..26cefa0 100644 --- a/med/urls.py +++ b/med/urls.py @@ -48,4 +48,5 @@ urlpatterns = [ url(r'^users/', include('users.urls', namespace='users')), url(r'^media/', include('media.urls', namespace='media')), url(r'^search/', include('search.urls', namespace='search')), + url(r'^logs/', include('logs.urls', namespace='logs')), ] diff --git a/templates/base.html b/templates/base.html index c157ada..9baa53a 100644 --- a/templates/base.html +++ b/templates/base.html @@ -58,6 +58,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
  • Utilisateurs
  • {% endif %}
  • Media
  • + {% if is_perm %} +
  • Statistiques
  • + {% endif %}