diff --git a/judge/admin/__init__.py b/judge/admin/__init__.py index 67c778c..0414d58 100644 --- a/judge/admin/__init__.py +++ b/judge/admin/__init__.py @@ -15,6 +15,7 @@ from judge.models import BlogPost, Comment, CommentLock, Contest, ContestPartici ContestTag, Judge, Language, License, MiscConfig, NavigationBar, Organization, \ OrganizationRequest, Problem, ProblemGroup, ProblemPointsVote, ProblemType, Profile, Submission, Ticket + admin.site.register(BlogPost, BlogPostAdmin) admin.site.register(Comment, CommentAdmin) admin.site.register(CommentLock) @@ -36,4 +37,3 @@ admin.site.register(ProblemType, ProblemTypeAdmin) admin.site.register(Profile, ProfileAdmin) admin.site.register(Submission, SubmissionAdmin) admin.site.register(Ticket, TicketAdmin) -admin.site diff --git a/judge/admin/contest.py b/judge/admin/contest.py index 8678281..bda5156 100644 --- a/judge/admin/contest.py +++ b/judge/admin/contest.py @@ -11,6 +11,7 @@ from django.utils import timezone from django.utils.html import format_html from django.utils.translation import gettext_lazy as _, ungettext from reversion.admin import VersionAdmin +from reversion_compare.admin import CompareVersionAdmin from django_ace import AceWidget from judge.models import Contest, ContestProblem, ContestSubmission, Profile, Rating @@ -113,7 +114,7 @@ class ContestForm(ModelForm): widgets['description'] = HeavyPreviewAdminPageDownWidget(preview=reverse_lazy('contest_preview')) -class ContestAdmin(VersionAdmin): +class ContestAdmin(CompareVersionAdmin): fieldsets = ( (None, {'fields': ('key', 'name', 'authors', 'curators', 'testers')}), (_('Settings'), {'fields': ('is_visible', 'use_clarifications', 'hide_problem_tags', 'scoreboard_visibility', diff --git a/judge/admin/interface.py b/judge/admin/interface.py index 4691c8b..fb57844 100644 --- a/judge/admin/interface.py +++ b/judge/admin/interface.py @@ -6,6 +6,8 @@ from django.utils.html import format_html from django.utils.translation import gettext_lazy as _ from mptt.admin import DraggableMPTTAdmin from reversion.admin import VersionAdmin +from reversion_compare.admin import CompareVersionAdmin + from judge.dblock import LockModel from judge.models import NavigationBar @@ -58,7 +60,7 @@ class BlogPostForm(ModelForm): widgets['summary'] = HeavyPreviewAdminPageDownWidget(preview=reverse_lazy('blog_preview')) -class BlogPostAdmin(VersionAdmin): +class BlogPostAdmin(CompareVersionAdmin): fieldsets = ( (None, {'fields': ('title', 'slug', 'authors', 'visible', 'sticky', 'publish_on', 'is_organization_private', 'organizations')}), @@ -121,7 +123,7 @@ class UserListFilter(admin.SimpleListFilter): 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') + list_display = ('__str__', 'action_time', 'user', 'content_type', 'object_link', 'diff_link') search_fields = ('object_repr', 'change_message') list_filter = (UserListFilter, 'content_type') list_display_links = None @@ -150,5 +152,17 @@ class LogEntryAdmin(admin.ModelAdmin): object_link.admin_order_field = 'object_repr' object_link.short_description = _('object') + def diff_link(self, obj): + if obj.is_deletion(): + return None + ct = obj.content_type + try: + url = reverse('admin:%s_%s_history' % (ct.app_label, ct.model), args=(obj.object_id,)) + link = format_html('{0}', _('Diff'), url) + except NoReverseMatch: + link = None + return link + diff_link.short_description = _('diff') + def queryset(self, request): return super().queryset(request).prefetch_related('content_type') diff --git a/judge/models/__init__.py b/judge/models/__init__.py index c9c5db2..2518bc2 100644 --- a/judge/models/__init__.py +++ b/judge/models/__init__.py @@ -31,4 +31,6 @@ revisions.register(ProblemPointsVote) revisions.register(ContestMoss) revisions.register(ProblemData) revisions.register(ProblemTestCase) +revisions.register(ContestParticipation) +revisions.register(Rating) del revisions