From bc3c46b63d9fd07ac7250d61a1e36c79d907f830 Mon Sep 17 00:00:00 2001 From: Luciano Almeida Date: Thu, 2 Feb 2017 16:11:32 -0200 Subject: [PATCH] Adiciona reversion no admin Signed-off-by: Luciano Almeida --- sapl/base/admin.py | 14 ++++++++++++++ sapl/settings.py | 1 + sapl/utils.py | 5 ++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/sapl/base/admin.py b/sapl/base/admin.py index 02ccd3c60..832b073db 100644 --- a/sapl/base/admin.py +++ b/sapl/base/admin.py @@ -1,6 +1,8 @@ from django.contrib import admin from django.core.urlresolvers import reverse +from django.shortcuts import redirect +from reversion.models import Revision from sapl.base.models import ProblemaMigracao from sapl.utils import register_all_models_in_admin @@ -27,3 +29,15 @@ class ProblemaMigracaoAdmin(admin.ModelAdmin): get_url.short_description = "Endereço" get_url.allow_tags = True + + +class RevisionAdmin(admin.ModelAdmin): + list_display = ('user', 'comment', 'date_created') + search_fields = ('=user__username', '=user__email') + date_hierarchy = ('date_created') + + def change_view(self, request, obj=None): + self.message_user(request, 'You cannot change history.') + return redirect('admin:reversion_revision_changelist') + +admin.site.register(Revision, RevisionAdmin) diff --git a/sapl/settings.py b/sapl/settings.py index add1f2d72..37646e675 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -86,6 +86,7 @@ if DEBUG: INSTALLED_APPS += ('debug_toolbar', 'rest_framework_docs',) MIDDLEWARE_CLASSES = ( + 'reversion.middleware.RevisionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', diff --git a/sapl/utils.py b/sapl/utils.py index bda144e5d..28c48d413 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -18,6 +18,9 @@ from django.contrib.contenttypes.fields import (GenericForeignKey, GenericRel, from django.core.exceptions import ValidationError from django.utils.translation import ugettext_lazy as _ from floppyforms import ClearableFileInput +from reversion.admin import VersionAdmin +import django_filters +import magic from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row from sapl.settings import BASE_DIR @@ -195,7 +198,7 @@ def register_all_models_in_admin(module_name): appname = appname[1] if appname[0] == 'sapl' else appname[0] app = apps.get_app_config(appname) for model in app.get_models(): - class CustomModelAdmin(admin.ModelAdmin): + class CustomModelAdmin(VersionAdmin): list_display = [f.name for f in model._meta.fields if f.name != 'id']