Add compare reversion for contest and blog
This commit is contained in:
parent
308234166b
commit
01c19b172a
4 changed files with 21 additions and 4 deletions
|
@ -15,6 +15,7 @@ from judge.models import BlogPost, Comment, CommentLock, Contest, ContestPartici
|
||||||
ContestTag, Judge, Language, License, MiscConfig, NavigationBar, Organization, \
|
ContestTag, Judge, Language, License, MiscConfig, NavigationBar, Organization, \
|
||||||
OrganizationRequest, Problem, ProblemGroup, ProblemPointsVote, ProblemType, Profile, Submission, Ticket
|
OrganizationRequest, Problem, ProblemGroup, ProblemPointsVote, ProblemType, Profile, Submission, Ticket
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(BlogPost, BlogPostAdmin)
|
admin.site.register(BlogPost, BlogPostAdmin)
|
||||||
admin.site.register(Comment, CommentAdmin)
|
admin.site.register(Comment, CommentAdmin)
|
||||||
admin.site.register(CommentLock)
|
admin.site.register(CommentLock)
|
||||||
|
@ -36,4 +37,3 @@ admin.site.register(ProblemType, ProblemTypeAdmin)
|
||||||
admin.site.register(Profile, ProfileAdmin)
|
admin.site.register(Profile, ProfileAdmin)
|
||||||
admin.site.register(Submission, SubmissionAdmin)
|
admin.site.register(Submission, SubmissionAdmin)
|
||||||
admin.site.register(Ticket, TicketAdmin)
|
admin.site.register(Ticket, TicketAdmin)
|
||||||
admin.site
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ from django.utils import timezone
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
from django.utils.translation import gettext_lazy as _, ungettext
|
from django.utils.translation import gettext_lazy as _, ungettext
|
||||||
from reversion.admin import VersionAdmin
|
from reversion.admin import VersionAdmin
|
||||||
|
from reversion_compare.admin import CompareVersionAdmin
|
||||||
|
|
||||||
from django_ace import AceWidget
|
from django_ace import AceWidget
|
||||||
from judge.models import Contest, ContestProblem, ContestSubmission, Profile, Rating
|
from judge.models import Contest, ContestProblem, ContestSubmission, Profile, Rating
|
||||||
|
@ -113,7 +114,7 @@ class ContestForm(ModelForm):
|
||||||
widgets['description'] = HeavyPreviewAdminPageDownWidget(preview=reverse_lazy('contest_preview'))
|
widgets['description'] = HeavyPreviewAdminPageDownWidget(preview=reverse_lazy('contest_preview'))
|
||||||
|
|
||||||
|
|
||||||
class ContestAdmin(VersionAdmin):
|
class ContestAdmin(CompareVersionAdmin):
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(None, {'fields': ('key', 'name', 'authors', 'curators', 'testers')}),
|
(None, {'fields': ('key', 'name', 'authors', 'curators', 'testers')}),
|
||||||
(_('Settings'), {'fields': ('is_visible', 'use_clarifications', 'hide_problem_tags', 'scoreboard_visibility',
|
(_('Settings'), {'fields': ('is_visible', 'use_clarifications', 'hide_problem_tags', 'scoreboard_visibility',
|
||||||
|
|
|
@ -6,6 +6,8 @@ from django.utils.html import format_html
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from mptt.admin import DraggableMPTTAdmin
|
from mptt.admin import DraggableMPTTAdmin
|
||||||
from reversion.admin import VersionAdmin
|
from reversion.admin import VersionAdmin
|
||||||
|
from reversion_compare.admin import CompareVersionAdmin
|
||||||
|
|
||||||
|
|
||||||
from judge.dblock import LockModel
|
from judge.dblock import LockModel
|
||||||
from judge.models import NavigationBar
|
from judge.models import NavigationBar
|
||||||
|
@ -58,7 +60,7 @@ class BlogPostForm(ModelForm):
|
||||||
widgets['summary'] = HeavyPreviewAdminPageDownWidget(preview=reverse_lazy('blog_preview'))
|
widgets['summary'] = HeavyPreviewAdminPageDownWidget(preview=reverse_lazy('blog_preview'))
|
||||||
|
|
||||||
|
|
||||||
class BlogPostAdmin(VersionAdmin):
|
class BlogPostAdmin(CompareVersionAdmin):
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(None, {'fields': ('title', 'slug', 'authors', 'visible', 'sticky', 'publish_on',
|
(None, {'fields': ('title', 'slug', 'authors', 'visible', 'sticky', 'publish_on',
|
||||||
'is_organization_private', 'organizations')}),
|
'is_organization_private', 'organizations')}),
|
||||||
|
@ -121,7 +123,7 @@ class UserListFilter(admin.SimpleListFilter):
|
||||||
|
|
||||||
class LogEntryAdmin(admin.ModelAdmin):
|
class LogEntryAdmin(admin.ModelAdmin):
|
||||||
readonly_fields = ('user', 'content_type', 'object_id', 'object_repr', 'action_flag', 'change_message')
|
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')
|
search_fields = ('object_repr', 'change_message')
|
||||||
list_filter = (UserListFilter, 'content_type')
|
list_filter = (UserListFilter, 'content_type')
|
||||||
list_display_links = None
|
list_display_links = None
|
||||||
|
@ -150,5 +152,17 @@ class LogEntryAdmin(admin.ModelAdmin):
|
||||||
object_link.admin_order_field = 'object_repr'
|
object_link.admin_order_field = 'object_repr'
|
||||||
object_link.short_description = _('object')
|
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):
|
def queryset(self, request):
|
||||||
return super().queryset(request).prefetch_related('content_type')
|
return super().queryset(request).prefetch_related('content_type')
|
||||||
|
|
|
@ -31,4 +31,6 @@ revisions.register(ProblemPointsVote)
|
||||||
revisions.register(ContestMoss)
|
revisions.register(ContestMoss)
|
||||||
revisions.register(ProblemData)
|
revisions.register(ProblemData)
|
||||||
revisions.register(ProblemTestCase)
|
revisions.register(ProblemTestCase)
|
||||||
|
revisions.register(ContestParticipation)
|
||||||
|
revisions.register(Rating)
|
||||||
del revisions
|
del revisions
|
||||||
|
|
Loading…
Reference in a new issue