def get(self): uuid = self.getTranslationUuid() if isLanguageIndependent(self.field) and uuid: manager = TranslationManager(uuid) result = manager.get_translations() if len(result) >= 1: orig_lang = list(result.keys())[0] obj = result[orig_lang] name = self.field.__name__ # XXX # this does not work with behaviors, if other than direct # attribute storage was used. try: value = getattr(aq_base(obj), name) except AttributeError: pass else: return value if self.field.default is None: return NO_VALUE return self.field.default
def get(self): uuid = self.getTranslationUuid() if isLanguageIndependent(self.field) and uuid: manager = TranslationManager(uuid) result = manager.get_translations() if len(result) >= 1: orig_lang = result.keys()[0] obj = result[orig_lang] name = self.field.__name__ # XXX # this does not work with behaviors, if other than direct # attribute storage was used. try: value = getattr(aq_base(obj), name) except AttributeError: pass else: return value if self.field.default is None: return NO_VALUE return self.field.default
def get(self): uuid = self.getTranslationUuid() if isLanguageIndependent(self.field) and uuid: manager = TranslationManager(uuid) result = manager.get_translations() if len(result) >= 1: orig_lang = result.keys()[0] obj = result[orig_lang] name = self.field.__name__ try: value = getattr(aq_base(obj), name) except AttributeError: pass else: return value if self.field.default is None: return NO_VALUE return self.field.default
def getClosestDestination(self): """Get the "closest translated object" URL. """ # We should travel the parent chain using the catalog here, # but I think using the acquisition chain is faster # (or well, __parent__ pointers) because the catalog # would require a lot of queries, while technically, # having done traversal up to this point you should # have the objects in memory already # As we don't have any content object we are going to look # for the best option site = getSite() root = getToolByName(site, 'portal_url') ltool = getToolByName(site, 'portal_languages') # We are using TranslationManager to get the translations of a # string tg manager = TranslationManager(self.tg) context = None languages = manager.get_translations() if len(languages) == 0: # If there is no results there are no translations # we move to portal root return self.wrapDestination(root(), postpath=False) # We are going to see if there is the preferred language translation # Otherwise we get the first as context to look for translation prefered = ltool.getPreferredLanguage(self.request) if prefered in languages: context = languages[prefered] else: context = languages[languages.keys()[0]] checkPermission = getSecurityManager().checkPermission chain = self.getParentChain(context) for item in chain: if ISiteRoot.providedBy(item) \ and not ILanguageRootFolder.providedBy(item): # We do not care to get a permission error # if the whole of the portal cannot be viewed. # Having a permission issue on the root is fine; # not so much for everything else so that is checked there return self.wrapDestination(item.absolute_url()) elif IFactoryTempFolder.providedBy(item) or \ IFactoryTool.providedBy(item): # TempFolder or portal_factory, can't have a translation continue try: canonical = ITranslationManager(item) except TypeError: if not ITranslatable.providedBy(item): # In case there it's not translatable go to parent # This solves the problem when a parent is not # ITranslatable continue else: raise translation = canonical.get_translation(self.lang) if translation and ( INavigationRoot.providedBy(translation) or bool(checkPermission('View', translation)) ): # Not a direct translation, therefore no postpath # (the view might not exist on a different context) return self.wrapDestination(translation.absolute_url(), postpath=False) # Site root's the fallback return self.wrapDestination(root(), postpath=False)
def getClosestDestination(self): """Get the "closest translated object" URL. """ # We should travel the parent chain using the catalog here, # but I think using the acquisition chain is faster # (or well, __parent__ pointers) because the catalog # would require a lot of queries, while technically, # having done traversal up to this point you should # have the objects in memory already # As we don't have any content object we are going to look # for the best option site = getSite() root = getToolByName(site, 'portal_url') ltool = getToolByName(site, 'portal_languages') # We are using TranslationManager to get the translations of a # string tg try: manager = TranslationManager(self.tg) languages = manager.get_translations() except AttributeError: languages = [] if len(languages) == 0: # If there is no results there are no translations # we move to portal root return self.wrapDestination(root(), postpath=False) # We are going to see if there is the preferred language translation # Otherwise we get the first as context to look for translation prefered = ltool.getPreferredLanguage(self.request) if prefered in languages: context = languages[prefered] else: context = languages[list(languages.keys())[0]] checkPermission = getSecurityManager().checkPermission chain = self.getParentChain(context) for item in chain: if ISiteRoot.providedBy(item) \ and not ILanguageRootFolder.providedBy(item): # We do not care to get a permission error # if the whole of the portal cannot be viewed. # Having a permission issue on the root is fine; # not so much for everything else so that is checked there return self.wrapDestination(item.absolute_url()) elif IFactoryTempFolder.providedBy(item) or \ IFactoryTool.providedBy(item): # TempFolder or portal_factory, can't have a translation continue try: canonical = ITranslationManager(item) except TypeError: if not ITranslatable.providedBy(item): # In case there it's not translatable go to parent # This solves the problem when a parent is not # ITranslatable continue else: raise translation = canonical.get_translation(self.lang) if translation and (INavigationRoot.providedBy(translation) or bool(checkPermission('View', translation))): # Not a direct translation, therefore no postpath # (the view might not exist on a different context) return self.wrapDestination(translation.absolute_url(), postpath=False) # Site root's the fallback return self.wrapDestination(root(), postpath=False)