Commit 35b36992 by Őry Máté

school: user configurable locale support

parent 60ceab11
...@@ -92,6 +92,7 @@ TEMPLATE_LOADERS = ( ...@@ -92,6 +92,7 @@ TEMPLATE_LOADERS = (
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.transaction.TransactionMiddleware', 'django.middleware.transaction.TransactionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
......
...@@ -35,4 +35,5 @@ urlpatterns = patterns('', ...@@ -35,4 +35,5 @@ urlpatterns = patterns('',
url(r'^ajax/store/newFolder$', 'store.views.ajax_new_folder', name='store_ajax_new_folder'), url(r'^ajax/store/newFolder$', 'store.views.ajax_new_folder', name='store_ajax_new_folder'),
url(r'^ajax/store/quota$', 'store.views.ajax_quota', name='store_ajax_quota'), url(r'^ajax/store/quota$', 'store.views.ajax_quota', name='store_ajax_quota'),
url(r'^ajax/store/rename$', 'store.views.ajax_rename', name='store_ajax_rename'), url(r'^ajax/store/rename$', 'store.views.ajax_rename', name='store_ajax_rename'),
url(r'^language/(?P<lang>[-A-Za-z]+)/$', 'school.views.language', name='language'),
) )
...@@ -31,14 +31,11 @@ ...@@ -31,14 +31,11 @@
{% else %} {% else %}
<a href="/login/">Bejelentkezés</a>. <a href="/login/">Bejelentkezés</a>.
{% endif %} {% endif %}
<!--{% if lang == 'hu' %} {% if lang == 'hu' %}
<a href="/language/en-US/">In English</a>. <a href="/language/en/">In English</a>.
{% else %} {% else %}
<a href="/language/hu/">Magyarul</a>. <a href="/language/hu/">Magyarul</a>.
{% if autolang %}
<p style="position: absolute; top: 40px; right: 1em;" class="triangle-border top">Böngészője kifejezetten angol tartalmat kért.<br/>A <a href="/language/hu/">magyar változat</a> részletesebb és frissebb!</p>
{% endif %} {% endif %}
{% endif %}-->
</p> </p>
</div> </div>
{% endblock %} {% endblock %}
......
...@@ -114,3 +114,24 @@ def login(request): ...@@ -114,3 +114,24 @@ def login(request):
response = redirect(redirect_to) response = redirect(redirect_to)
response.set_cookie(settings.LANGUAGE_COOKIE_NAME, p.language, 10*365*24*3600) response.set_cookie(settings.LANGUAGE_COOKIE_NAME, p.language, 10*365*24*3600)
return response return response
def language(request, lang):
cname = settings.LANGUAGE_COOKIE_NAME
if not cname:
cname = 'django_language'
redirect_to = request.META['HTTP_REFERER']
r = redirect(redirect_to)
if not redirect_to:
redirect_to = "/"
try:
p = Person.objects.get(user=request.user)
p.language = lang
p.save()
except ValidationError as e:
messages.error(e)
except:
messages.error(_("Could not found Person object."))
r.set_cookie(cname, lang, 10*365*24*3600)
return r
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment