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

22 lines
761 B
Python
Raw Normal View History

2016-04-05 20:21:28 +01:00
from django.views.generic import TemplateView
2016-02-20 23:06:49 +00:00
from .utils import get_post, reformat_date
2016-02-20 19:27:18 +00:00
from django.http import Http404
2016-04-05 20:21:28 +01:00
class BlogView(TemplateView):
2016-03-15 22:55:07 +00:00
template_name = "blog/post.html"
2016-02-20 19:27:18 +00:00
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['blog'] = self.blog_data
2016-02-20 23:06:49 +00:00
context['blog']['date'] = reformat_date(self.blog_data['date'])
2016-04-05 20:21:28 +01:00
context['html_title'] = self.blog_data['title']
2016-04-08 23:12:15 +01:00
context['header_image'] = self.blog_data['featured_image']
2016-02-20 19:27:18 +00:00
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)