#
# Copyright (C) 2010 by Johan De Taeye
#
# This library is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# file : $URL: https://frepple.svn.sourceforge.net/svnroot/frepple/tags/0.8.0/contrib/django/freppledb/common/middleware.py $
# revision : $LastChangedRevision: 1198 $ $LastChangedBy: jdetaeye $
# date : $LastChangedDate: 2010-03-07 10:52:39 +0100 (Sun, 07 Mar 2010) $
from django.contrib.auth.models import AnonymousUser
from django.middleware.locale import LocaleMiddleware
from django.utils import translation
class LocaleMiddleware(DjangoLocaleMiddleware):
"""
This middleware extends the Django default locale middleware:
- Support for a user preference that overrides the browser default.
"""
def process_request(self, request):
if isinstance(request.user,AnonymousUser):
language = 'auto'
else:
language = request.user.get_profile().language
if language == 'auto':
language = translation.get_language_from_request(request)
translation.activate(language)
request.LANGUAGE_CODE = translation.get_language()
|