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.http import Http404
|
||||||
from django.views.generic import ListView, DetailView
|
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 .models import Post, BlogCategory, BLOG_CURRENT_POST_IDENTIFIER
|
||||||
from .settings import (BLOG_PAGINATION, BLOG_POSTS_LIST_TRUNCWORDS_COUNT,
|
from .settings import (BLOG_PAGINATION, BLOG_POSTS_LIST_TRUNCWORDS_COUNT,
|
||||||
|
@ -40,22 +40,13 @@ class PostListView(BaseBlogView, ListView):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class PostDetailView(BaseBlogView, DetailView):
|
class PostDetailView(TranslatableSlugMixin, 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 = 'slug'
|
slug_field = 'slug'
|
||||||
view_url_name = 'djangocms_blog:post-detail'
|
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):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(PostDetailView, self).get_context_data(**kwargs)
|
context = super(PostDetailView, self).get_context_data(**kwargs)
|
||||||
context['meta'] = self.get_object().as_meta()
|
context['meta'] = self.get_object().as_meta()
|
||||||
|
|
|
@ -112,7 +112,8 @@ try:
|
||||||
)
|
)
|
||||||
|
|
||||||
from django_nose import NoseTestSuiteRunner
|
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')
|
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,
|
include_package_data=True,
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'django-parler>=1.0b1',
|
'django-parler>=1.0b3',
|
||||||
'django-cms>=3.0',
|
'django-cms>=3.0',
|
||||||
'django-taggit',
|
'django-taggit',
|
||||||
'django-filer',
|
'django-filer',
|
||||||
|
|
|
@ -79,7 +79,9 @@ class ViewTest(BaseTest):
|
||||||
|
|
||||||
request = self.get_page_request(page1, AnonymousUser(), r'/it/blog/', lang_code='it', edit=False)
|
request = self.get_page_request(page1, AnonymousUser(), r'/it/blog/', lang_code='it', edit=False)
|
||||||
activate('it')
|
activate('it')
|
||||||
|
post_1.set_current_language('it')
|
||||||
view_obj.request = request
|
view_obj.request = request
|
||||||
|
view_obj.kwargs = {'slug': post_1.slug}
|
||||||
post_obj = view_obj.get_object()
|
post_obj = view_obj.get_object()
|
||||||
self.assertEqual(post_obj, post_1)
|
self.assertEqual(post_obj, post_1)
|
||||||
self.assertEqual(post_obj.language_code, 'it')
|
self.assertEqual(post_obj.language_code, 'it')
|
||||||
|
|
Loading…
Reference in a new issue