Switch to TranslatableSlugMixin. Fix #27

This commit is contained in:
Iacopo Spalletti 2014-06-11 17:45:18 +02:00
parent f109adc77d
commit a35fc201e8
4 changed files with 7 additions and 13 deletions

View file

@ -6,7 +6,7 @@ from django.core.urlresolvers import resolve
from django.http import Http404
from django.views.generic import ListView, DetailView
from parler.views import ViewUrlMixin
from parler.views import ViewUrlMixin, TranslatableSlugMixin
from .models import Post, BlogCategory, BLOG_CURRENT_POST_IDENTIFIER
from .settings import (BLOG_PAGINATION, BLOG_POSTS_LIST_TRUNCWORDS_COUNT,
@ -40,22 +40,13 @@ class PostListView(BaseBlogView, ListView):
return context
class PostDetailView(BaseBlogView, DetailView):
class PostDetailView(TranslatableSlugMixin, BaseBlogView, DetailView):
model = Post
context_object_name = 'post'
template_name = "djangocms_blog/post_detail.html"
slug_field = 'slug'
view_url_name = 'djangocms_blog:post-detail'
def get_object(self, queryset=None):
try:
qs = self.model._default_manager.active_translations(**{
self.slug_field: self.kwargs.get(self.slug_url_kwarg, None)
}).latest()
except Post.DoesNotExist:
raise Http404()
return qs
def get_context_data(self, **kwargs):
context = super(PostDetailView, self).get_context_data(**kwargs)
context['meta'] = self.get_object().as_meta()

View file

@ -112,7 +112,8 @@ try:
)
from django_nose import NoseTestSuiteRunner
except ImportError:
except ImportError as e:
print(e)
raise ImportError('To fix this error, run: pip install -r requirements-test.txt')

View file

@ -36,7 +36,7 @@ setup(
],
include_package_data=True,
install_requires=[
'django-parler>=1.0b1',
'django-parler>=1.0b3',
'django-cms>=3.0',
'django-taggit',
'django-filer',

View file

@ -79,7 +79,9 @@ class ViewTest(BaseTest):
request = self.get_page_request(page1, AnonymousUser(), r'/it/blog/', lang_code='it', edit=False)
activate('it')
post_1.set_current_language('it')
view_obj.request = request
view_obj.kwargs = {'slug': post_1.slug}
post_obj = view_obj.get_object()
self.assertEqual(post_obj, post_1)
self.assertEqual(post_obj.language_code, 'it')