From 5b255ce55da0d30bbe8d97de9f6ace6e57564fa3 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Sun, 3 Jun 2012 21:55:26 +0200 Subject: [PATCH] [gen] Added boolean Tool.loadTranslationsAtStartup that, if False, prevents to overwrite, on a production site, translations edited through-the-web by users. If True, at every Zope startup, Translation objects are overwritten by the content of their corresponding po files on disk. --- gen/installer.py | 29 ++++++++++++++++------------- gen/model.py | 13 +++++++------ gen/ui/icons.pt | 1 + 3 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 gen/ui/icons.pt diff --git a/gen/installer.py b/gen/installer.py index 0af8a41..10dbe09 100644 --- a/gen/installer.py +++ b/gen/installer.py @@ -326,23 +326,26 @@ class ZopeInstaller: appyTool.create('translations', noSecurity=True, id=language, title=title) appyTool.log('Translation object created for "%s".' % language) - # Now, we synchronise every Translation object with the corresponding - # "po" file on disk. - appFolder = self.config.diskFolder - appName = self.config.PROJECTNAME - i18nFolder = os.path.join(appFolder, 'tr') - for translation in appyTool.translations: - # Get the "po" file - poName = '%s-%s.po' % (appName, translation.id) - poFile = PoParser(os.path.join(i18nFolder, poName)).parse() - for message in poFile.messages: - setattr(translation, message.id, message.getMessage()) - appyTool.log('Translation "%s" updated from "%s".' % \ - (translation.id, poName)) # Execute custom installation code if any if hasattr(appyTool, 'onInstall'): appyTool.onInstall() + # Now, if required, we synchronise every Translation object with the + # corresponding "po" file on disk. + if appyTool.loadTranslationsAtStartup: + appFolder = self.config.diskFolder + appName = self.config.PROJECTNAME + i18nFolder = os.path.join(appFolder, 'tr') + for translation in appyTool.translations: + # Get the "po" file + poName = '%s-%s.po' % (appName, translation.id) + poFile = PoParser(os.path.join(i18nFolder, poName)).parse() + for message in poFile.messages: + setattr(translation, message.id, message.getMessage()) + appyTool.log('Translation "%s" updated from "%s".' % \ + (translation.id, poName)) + + def configureSessions(self): '''Configure the session machinery.''' # Register a function warning us when a session object is deleted. When diff --git a/gen/model.py b/gen/model.py index 7655e4c..0de3005 100644 --- a/gen/model.py +++ b/gen/model.py @@ -213,9 +213,9 @@ toolFieldPrefixes = ('defaultValue', 'podTemplate', 'formats', 'resultColumns', 'searchFields', 'optionalFields', 'showWorkflow', 'showAllStatesInPhase') defaultToolFields = ('title', 'mailHost', 'mailEnabled', 'mailFrom', - 'appyVersion', 'users', 'groups', 'translations', 'pages', - 'unoEnabledPython','openOfficePort', - 'numberOfResultsPerPage') + 'appyVersion', 'users', 'groups', 'translations', + 'loadTranslationsAtStartup', 'pages', 'unoEnabledPython', + 'openOfficePort', 'numberOfResultsPerPage') class Tool(ModelClass): # In a ModelClass we need to declare attributes in the following list. @@ -242,10 +242,11 @@ class Tool(ModelClass): page=gen.Page('groups', show=isManager), queryable=True, queryFields=('title', 'login'), showHeaders=True, shownInfo=('title', 'login', 'roles')) + pt = gen.Page('translations', show=isManager) translations = gen.Ref(Translation, multiplicity=(0,None), add=False, - link=False, show='view', - back=gen.Ref(attribute='trToTool', show=False), - page=gen.Page('translations', show=isManager)) + link=False, show='view', page=pt, + back=gen.Ref(attribute='trToTool', show=False)) + loadTranslationsAtStartup = gen.Boolean(default=True, show=False, page=pt) pages = gen.Ref(Page, multiplicity=(0,None), add=True, link=False, show='view', back=gen.Ref(attribute='toTool3', show=False), page=gen.Page('pages', show=isManager)) diff --git a/gen/ui/icons.pt b/gen/ui/icons.pt new file mode 100644 index 0000000..dbf8d58 --- /dev/null +++ b/gen/ui/icons.pt @@ -0,0 +1 @@ +