[gen] Allow to specify several folder within an app where to store static ui content (js, css, images). [gen] When browser settings are ignored or absent, default language is the first one listed in Config.languages.

This commit is contained in:
Gaetan Delannay 2014-03-28 12:25:42 +01:00
parent d5a9450d72
commit 81a201dcad
3 changed files with 14 additions and 4 deletions

View file

@ -171,4 +171,8 @@ class Config:
# When using a LDAP for authenticating users, place an instance of class # When using a LDAP for authenticating users, place an instance of class
# LdapConfig above in the field below. # LdapConfig above in the field below.
ldap = None ldap = None
# For an app, the default folder where to look for static content for the
# user interface (CSS, Javascript and image files) is folder "ui" within
# this app.
uiFolders = ['ui']
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View file

@ -66,8 +66,13 @@ class ZopeInstaller:
# the one from the app-specific folder is chosen. # the one from the app-specific folder is chosen.
j = os.path.join j = os.path.join
uiFolders = [j(j(appy.getPath(), 'gen'), 'ui')] uiFolders = [j(j(appy.getPath(), 'gen'), 'ui')]
appUi = j(self.config.diskFolder, 'ui') for uiFolder in self.config.appConfig.uiFolders:
if os.path.exists(appUi): uiFolders.insert(0, appUi) if uiFolder.startswith('..'):
folder = j(os.path.dirname(self.config.diskFolder),uiFolder[3:])
else:
folder = j(self.config.diskFolder, uiFolder)
if os.path.exists(folder):
uiFolders.insert(0, folder)
for ui in uiFolders: for ui in uiFolders:
for root, dirs, files in os.walk(ui): for root, dirs, files in os.walk(ui):
folderName = root[len(ui):] folderName = root[len(ui):]

View file

@ -1470,7 +1470,8 @@ class BaseMixin:
def getUserLanguage(self): def getUserLanguage(self):
'''Gets the language (code) of the current user.''' '''Gets the language (code) of the current user.'''
if not hasattr(self, 'REQUEST'): return 'en' if not hasattr(self, 'REQUEST'):
return self.getProductConfig().appConfig.languages[0]
# Try the value which comes from the cookie. Indeed, if such a cookie is # Try the value which comes from the cookie. Indeed, if such a cookie is
# present, it means that the user has explicitly chosen this language # present, it means that the user has explicitly chosen this language
# via the language selector. # via the language selector.
@ -1484,7 +1485,7 @@ class BaseMixin:
# language preferences as defined in the user's browser. Several # language preferences as defined in the user's browser. Several
# languages can be listed, from most to less wanted. # languages can be listed, from most to less wanted.
res = self.REQUEST.get('HTTP_ACCEPT_LANGUAGE', None) res = self.REQUEST.get('HTTP_ACCEPT_LANGUAGE', None)
if not res: return 'en' if not res: return self.getProductConfig().appConfig.languages[0]
if ',' in res: res = res[:res.find(',')] if ',' in res: res = res[:res.find(',')]
if '-' in res: res = res[:res.find('-')] if '-' in res: res = res[:res.find('-')]
return res return res