Use Martor for flatpage admin preview

This commit is contained in:
Evan 2020-04-04 17:39:24 -04:00 committed by Tudor Brindus
parent f7cc0c44fe
commit 432b73e3e0
7 changed files with 24 additions and 13 deletions

View File

@ -392,6 +392,7 @@ MARKDOWN_STYLES = {
'self-description': MARKDOWN_USER_LARGE_STYLE,
'problem': MARKDOWN_ADMIN_EDITABLE_STYLE,
'contest': MARKDOWN_ADMIN_EDITABLE_STYLE,
'flatpage': MARKDOWN_ADMIN_EDITABLE_STYLE,
'language': MARKDOWN_ADMIN_EDITABLE_STYLE,
'license': MARKDOWN_ADMIN_EDITABLE_STYLE,
'judge': MARKDOWN_ADMIN_EDITABLE_STYLE,

View File

@ -299,6 +299,7 @@ urlpatterns = [
url(r'^blog$', preview.BlogMarkdownPreviewView.as_view(), name='blog_preview'),
url(r'^contest$', preview.ContestMarkdownPreviewView.as_view(), name='contest_preview'),
url(r'^comment$', preview.CommentMarkdownPreviewView.as_view(), name='comment_preview'),
url(r'^flatpage$', preview.FlatPageMarkdownPreviewView.as_view(), name='flatpage_preview'),
url(r'^profile$', preview.ProfileMarkdownPreviewView.as_view(), name='profile_preview'),
url(r'^organization$', preview.OrganizationMarkdownPreviewView.as_view(), name='organization_preview'),
url(r'^solution$', preview.SolutionMarkdownPreviewView.as_view(), name='solution_preview'),

View File

@ -1,9 +1,10 @@
from django.contrib import admin
from django.contrib.admin.models import LogEntry
from django.contrib.flatpages.models import FlatPage
from judge.admin.comments import CommentAdmin
from judge.admin.contest import ContestAdmin, ContestParticipationAdmin, ContestTagAdmin
from judge.admin.interface import BlogPostAdmin, LicenseAdmin, LogEntryAdmin, NavigationBarAdmin
from judge.admin.interface import BlogPostAdmin, FlatPageAdmin, LicenseAdmin, LogEntryAdmin, NavigationBarAdmin
from judge.admin.organization import OrganizationAdmin, OrganizationRequestAdmin
from judge.admin.problem import ProblemAdmin
from judge.admin.profile import ProfileAdmin
@ -21,6 +22,8 @@ admin.site.register(CommentLock)
admin.site.register(Contest, ContestAdmin)
admin.site.register(ContestParticipation, ContestParticipationAdmin)
admin.site.register(ContestTag, ContestTagAdmin)
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageAdmin)
admin.site.register(Judge, JudgeAdmin)
admin.site.register(Language, LanguageAdmin)
admin.site.register(License, LicenseAdmin)

View File

@ -1,5 +1,6 @@
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.flatpages.admin import FlatPageAdmin as OldFlatPageAdmin, FlatpageForm as OldFlatpageForm
from django.forms import ModelForm
from django.urls import NoReverseMatch, reverse, reverse_lazy
from django.utils.html import format_html
@ -41,6 +42,15 @@ class NavigationBarAdmin(DraggableMPTTAdmin):
return result
class FlatpageForm(OldFlatpageForm):
class Meta(OldFlatpageForm.Meta):
widgets = {'content': AdminMartorWidget(attrs={'data-markdownfy-url': reverse_lazy('flatpage_preview')})}
class FlatPageAdmin(VersionAdmin, OldFlatPageAdmin):
form = FlatpageForm
class BlogPostForm(ModelForm):
def __init__(self, *args, **kwargs):
super(BlogPostForm, self).__init__(*args, **kwargs)

View File

@ -14,18 +14,6 @@ class JudgeAppConfig(AppConfig):
# noinspection PyUnresolvedReferences
from . import signals, jinja2 # noqa: F401, imported for side effects
from django.contrib.flatpages.models import FlatPage
from django.contrib.flatpages.admin import FlatPageAdmin
from django.contrib import admin
from reversion.admin import VersionAdmin
class FlatPageVersionAdmin(VersionAdmin, FlatPageAdmin):
pass
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageVersionAdmin)
from judge.models import Language, Profile
from django.contrib.auth.models import User

View File

@ -30,6 +30,10 @@ class CommentMarkdownPreviewView(MarkdownPreviewView):
template_name = 'comments/preview.html'
class FlatPageMarkdownPreviewView(MarkdownPreviewView):
template_name = 'flatpage-preview.html'
class ProfileMarkdownPreviewView(MarkdownPreviewView):
template_name = 'user/preview.html'

View File

@ -0,0 +1,4 @@
{{ preview_data|markdown('flatpage', MATH_ENGINE)|reference|str }}
{% if REQUIRE_JAX %}
<div data-config="{{ static('mathjax_config.js') }}" class="require-mathjax-support"></div>
{% endif %}