From 8fd79ffe610d4fce69913fd167d437322347c3d4 Mon Sep 17 00:00:00 2001 From: Yaroslsav-95 Date: Fri, 22 Jun 2018 20:20:50 +0300 Subject: read post in another language (templates missing links) --- setup.py | 2 +- weblog/urls.py | 3 ++- weblog/views.py | 8 ++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 8aa8e04..7b7557d 100755 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) setup( name='django-weblog', - version='0.3.1', + version='0.3-postlang.1', packages=find_packages(), include_package_data=True, license='BSD License', diff --git a/weblog/urls.py b/weblog/urls.py index 643e8c7..71206bb 100755 --- a/weblog/urls.py +++ b/weblog/urls.py @@ -9,4 +9,5 @@ urlpatterns = [ url(r'^(?P[0-9]{4})/(?P[0-9]{1,2})/$', views.Index, name='ArchiveIndex'), url(r'^(?P[-\w]+)/$', views.Index, name='CategoryIndex'), url(r'^(?P[-\w]+)/(?P[-\w]+)/$', views.PostView, name='PostView'), -] \ No newline at end of file + url(r'^(?P[-\w]+)/(?P[-\w]+)/(?P[-\w]+)/$', views.PostView, name='TranslationView'), +] diff --git a/weblog/views.py b/weblog/views.py index e082d05..f28f201 100755 --- a/weblog/views.py +++ b/weblog/views.py @@ -153,7 +153,9 @@ def Index(request, **kwargs): return render(request, 'weblog/index.html', context_dict) -def PostView(request, category_slug, post_slug): +def PostView(request, category_slug, post_slug, language=None): + if language and not IS_MULTILINGUAL: + redirect('weblog:PostView', category_slug=category_slug, post_slug=post_slug) post = get_object_or_404(BlogPost, slug=post_slug) context_dict = blog_settings.copy() context_dict['comment_form'] = PostCommentForm() @@ -218,7 +220,9 @@ def PostView(request, category_slug, post_slug): context_dict['languages'] = [orig_lang,] for post_translation in post_translations: context_dict['languages'].append(post_translation.language) - if current_language[0:2] == post_translation.language[0:2]: + if language and language == post_translation.language[0:2]: + context_dict['post_translation'] = post_translation + elif current_language[0:2] == post_translation.language[0:2]: context_dict['post_translation'] = post_translation if 'post_translation' in context_dict: context_dict['breadcrumbs'].append({'url': post.get_absolute_url(), 'name': post_translation.title}) -- cgit v1.2.3