Fix views

This commit is contained in:
Iacopo Spalletti 2014-03-07 18:04:46 +01:00
commit 5a1aa5c6bb

View file

@ -6,6 +6,7 @@ from django.core.urlresolvers import resolve
from django.db.models import Count from django.db.models import Count
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.generic import ListView, DetailView from django.views.generic import ListView, DetailView
from parler.utils import get_active_language_choices
from .models import Post, BlogCategory from .models import Post, BlogCategory
from .settings import BLOG_PAGINATION, BLOG_POSTS_LIST_TRUNCWORDS_COUNT from .settings import BLOG_PAGINATION, BLOG_POSTS_LIST_TRUNCWORDS_COUNT
@ -36,12 +37,20 @@ class PostListView(BaseBlogView, ListView):
context['TRUNCWORDS_COUNT'] = BLOG_POSTS_LIST_TRUNCWORDS_COUNT context['TRUNCWORDS_COUNT'] = BLOG_POSTS_LIST_TRUNCWORDS_COUNT
return context return context
class PostDetailView(BaseBlogView, DetailView): class PostDetailView(BaseBlogView, DetailView):
model = Post model = Post
context_object_name = 'post' context_object_name = 'post'
template_name = "djangocms_blog/post_detail.html" template_name = "djangocms_blog/post_detail.html"
slug_field = 'translations__slug' slug_field = 'translations__slug'
def get_object(self, queryset=None):
qs = self.model._default_manager.get(**{
'translations__language_code': get_language_from_request(self.request),
self.slug_field: self.kwargs.get(self.slug_url_kwarg, None)
})
return qs
class PostArchiveView(BaseBlogView, ListView): class PostArchiveView(BaseBlogView, ListView):
model = Post model = Post