1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
theorangeone.net-legacy/project/common/views.py

49 lines
1.4 KiB
Python
Raw Normal View History

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
from django.http import Http404
import markdown2
2015-10-19 13:04:49 +01:00
2016-01-22 08:40:01 +00: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
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
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 {}