From 81a201dcadd7223a81f7ca8492134407d029712f Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Fri, 28 Mar 2014 12:25:42 +0100 Subject: [PATCH] [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. --- gen/__init__.py | 4 ++++ gen/installer.py | 9 +++++++-- gen/mixins/__init__.py | 5 +++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gen/__init__.py b/gen/__init__.py index 021aef7..6f3df74 100644 --- a/gen/__init__.py +++ b/gen/__init__.py @@ -171,4 +171,8 @@ class Config: # When using a LDAP for authenticating users, place an instance of class # LdapConfig above in the field below. 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'] # ------------------------------------------------------------------------------ diff --git a/gen/installer.py b/gen/installer.py index f940a5c..fac536c 100644 --- a/gen/installer.py +++ b/gen/installer.py @@ -66,8 +66,13 @@ class ZopeInstaller: # the one from the app-specific folder is chosen. j = os.path.join uiFolders = [j(j(appy.getPath(), 'gen'), 'ui')] - appUi = j(self.config.diskFolder, 'ui') - if os.path.exists(appUi): uiFolders.insert(0, appUi) + for uiFolder in self.config.appConfig.uiFolders: + 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 root, dirs, files in os.walk(ui): folderName = root[len(ui):] diff --git a/gen/mixins/__init__.py b/gen/mixins/__init__.py index f216b22..eca2424 100644 --- a/gen/mixins/__init__.py +++ b/gen/mixins/__init__.py @@ -1470,7 +1470,8 @@ class BaseMixin: def getUserLanguage(self): '''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 # present, it means that the user has explicitly chosen this language # via the language selector. @@ -1484,7 +1485,7 @@ class BaseMixin: # language preferences as defined in the user's browser. Several # languages can be listed, from most to less wanted. 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('-')] return res