This repository has been archived by the owner on Sep 3, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
130 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import datetime, time | ||
|
||
from django.views.generic import ListView, DetailView | ||
|
||
from blog.models import Post | ||
from blog.settings import BLOG_PAGINATE_BY | ||
from blog.views.category import BlogCategoryDetailView, BlogCategoryListView | ||
|
||
__all__ = [ | ||
'BlogPostListView', | ||
'BlogPostDeatilView', | ||
'BlogCategoryListView', | ||
'BlogCategoryDetailView', | ||
] | ||
|
||
class BlogPostListView(ListView): | ||
|
||
context_object_name = "post_list" | ||
template_name = "blog/index.html" | ||
paginate_by = BLOG_PAGINATE_BY | ||
|
||
def get_queryset(self): | ||
return Post.objects.published().select_related() | ||
|
||
class BlogPostDeatilView(DetailView): | ||
|
||
context_object_name = 'post' | ||
template_name = "blog/detail.html" | ||
|
||
def get_object(self): | ||
year = self.kwargs['year'] | ||
month = self.kwargs['month'] | ||
day = self.kwargs['day'] | ||
slug = self.kwargs['slug'] | ||
|
||
try: | ||
date = datetime.date(*time.strptime(year+month+day, '%Y%b%d')[:3]) | ||
except ValueError: | ||
raise Http404 | ||
|
||
try: | ||
return Post.objects.get_post(slug, date) | ||
except Post.DoesNotExist: | ||
raise Http404 |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from django.views.generic import ListView | ||
|
||
from blog.models import Post, Category | ||
from blog.settings import BLOG_PAGINATE_BY | ||
|
||
class BlogCategoryListView(ListView): | ||
|
||
context_object_name = "category_list" | ||
template_name = "blog/category/list.html" | ||
|
||
def get_queryset(self): | ||
return Category.objects.all().select_related() | ||
|
||
class BlogCategoryDetailView(ListView): | ||
|
||
context_object_name = 'posts' | ||
template_name = "blog/category/detail.html" | ||
paginate_by = BLOG_PAGINATE_BY | ||
|
||
def get_queryset(self): | ||
try: | ||
self.category = Category.objects.get(slug__iexact=self.kwargs['slug']) | ||
except Category.DoesNotExist: | ||
raise Http404 | ||
|
||
return Post.objects.published(categories=self.category) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.