Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display change log in admin for superusers #952

Merged
merged 2 commits into from Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion judge/admin/__init__.py
@@ -1,8 +1,9 @@
from django.contrib import admin
from django.contrib.admin.models import LogEntry

from judge.admin.comments import CommentAdmin
from judge.admin.contest import ContestTagAdmin, ContestAdmin, ContestParticipationAdmin
from judge.admin.interface import NavigationBarAdmin, BlogPostAdmin, LicenseAdmin
from judge.admin.interface import NavigationBarAdmin, BlogPostAdmin, LicenseAdmin, LogEntryAdmin
from judge.admin.organization import OrganizationAdmin, OrganizationRequestAdmin
from judge.admin.problem import ProblemAdmin
from judge.admin.profile import ProfileAdmin
Expand All @@ -23,6 +24,7 @@
admin.site.register(Judge, JudgeAdmin)
admin.site.register(Language, LanguageAdmin)
admin.site.register(License, LicenseAdmin)
admin.site.register(LogEntry, LogEntryAdmin)
admin.site.register(MiscConfig)
admin.site.register(NavigationBar, NavigationBarAdmin)
admin.site.register(Organization, OrganizationAdmin)
Expand Down
37 changes: 36 additions & 1 deletion judge/admin/interface.py
@@ -1,6 +1,6 @@
from django.contrib import admin
from django.forms import ModelForm
from django.urls import reverse_lazy
from django.urls import reverse, reverse_lazy, NoReverseMatch
from django.utils.html import format_html
from django.utils.translation import gettext_lazy as _
from mptt.admin import DraggableMPTTAdmin
Expand Down Expand Up @@ -100,3 +100,38 @@ class LicenseAdmin(admin.ModelAdmin):
fields = ('key', 'link', 'name', 'display', 'icon', 'text')
list_display = ('name', 'key')
form = LicenseForm


class LogEntryAdmin(admin.ModelAdmin):
readonly_fields = ('user', 'content_type', 'object_id', 'object_repr', 'action_flag', 'change_message')
list_display = ('__str__', 'action_time', 'user', 'content_type', 'object_link')
search_fields = ('object_repr', 'change_message')
list_filter = ('user', 'content_type')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhhhh... this lists all the users on the site. That's... excessive.

list_display_links = None
actions = None

def has_add_permission(self, request):
return False

def has_change_permission(self, request, obj=None):
return obj is None and request.user.is_superuser

def has_delete_permission(self, request, obj=None):
return False

def object_link(self, obj):
if obj.is_deletion():
link = obj.object_repr
else:
ct = obj.content_type
try:
link = format_html('<a href="{1}">{0}</a>', obj.object_repr,
reverse('admin:%s_%s_change' % (ct.app_label, ct.model), args=(obj.object_id,)))
except NoReverseMatch:
link = obj.object_repr
return link
object_link.admin_order_field = 'object_repr'
object_link.short_description = _('object')

def queryset(self, request):
return super().queryset(request).prefetch_related('content_type')