def reindex_language_independent(ob, event):
    """Re-index language independent object for other languages

    Language independent objects are indexed once for each language with
    different, language code post-fixed, UUID for each. When ever a language
    independent object is modified in some language, it must be re-indexed
    for all the other languages as well.

    """
    if not is_language_independent(ob):
        return

    pc = getToolByName(ob, 'portal_catalog')
    parent = aq_parent(ob)

    # Re-index objects just below the language independent folder
    if ILanguageIndependentFolder.providedBy(parent):
        brains = pc.unrestrictedSearchResults(portal_type='LIF')
        for brain in brains:
            lif = brain._unrestrictedGetObject()
            if lif != parent:
                lif[ob.id].indexObject()
    # Re-index objects deeper inside language independent folder
    else:
        language_tool = getToolByName(ob, 'portal_languages')
        language_codes = language_tool.supported_langs
        parent_uuid = IUUID(parent).split('-')[0] + '-'
        for code in language_codes:
            results = pc.unrestrictedSearchResults(UID=parent_uuid + code)
            # When we have results, parent has been indexed and we can reindex:
            for brain in results:
                tmp = ob.unrestrictedTraverse(brain.getPath() + '/' + ob.id)
                tmp.reindexObject()
Пример #2
0
def attributeUUID(context):
    is_language_independent = False
    for element in aq_chain(context):
        if ILanguageIndependentFolder.providedBy(element):
            is_language_independent = True
        if ILanguageRootFolder.providedBy(element) and is_language_independent:
            uid = getattr(aq_base(context), ATTRIBUTE_NAME, None) or ''
            return uid + '-' + element.id if uid is not None else None
    return getattr(context, ATTRIBUTE_NAME, None)
Пример #3
0
def is_language_independent(ob):
    if not ILanguageIndependentFolder.providedBy(ob):
        for element in aq_chain(ob):
            if ILanguageIndependentFolder.providedBy(element):
                return True
    return False