def get_html_escaped_string(strings,
                            key,
                            app=None,
                            none_if_missing=False,
                            allow_basic_html=False):
    kdebug.debug(1, "set_strings(key='%s', app='%s', none_if_missing='%s', allow_basic_html='%s'" % \
        ( key, str(app), str(none_if_missing), str(allow_basic_html) ), "kweb_getstrings" )

    # get the string
    tmpstr = kgetstrings.get_string(strings,
                                    key,
                                    app=app,
                                    none_if_missing=none_if_missing)
    if not tmpstr:
        return None

    # escape basic forbidden html characters (not entities)
    tmpstr = kweb_lib.html_text_escape(tmpstr)

    if allow_basic_html:
        # unescape some html tags that we allow in strings
        tmpstr = re.sub(
            '<nbsp>', " ", tmpstr
        )  # special case -- convert <nbsp> (not a real tag) to &nbsp;
        tmpstr = re.sub(
            '&lt;(\/?)(p|b|i)&gt;', "<\\1\\2>",
            tmpstr)  # convert back <p>, </p>, <b>, </b>,  <i>, </i>

    return tmpstr
def get_html_escaped_string(strings, key, app=None, none_if_missing=False, allow_basic_html=False):
    kdebug.debug(1, "set_strings(key='%s', app='%s', none_if_missing='%s', allow_basic_html='%s'" % \
        ( key, str(app), str(none_if_missing), str(allow_basic_html) ), "kweb_getstrings" )

    # get the string
    tmpstr = kgetstrings.get_string(strings, key, app=app, none_if_missing=none_if_missing)
    if not tmpstr:
        return None

    # escape basic forbidden html characters (not entities)
    tmpstr = kweb_lib.html_text_escape(tmpstr)

    if allow_basic_html:
        # unescape some html tags that we allow in strings
        tmpstr = re.sub('&lt;nbsp&gt;', "&nbsp;", tmpstr) # special case -- convert <nbsp> (not a real tag) to &nbsp;
        tmpstr = re.sub('&lt;(\/?)(p|b|i)&gt;', "<\\1\\2>", tmpstr) # convert back <p>, </p>, <b>, </b>,  <i>, </i>

    return tmpstr
示例#3
0
def GT(key, app=None, allow_basic_html=0):
    if allow_basic_html:
        return kweb_getstrings.get_html_escaped_string(cfg_common.strings, key,
                                                       app, 0, 1)
    return kgetstrings.get_string(cfg_common.strings, key, app)
示例#4
0
def GT(key, app=None, allow_basic_html=0):
    if allow_basic_html: return kweb_getstrings.get_html_escaped_string(cfg_common.strings, key, app, 0, 1)
    return kgetstrings.get_string(cfg_common.strings, key, app)