NDOJ/judge/views/preview.py

53 lines
1.4 KiB
Python
Raw Normal View History

2020-01-21 06:35:58 +00:00
from django.http import HttpResponseBadRequest
from django.views.generic.base import ContextMixin, TemplateResponseMixin, View
class MarkdownPreviewView(TemplateResponseMixin, ContextMixin, View):
def post(self, request, *args, **kwargs):
try:
2022-05-14 17:57:27 +00:00
self.preview_data = data = request.POST["preview"]
2020-01-21 06:35:58 +00:00
except KeyError:
2022-05-14 17:57:27 +00:00
return HttpResponseBadRequest("No preview data specified.")
2020-01-21 06:35:58 +00:00
2022-05-14 17:57:27 +00:00
return self.render_to_response(
self.get_context_data(
preview_data=data,
)
)
2020-01-21 06:35:58 +00:00
class ProblemMarkdownPreviewView(MarkdownPreviewView):
2022-05-14 17:57:27 +00:00
template_name = "problem/preview.html"
2020-01-21 06:35:58 +00:00
class BlogMarkdownPreviewView(MarkdownPreviewView):
2022-05-14 17:57:27 +00:00
template_name = "blog/preview.html"
2020-01-21 06:35:58 +00:00
class ContestMarkdownPreviewView(MarkdownPreviewView):
2022-05-14 17:57:27 +00:00
template_name = "contest/preview.html"
2020-01-21 06:35:58 +00:00
class CommentMarkdownPreviewView(MarkdownPreviewView):
2022-05-14 17:57:27 +00:00
template_name = "comments/preview.html"
2020-01-21 06:35:58 +00:00
class ProfileMarkdownPreviewView(MarkdownPreviewView):
2022-05-14 17:57:27 +00:00
template_name = "user/preview.html"
2020-01-21 06:35:58 +00:00
class OrganizationMarkdownPreviewView(MarkdownPreviewView):
2022-05-14 17:57:27 +00:00
template_name = "organization/preview.html"
2020-01-21 06:35:58 +00:00
class SolutionMarkdownPreviewView(MarkdownPreviewView):
2022-05-14 17:57:27 +00:00
template_name = "solution-preview.html"
2020-01-21 06:35:58 +00:00
class LicenseMarkdownPreviewView(MarkdownPreviewView):
2022-05-14 17:57:27 +00:00
template_name = "license-preview.html"
2020-01-21 06:35:58 +00:00
class TicketMarkdownPreviewView(MarkdownPreviewView):
2022-05-14 17:57:27 +00:00
template_name = "ticket/preview.html"