Merge pull request #341 from nephila/hotfix/post_language

Fix post language url
This commit is contained in:
Iacopo Spalletti 2017-01-02 09:43:41 +01:00 committed by GitHub
commit 20ea302645
8 changed files with 30 additions and 6 deletions

View file

@ -7,7 +7,9 @@ import os
from tempfile import mkdtemp
def gettext(s): return s
def gettext(s):
return s
HELPER_SETTINGS = dict(
ROOT_URLCONF='tests.test_utils.urls',
@ -138,5 +140,6 @@ def run():
from djangocms_helper import runner
runner.cms('djangocms_blog')
if __name__ == '__main__':
run()

View file

@ -308,6 +308,7 @@ class BlogConfigAdmin(BaseAppHookConfig, TranslatableAdmin):
menu_pool.clear(all=True)
return super(BlogConfigAdmin, self).save_model(request, obj, form, change)
admin.site.register(BlogCategory, BlogCategoryAdmin)
admin.site.register(Post, PostAdmin)
admin.site.register(BlogConfig, BlogConfigAdmin)

View file

@ -134,4 +134,6 @@ class BlogConfigForm(AppDataForm):
label=_('Send notifications on post update'), required=False, initial=False,
help_text=_('Emits a desktop notification -if enabled- when editing a published post')
)
setup_config(BlogConfigForm, BlogConfig)

View file

@ -11,6 +11,7 @@ from .menu import BlogCategoryMenu
from .settings import get_setting
@apphook_pool.register
class BlogApp(AutoCMSAppMixin, CMSConfigApp):
name = _('Blog')
urls = ['djangocms_blog.urls']
@ -28,5 +29,6 @@ class BlogApp(AutoCMSAppMixin, CMSConfigApp):
'object_name': get_setting('DEFAULT_OBJECT_NAME')
},
}
apphook_pool.register(BlogApp)
BlogApp.setup()

View file

@ -104,8 +104,6 @@ class BlogCategoryMenu(CMSAttachMenu):
return nodes
menu_pool.register_menu(BlogCategoryMenu)
class BlogNavModifier(Modifier):
"""
@ -159,7 +157,9 @@ class BlogNavModifier(Modifier):
node.selected = True
return nodes
menu_pool.register_modifier(BlogNavModifier)
menu_pool.register_menu(BlogCategoryMenu)
def clear_menu_cache(**kwargs):
@ -168,5 +168,6 @@ def clear_menu_cache(**kwargs):
"""
menu_pool.clear(all=True)
post_save.connect(clear_menu_cache, sender=BlogCategory)
post_delete.connect(clear_menu_cache, sender=BlogCategory)

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

@ -20,6 +20,7 @@ def get_urls():
)
return details
detail_urls = get_urls()
urlpatterns = [

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