[Zope3-Users] User preferences for languages- possible?
Vinny
vinny-mail-01+zope3users at palaceofretention.ca
Fri Feb 23 00:48:08 EST 2007
Hi,
[much snippage]
Try adding the code snippet shown below. It detects
whether a principal is available and only checks
for preferences if there is one.
class BrowserFormLanguages(BrowserLanguages):
implements(IModifiableUserPreferredLanguages)
language_store = [] # ignore this for now
def __init__(self, request):
super(BrowserFormLanguages, self).__init__(request)
print "created BFL", self.language_store
def setPreferredLanguages(self, langs):
#prefs = UserPreferences()
#print prefs.eods.general.language
self.language_store = langs
print "set language", self.language_store
def getPreferredLanguages(self):
langs =
super(BrowserFormLanguages,self).getPreferredLanguages()
if self.language_store:
langs = self.language_store + langs
form_lang = self.request.get("Language", None)
if form_lang is not None:
langs.insert(0, form_lang)
# LOOK HERE
# don't look up preferences unless we have
# something which _has_ preferences!
if self.request.principal != None:
prefs = UserPreferences()
print "Prefs", repr(prefs)
# substitute your own 'None' value case.
if prefs.eods.general.language is not None:
langs.insert(0, prefs.eods.general.language)
print "My prefered override", langs
return langs
The principal annotation error seems to be avoided (since
we've made sure we have a principal).
The language does seem to be set to the preference for page
displays, so what Philipp said about being able to ignore
uninteresting things until we've traversed far enough
was a good hint.
Vinny
More information about the Zope3-users
mailing list