preview.py
39 lines
| 992 B
| text/x-python
|
PythonLexer
|
r825 | from django.shortcuts import render | ||
from django.template import RequestContext | ||||
from django.views.generic import View | ||||
|
r1066 | from boards.mdx_neboard import Parser | ||
|
r825 | |||
FORM_QUERY = 'query' | ||||
CONTEXT_RESULT = 'result' | ||||
CONTEXT_QUERY = 'query' | ||||
__author__ = 'neko259' | ||||
TEMPLATE = 'boards/preview.html' | ||||
class PostPreviewView(View): | ||||
def get(self, request): | ||||
context = RequestContext(request) | ||||
|
r872 | # TODO Use dict here | ||
return render(request, TEMPLATE, context_instance=context) | ||||
|
r825 | |||
def post(self, request): | ||||
context = RequestContext(request) | ||||
if FORM_QUERY in request.POST: | ||||
raw_text = request.POST[FORM_QUERY] | ||||
if len(raw_text) >= 0: | ||||
|
r1066 | parser = Parser() | ||
rendered_text = parser.parse(parser.preparse(raw_text)) | ||||
|
r825 | |||
context[CONTEXT_RESULT] = rendered_text | ||||
context[CONTEXT_QUERY] = raw_text | ||||
|
r872 | # TODO Use dict here | ||
return render(request, TEMPLATE, context_instance=context) | ||||