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/blog/views.py
2016-04-08 23:15:15 +01:00

22 lines
812 B
Python

from django.views.generic import TemplateView
from .utils import get_post, reformat_date
from django.http import Http404
class BlogView(TemplateView):
template_name = "blog/post.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['blog'] = self.blog_data
context['blog']['date'] = reformat_date(self.blog_data['date'])
context['html_title'] = self.blog_data['title']
if 'featured_image' in self.blog_data:
context['header_image'] = self.blog_data['featured_image']
return context
def dispatch(self, request, *args, **kwargs):
self.blog_data = get_post(kwargs['slug'])
if not self.blog_data:
raise Http404
return super().dispatch(request, *args, **kwargs)