Ignore:
Timestamp:
6 Jan 2015, 09:15:21 (10 years ago)
Author:
Henrik Bettermann
Message:

Add RESTDocument.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/utils/helpers.py

    r12361 r12408  
    832832                contents=text)
    833833    return elements
     834
     835def rest2dict(value=None,portal_language='en'):
     836    """Transforms a localized REST text string into a dictionary.
     837
     838    Different languages must be separated by `>>xy<<` whereas
     839    xy is the language code. Text parts without correct leading
     840    language separator - usually the first part has no language
     841    descriptor - are interpreted as texts in the portal's language.
     842    The latter can be configured in waeup.srp.utils.utils.IkobaUtils.
     843    """
     844    try:
     845        parts = value.split('>>')
     846    except:
     847        return {}
     848    elements = {}
     849    lang = portal_language
     850    for part in parts:
     851        if part[2:4] == u'<<':
     852            lang = str(part[0:2].lower())
     853            text = part[4:]
     854            elements[lang] = renderElement(u'div id="rest"',
     855                contents=ReST2HTML(text))
     856        else:
     857            text = part
     858            elements[lang] = renderElement(u'div id="rest"',
     859                contents=ReST2HTML(text))
     860    return elements
Note: See TracChangeset for help on using the changeset viewer.