Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add admin view for the admin log.

  • Loading branch information...
commit 39052d1e73f6a9f1c4a7d3df60e62b3bb38b4a0e 1 parent 6c45f8e
@Osmose Osmose authored
Showing with 41 additions and 0 deletions.
  1. +41 −0 flicks/base/admin.py
View
41 flicks/base/admin.py
@@ -1,4 +1,7 @@
from django.contrib import admin
+from django.contrib.admin.models import LogEntry, DELETION
+from django.core.urlresolvers import reverse
+from django.utils.html import escape
from caching.base import CachingQuerySet
@@ -16,3 +19,41 @@ def queryset(self, request):
if isinstance(qs, CachingQuerySet):
qs = qs.no_cache()
return qs
+
+
+class LogEntryAdmin(admin.ModelAdmin):
+ """
+ Allows review of admin actions.
+
+ Taken from http://djangosnippets.org/snippets/2484/
+ """
+ date_hierarchy = 'action_time'
+ readonly_fields = LogEntry._meta.get_all_field_names()
+ list_filter = ('user', 'content_type', 'action_flag')
+ search_fields = ('object_repr', 'change_message')
+ list_display = ('__unicode__', 'action_time', 'user', 'content_type',
+ 'object_link', 'action_flag', 'change_message')
+
+ def has_add_permission(self, request):
+ return False
+
+ def has_change_permission(self, request, obj=None):
+ return request.user.is_superuser and request.method != 'POST'
+
+ def has_delete_permission(self, request, obj=None):
+ return False
+
+ def object_link(self, obj):
+ if obj.action_flag == DELETION:
+ link = escape(obj.object_repr)
+ else:
+ ct = obj.content_type
+ link = u'<a href="%s">%s</a>' % (
+ reverse('admin:%s_%s_change' % (ct.app_label, ct.model), args=[obj.object_id]),
+ escape(obj.object_repr),
+ )
+ return link
+ object_link.allow_tags = True
+ object_link.admin_order_field = 'object_repr'
+ object_link.short_description = u'object'
+admin.site.register(LogEntry, LogEntryAdmin)
Please sign in to comment.
Something went wrong with that request. Please try again.