Fix post language url

This commit is contained in:
Iacopo Spalletti 2017-01-02 00:09:25 +01:00
parent 9e7f66b3f5
commit 446b4b83e9
No known key found for this signature in database
GPG key ID: BDCBC2EB289F60C6
2 changed files with 16 additions and 2 deletions

View file

@ -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 = {}

View file

@ -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'])