mirror of
https://github.com/DMOJ/online-judge.git
synced 2024-11-25 16:32:37 +08:00
Use Martor for flatpage admin preview
This commit is contained in:
parent
f7cc0c44fe
commit
432b73e3e0
@ -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,
|
||||
|
@ -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'),
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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'
|
||||
|
||||
|
4
templates/flatpage-preview.html
Normal file
4
templates/flatpage-preview.html
Normal 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 %}
|
Loading…
Reference in New Issue
Block a user