diff options
Diffstat (limited to 'weblog/views.py')
-rwxr-xr-x | weblog/views.py | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/weblog/views.py b/weblog/views.py index e082d05..95558fc 100755 --- a/weblog/views.py +++ b/weblog/views.py @@ -47,7 +47,7 @@ def Index(request, **kwargs): all_pages = all_pages.filter(published=True, publish_date__lte=now, publish_date__month=month) context_dict['breadcrumbs'].append({'url': reverse('weblog:ArchiveIndex', kwargs={'year': year, 'month': month}), 'name': MONTHS[int(month)-1]}) - # Check how many blog posts are there in total, to calculate into how many pages + # Check how many blog posts there are in total, to calculate into how many pages # the index needs to be divided post_count = all_pages.count() if post_count < 1: @@ -153,10 +153,13 @@ 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() + context_dict['post_url'] = post.get_absolute_url() post_translations = Translation.objects.filter(post=post) category = None current_language = translation.get_language() @@ -214,12 +217,21 @@ def PostView(request, category_slug, post_slug): return render(request, 'weblog/post.html', context_dict) orig_lang = post.original_language if len(orig_lang) < 2: - orig_lang = settings.LANGUAGE_CODE[0:2] - context_dict['languages'] = [orig_lang,] + orig_lang = settings.LANGUAGE_CODE[:2] + context_dict['post_languages'] = [] + post_languages = [] for post_translation in post_translations: - context_dict['languages'].append(post_translation.language) - if current_language[0:2] == post_translation.language[0:2]: + post_languages.append(post_translation.language[:2].lower()) + 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 + for lang in settings.LANGUAGES: + if lang[0][:2] == orig_lang.lower(): + context_dict['post_languages'].append(lang) + continue + if lang[0][:2] in post_languages: + context_dict['post_languages'].append(lang) if 'post_translation' in context_dict: context_dict['breadcrumbs'].append({'url': post.get_absolute_url(), 'name': post_translation.title}) else: |