diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index 706be47..44b3545 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -234,10 +234,10 @@ class Post(KnockerModel, ModelMeta, TranslatableModel): super(Post, self).save_translation(translation, *args, **kwargs) def get_absolute_url(self, lang=None): - if not lang or lang not in self.get_available_languages(): - lang = self.get_current_language() if not lang or lang not in self.get_available_languages(): lang = get_language() + if not lang or lang not in self.get_available_languages(): + lang = self.get_current_language() with switch_language(self, lang): category = self.categories.first() kwargs = {} diff --git a/tests/test_models.py b/tests/test_models.py index a03dd1e..c5aeb52 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -608,6 +608,20 @@ class ModelsTest(BaseTest): post.app_config = self.app_config_1 self.assertTrue(re.match(r'.*/%s/$' % post.slug, post.get_absolute_url())) + def test_url_language(self): + self.get_pages() + post = self._get_post(self._post_data[0]['en']) + post = self._get_post(self._post_data[0]['it'], post, 'it') + + with override('it'): + self.assertEqual(post.get_current_language(), 'en') + self.assertEqual(post.get_absolute_url(), post.get_absolute_url('it')) + + post.set_current_language('it') + with override('en'): + self.assertEqual(post.get_current_language(), 'it') + self.assertEqual(post.get_absolute_url(), post.get_absolute_url('en')) + def test_manager(self): self.get_pages() post1 = self._get_post(self._post_data[0]['en'])