Switch to TranslatableSlugMixin. Fix #27
This commit is contained in:
parent
f109adc77d
commit
a35fc201e8
4 changed files with 7 additions and 13 deletions
|
@ -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()
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
||||
|
|
2
setup.py
2
setup.py
|
@ -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',
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue