2016-01-14 20:01:47 +00:00
|
|
|
from django.views.generic import TemplateView, FormView
|
2016-01-22 08:23:34 +00:00
|
|
|
from django.template import loader, Context
|
|
|
|
from django.template.base import TemplateDoesNotExist
|
2016-01-18 22:24:25 +00:00
|
|
|
from django.http import Http404
|
|
|
|
import markdown2
|
2015-10-19 13:04:49 +01:00
|
|
|
|
2015-11-25 21:11:52 +00:00
|
|
|
class CustomTemplate(TemplateView):
|
|
|
|
html_title = ""
|
|
|
|
body_class = ""
|
2015-11-26 09:53:40 +00:00
|
|
|
|
2015-11-25 21:11:52 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['html_title'] = self.html_title
|
|
|
|
context['body_class'] = self.body_class
|
2015-12-11 08:40:01 +00:00
|
|
|
context['js_redirect'] = True
|
2015-11-25 21:11:52 +00:00
|
|
|
return context
|
2016-01-14 20:01:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CustomFormTemplate(FormView):
|
|
|
|
html_title = ""
|
|
|
|
body_class = ""
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['html_title'] = self.html_title
|
|
|
|
context['body_class'] = self.body_class
|
|
|
|
context['js_redirect'] = True
|
|
|
|
return context
|
2016-01-18 22:24:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MarkdownView(CustomTemplate):
|
|
|
|
template_name = 'markdown_content.html'
|
|
|
|
page_title = ""
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['page_title'] = self.page_title
|
|
|
|
try:
|
|
|
|
markdown_template = loader.get_template(self.markdown)
|
|
|
|
except TemplateDoesNotExist:
|
|
|
|
raise Http404
|
|
|
|
c = Context(self.get_markdown_context().update(context))
|
|
|
|
context['markdown_content'] = markdown2.markdown(markdown_template.render(c))
|
|
|
|
return context
|
|
|
|
|
|
|
|
def get_markdown_context(self):
|
|
|
|
return {}
|