Merge lp:~daker/loco-team-portal/fix.648296-648293 into lp:loco-team-portal

Proposed by Adnane Belmadiaf
Status: Merged
Approved by: Adnane Belmadiaf
Approved revision: 559
Merged at revision: 557
Proposed branch: lp:~daker/loco-team-portal/fix.648296-648293
Merge into: lp:loco-team-portal
Diff against target: 179 lines (+69/-21)
5 files modified
loco_directory/common/context_processors.py (+11/-3)
loco_directory/common/utils.py (+36/-3)
loco_directory/common/views.py (+18/-11)
loco_directory/settings.py (+2/-2)
loco_directory/templates/base.html (+2/-2)
To merge this branch: bzr merge lp:~daker/loco-team-portal/fix.648296-648293
Reviewer Review Type Date Requested Status
LoCo Team Portal Developers Pending
Review via email: mp+133769@code.launchpad.net

Commit message

Fixed the Languages switcher

To post a comment you must log in.
557. By Adnane Belmadiaf

* Remove print statement

558. By Adnane Belmadiaf

* Removed another print statement

559. By Adnane Belmadiaf

* Fixed a typo

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'loco_directory/common/context_processors.py'
--- loco_directory/common/context_processors.py 2012-06-01 23:45:18 +0000
+++ loco_directory/common/context_processors.py 2012-11-09 23:49:20 +0000
@@ -1,8 +1,9 @@
1# context processors for loco-directory1# -*- coding: utf-8 -*-
2# see: http://docs.djangoproject.com/en/dev/ref/settings/#setting-TEMPLATE_CONTEXT_PROCESSORS
3# to use this processor, add "common.context_processors.loco_version" to your variable TEMPLATE_CONTEXT_PROCESSORS in your settings file
42
5from django.conf import settings3from django.conf import settings
4from django.utils.translation import to_locale, get_language
5
6from utils import get_languages
67
78
8def loco_version(request):9def loco_version(request):
@@ -54,3 +55,10 @@
54 from common.forms import SiteSearchForm55 from common.forms import SiteSearchForm
55 search_form = SiteSearchForm(data=request.GET)56 search_form = SiteSearchForm(data=request.GET)
56 return {'search_form': search_form}57 return {'search_form': search_form}
58
59
60def languages_menu(request):
61 """
62 Return the languages list.
63 """
64 return {'languages': get_languages(), 'LOCALE': to_locale(get_language())}
57\ No newline at end of file65\ No newline at end of file
5866
=== modified file 'loco_directory/common/utils.py'
--- loco_directory/common/utils.py 2012-06-01 23:45:18 +0000
+++ loco_directory/common/utils.py 2012-11-09 23:49:20 +0000
@@ -1,11 +1,14 @@
1# -*- coding: utf-8 -*-
2
3import subprocess
4import datetime
1import email5import email
2import os6import os
3from copy import deepcopy7from copy import deepcopy
4import subprocess
5import datetime
6
7from django.conf import settings8from django.conf import settings
89
10languages = None
11
912
10def write_log(job_name, log):13def write_log(job_name, log):
11 stamp_dir = os.path.join(settings.PROJECT_PATH, 'data')14 stamp_dir = os.path.join(settings.PROJECT_PATH, 'data')
@@ -106,3 +109,33 @@
106 def reset(self):109 def reset(self):
107 self.index = -1110 self.index = -1
108 return ''111 return ''
112
113
114def check_for_language(lang_code):
115 """
116 Checks whether there is a global language file for the given language code.
117 """
118 globalpath = os.path.join(settings.PROJECT_PATH, 'locale')
119 for dirnames in os.listdir(globalpath):
120 if dirnames == lang_code:
121 for dirpath_local, dirnames_local, filenames in os.walk(os.path.join(globalpath, dirnames, 'LC_MESSAGES')):
122 if 'django.mo' in filenames:
123 return True
124 else:
125 return False
126
127def get_languages():
128 """
129 Return a language list.
130 """
131 global languages
132 if languages is None:
133 from teams.models import Language
134 languages = {}
135 Languages = Language.objects.order_by('name')
136 for language in Languages:
137 if check_for_language(language.code):
138 languages[language.code] = language.name
139 languages['en_US'] = 'English'
140 languages = sorted([(value,key) for (key,value) in languages.items()])
141 return languages
109142
=== modified file 'loco_directory/common/views.py'
--- loco_directory/common/views.py 2012-06-01 23:45:18 +0000
+++ loco_directory/common/views.py 2012-11-09 23:49:20 +0000
@@ -4,8 +4,9 @@
4from django.template import RequestContext4from django.template import RequestContext
5from django.template.loader import render_to_string5from django.template.loader import render_to_string
6from django.contrib.auth import logout6from django.contrib.auth import logout
7from django.conf import settings
8from django.utils import translation
7from django.utils.translation import check_for_language9from django.utils.translation import check_for_language
8from django.conf import settings
910
10try:11try:
11 from django_openid_auth.exceptions import (12 from django_openid_auth.exceptions import (
@@ -78,19 +79,25 @@
78 return HttpResponseRedirect('/')79 return HttpResponseRedirect('/')
7980
8081
81def set_language(request):82def set_language(request, next=None):
82 """83 """
83 Change the language for a user84 Change the language for a user
84 """85 """
85 next_url = request.META.get('HTTP_REFERER', None)86 if not next:
86 if not next_url:87 next = request.REQUEST.get('next', None)
87 next_url = '/'88 if not next:
88 response = HttpResponseRedirect(next_url)89 next = request.META.get('HTTP_REFERER', None)
89 lang = request.GET.get('lang', '')90 if not next:
90 if check_for_language(lang):91 next = '/'
91 if hasattr(request, 'session'):92 response = HttpResponseRedirect(next)
92 request.session['django_language'] = lang93 if request.method == 'GET':
93 response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang)94 lang_code = request.GET.get('lang', '')
95 if lang_code and check_for_language(lang_code):
96 if hasattr(request, 'session'):
97 request.session['django_language'] = lang_code
98 else:
99 response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
100 translation.activate(lang_code)
94 return response101 return response
95102
96103
97104
=== modified file 'loco_directory/settings.py'
--- loco_directory/settings.py 2012-11-05 21:16:15 +0000
+++ loco_directory/settings.py 2012-11-09 23:49:20 +0000
@@ -29,7 +29,7 @@
2929
30# Check for necessary modules30# Check for necessary modules
31modules = {31modules = {
32 'pytz': 'python-tz', 32 'pytz': 'python-tz',
33 'vobject': 'python-vobject',33 'vobject': 'python-vobject',
34 }34 }
3535
@@ -106,7 +106,6 @@
106106
107MIDDLEWARE_CLASSES = (107MIDDLEWARE_CLASSES = (
108 'django.middleware.common.CommonMiddleware',108 'django.middleware.common.CommonMiddleware',
109 'django.middleware.locale.LocaleMiddleware',
110 'django.contrib.sessions.middleware.SessionMiddleware',109 'django.contrib.sessions.middleware.SessionMiddleware',
111 'django.contrib.auth.middleware.AuthenticationMiddleware',110 'django.contrib.auth.middleware.AuthenticationMiddleware',
112)111)
@@ -124,6 +123,7 @@
124 "common.context_processors.login_redirect",123 "common.context_processors.login_redirect",
125 "common.context_processors.url_base",124 "common.context_processors.url_base",
126 "common.context_processors.site_search",125 "common.context_processors.site_search",
126 "common.context_processors.languages_menu",
127)127)
128128
129ROOT_URLCONF = 'loco_directory.urls'129ROOT_URLCONF = 'loco_directory.urls'
130130
=== modified file 'loco_directory/templates/base.html'
--- loco_directory/templates/base.html 2012-09-25 21:01:12 +0000
+++ loco_directory/templates/base.html 2012-11-09 23:49:20 +0000
@@ -81,8 +81,8 @@
81 <form name="lang-switcher" style="text-align:right;" action="/language/" method="get">81 <form name="lang-switcher" style="text-align:right;" action="/language/" method="get">
82 <input name="next" type="hidden" value="{{ request.path }}" />82 <input name="next" type="hidden" value="{{ request.path }}" />
83 <select name="lang" onchange="document.forms['lang-switcher'].submit()">83 <select name="lang" onchange="document.forms['lang-switcher'].submit()">
84 {% for lang in LANGUAGES %}84 {% for lang in languages %}
85 <option value="{{ lang.0 }}"{% ifequal LANGUAGE_CODE lang.0 %} selected="selected"{% endifequal %}>{{ lang.1 }}</option>85 <option value="{{ lang.1 }}"{% ifequal LOCALE lang.1 %} selected="selected"{% endifequal %}>{{ lang.0 }}</option>
86 {% endfor %}86 {% endfor %}
87 </select>87 </select>
88 </form>88 </form>

Subscribers

People subscribed via source and target branches