Browse Source

Adiciona reversion no admin

Signed-off-by: Luciano Almeida <lucianoalmeida@interlegis.leg.br>
pull/900/head
Luciano Almeida 8 years ago
parent
commit
bc3c46b63d
  1. 14
      sapl/base/admin.py
  2. 1
      sapl/settings.py
  3. 5
      sapl/utils.py

14
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)

1
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',

5
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']

Loading…
Cancel
Save