SHARE
TWEET

Language middleware

a guest Nov 6th, 2012 41 Never
  1.     def process_request(self, request):
  2.         if hasattr(request, 'user'):
  3.             # FIXME: kinda hacky the way it determines user preference
  4.             if not request.user.is_anonymous():
  5.                 pref_lang = request.user.userprofile.language - 1
  6.                 pref_lang_str = settings.LANGUAGES[pref_lang][0]
  7.                 if hasattr(request, 'session'):
  8.                     request.session['django_language'] = pref_lang_str
  9.         return None
RAW Paste Data
Top