diff options
author | Yaroslav de la Peña Smirnov <contact@yaroslavps.com> | 2018-07-15 02:39:43 +0300 |
---|---|---|
committer | Yaroslav de la Peña Smirnov <contact@yaroslavps.com> | 2018-07-15 02:39:43 +0300 |
commit | c9d2bbeea44a9e691ba214d0be8566fe0d59fd77 (patch) | |
tree | 51dbe4df410e219b1b0e295163d543da6d4930ce | |
parent | c9832e71790c7d93fcf3c512de8327dda3748e70 (diff) | |
download | w3blog-c9d2bbeea44a9e691ba214d0be8566fe0d59fd77.tar.gz w3blog-c9d2bbeea44a9e691ba214d0be8566fe0d59fd77.zip |
languages list in post view
-rwxr-xr-x | weblog/templates/weblog/post.html | 12 | ||||
-rwxr-xr-x | weblog/views.py | 16 |
2 files changed, 23 insertions, 5 deletions
diff --git a/weblog/templates/weblog/post.html b/weblog/templates/weblog/post.html index d602223..5a389f8 100755 --- a/weblog/templates/weblog/post.html +++ b/weblog/templates/weblog/post.html @@ -5,6 +5,18 @@ <div class="container-fluid blogpost"> <h2>{% if post_translation %}{{ post_translation.title }}{% else %}{{ post.title }}{% endif %}</h2> <p class="publish-info">{% blocktrans with publish_date=post.publish_date %}Published on {{ publish_date }}{% endblocktrans %}{% if post_author %}{% blocktrans with author=post_author context 'Written by (Author)' %}, by {{ author }}{% endblocktrans %}{% endif %}</p> + {% if languages %} + <form> + <div class="form-group"> + <label for="post-languages">{% trans 'Read in another language' %}</label> + <select class="form-control" id="post-languages" name="post-language"> + {% for lang in post_languages %} + <option value="{{ lang[0] }}">{{ lang[1] }}</option> + {% endfor %} + </select> + </div> + </form> + {% endif %} <hr> {% if post_translation %} {{ post_translation.content|safe }} diff --git a/weblog/views.py b/weblog/views.py index d2bdb2d..922e8c5 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: @@ -216,15 +216,21 @@ def PostView(request, category_slug, post_slug, language=None): 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,] - context_dict['all_languages'] = settings.LANGUAGES + 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) + 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: |