Permalink
Browse files

fixed get_absolute_url error

  • Loading branch information...
1 parent e88bf83 commit d19e1cf7f25ccbdb031de31ef80095e8e0fde740 @Tyrdall Tyrdall committed Mar 27, 2013
View
@@ -1,5 +1,10 @@
=== ongoing ===
+=== 0.5.1 ===
+
+- Fixed get_absolute_url. If the multilingual middleware isn't used it had a
+ wrong output, because even ``False`` variables were put into url parts.
+
=== 0.5 ===
- get_absolute_url now returns the language namespace (i.e. `/en/`). This
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
-__version__ = '0.5'
+__version__ = '0.5.1'
@@ -40,11 +40,11 @@ def get_entries(self):
def get_absolute_url(self):
url = reverse('blog_archive_category', kwargs={
'category': self.slug, })
- lang = None
if 'simple_translation.middleware.MultilingualGenericsMiddleware' in \
settings.MIDDLEWARE_CLASSES:
lang = '/{0}'.format(get_language())
- return '{0}{1}'.format(lang, url)
+ return '{0}{1}'.format(lang, url)
+ return '{0}'.format(url)
def get_title(self):
return self.get_translation().title
@@ -1,5 +1,7 @@
"""Tests for models of the ``cmsplugin_blog_categories``` application."""
+from django.conf import settings
from django.test import TestCase
+from django.test.utils import override_settings
from cmsplugin_blog_categories.tests.factories import (
CategoryTitleCNFactory,
@@ -38,6 +40,19 @@ def test_get_title(self):
result = self.category.get_title()
self.assertEqual(result, 'Category Title')
+ def test_get_absolute_url_with_middleware(self):
+ # If the multilingual middleware is added, add the language prefix
+ self.assertEqual(self.category.get_absolute_url(),
+ '/{0}/blog/category/{1}/'.format(
+ settings.LANGUAGE_CODE, self.category.slug))
+
+ @override_settings(MIDDLEWARE_CLASSES=[])
+ def test_get_absolute_url_without_middleware(self):
+ # If the multilingual middleware is disabled, only the prefix should be
+ # removed
+ self.assertEqual(self.category.get_absolute_url(),
+ '/blog/category/{0}/'.format(self.category.slug))
+
class CategoryTitleTestCase(TestCase):
"""Tests for the ``CategoryTitle`` model class."""

0 comments on commit d19e1cf

Please sign in to comment.