Add compare reversion for contest and blog

This commit is contained in:
cuom1999 2022-04-26 13:24:36 -05:00
parent 308234166b
commit 01c19b172a
4 changed files with 21 additions and 4 deletions

View file

@ -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

View file

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

View file

@ -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('<a href="{1}">{0}</a>', _('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')

View file

@ -31,4 +31,6 @@ revisions.register(ProblemPointsVote)
revisions.register(ContestMoss)
revisions.register(ProblemData)
revisions.register(ProblemTestCase)
revisions.register(ContestParticipation)
revisions.register(Rating)
del revisions