Ignore:
Timestamp:
10 Mar 2012, 04:29:35 (13 years ago)
Author:
uli
Message:

Do utility lookup only once in a session.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/language.py

    r7819 r7832  
    1616## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    1717##
    18 
     18"""Handle language as requested by users.
     19"""
    1920import grokcore.component
    2021from zope.component import getUtility
    2122from zope.publisher.interfaces.browser import IBrowserRequest
     23from zope.session.interfaces import ISession
    2224from zope.i18n.interfaces import IUserPreferredLanguages
    2325from waeup.kofa.configuration import ConfigurationContainer
     
    3032
    3133    def getPreferredLanguages(self):
    32         portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    33 
    3434        # This an adapter for the request, so self.context is the request.
    3535        request = self.context
    3636
    3737        # Extract the preferred language from a cookie:
    38         lang = request.cookies.get('kofa.language', portal_language)
     38        lang = request.cookies.get('kofa.language', None)
     39        if lang is None:
     40            lang = getUtility(IKofaUtils).PORTAL_LANGUAGE
     41            request.response.setCookie('kofa.language', lang, path='/')
    3942
    4043        # According to IUserPreferredLanguages, we must return a list.
Note: See TracChangeset for help on using the changeset viewer.