def handle_modified(self, content): fieldmanager = ILanguageIndependentFieldsManager(content) if not fieldmanager.has_independent_fields(): return sm = getSecurityManager() try: # Do we have permission to sync language independent fields? if self.bypass_security_checks(): # Clone the current user and assign a new editor role to # allow edition of all translated objects even if the # current user whould not have permission to do that. tmp_user = UnrestrictedUser(sm.getUser().getId(), '', [ 'Editor', ], '') # Wrap the user in the acquisition context of the portal # and finally switch the user to our new editor acl_users = getToolByName(content, 'acl_users') tmp_user = tmp_user.__of__(acl_users) newSecurityManager(None, tmp_user) # Copy over all language independent fields transmanager = ITranslationManager(content) for translation in self.get_all_translations(content): trans_obj = transmanager.get_translation(translation) if fieldmanager.copy_fields(trans_obj): self.reindex_translation(trans_obj) finally: # Restore the old security manager setSecurityManager(sm)
def handle_modified(self, content): fieldmanager = ILanguageIndependentFieldsManager(content) if not fieldmanager.has_independent_fields(): return sm = getSecurityManager() try: # Do we have permission to sync language independent fields? if self.bypass_security_checks(): # Clone the current user and assign a new editor role to # allow edition of all translated objects even if the # current user whould not have permission to do that. tmp_user = UnrestrictedUser( sm.getUser().getId(), '', ['Editor', ], '') # Wrap the user in the acquisition context of the portal # and finally switch the user to our new editor acl_users = getToolByName(content, 'acl_users') tmp_user = tmp_user.__of__(acl_users) newSecurityManager(None, tmp_user) # Copy over all language independent fields transmanager = ITranslationManager(content) for translation in self.get_all_translations(content): trans_obj = transmanager.get_translation(translation) if fieldmanager.copy_fields(trans_obj): self.reindex_translation(trans_obj) finally: # Restore the old security manager setSecurityManager(sm)
def handle_modified(self, content): canonical = ITranslationManager(content).query_canonical() if canonical in self.stack: return else: self.stack.append(canonical) # Copy over all language independent fields translations = self.get_all_translations(content) manager = ILanguageIndependentFieldsManager(content) for translation in translations: manager.copy_fields(translation) schema = content.Schema() descriptions = Attributes(schema) self.reindex_translations(translations, descriptions) self.stack.remove(canonical)
def createdEvent(obj, event): """ Subscriber to set language on the child folder It can be a - IObjectRemovedEvent - don't do anything - IObjectMovedEvent - IObjectAddedEvent - IObjectCopiedEvent """ if IObjectRemovedEvent.providedBy(event): return request = getattr(event.object, 'REQUEST', getRequest()) if not IPloneAppMultilingualInstalled.providedBy(request): return # On ObjectCopiedEvent and ObjectMovedEvent aq_parent(event.object) is # always equal to event.newParent. parent = aq_parent(event.object) # special parent handling if not ITranslatable.providedBy(parent): set_recursive_language(obj, LANGUAGE_INDEPENDENT) return # Normal use case # We set the tg, linking language = ILanguage(parent).get_language() set_recursive_language(obj, language) request = getattr(event.object, 'REQUEST', getRequest()) try: ti = request.translation_info except AttributeError: return # AT check portal = getSite() portal_factory = getToolByName(portal, 'portal_factory', None) if (not IDexterityContent.providedBy(obj) and portal_factory is not None and not portal_factory.isTemporary(obj)): return IMutableTG(obj).set(ti['tg']) modified(obj) tm = ITranslationManager(obj) old_obj = tm.get_translation(ti['source_language']) ILanguageIndependentFieldsManager(old_obj).copy_fields(obj)
def __call__(self, obj): li_clonner = ILanguageIndependentFieldsManager(self.context) li_clonner.copy_fields(obj)
def __call__(self, obj): ILanguageIndependentFieldsManager(self.context).copy_fields(obj)