(langs, form)
return rows
Returns form question label, name, and media, in given langs
Returns form question label, name, and media, in given langs
Returns form question label name and media in given langs
def get_form_question_label_name_media(langs, form):
    """
    Returns form question label, name, and media, in given langs
    """
    if form.form_type == 'shadow_form':
        return []

    rows = []

    xform = form.wrapped_xform()
    itext_items = OrderedDict()
    nodes = []
    try:
        for lang in langs:
            nodes += xform.itext_node.findall("./{f}translation[@lang='%s']" % lang)
    except XFormException:
        pass

    for translation_node in nodes:
        lang = translation_node.attrib['lang']
        for text_node in translation_node.findall("./{f}text"):
            text_id = text_node.attrib['id']
            itext_items[text_id] = itext_items.get(text_id, {})

            for value_node in text_node.findall("./{f}value"):
                value_form = value_node.attrib.get("form", "default")
                value = ''
                for part in ItextValue.from_node(value_node).parts:
                    if isinstance(part, ItextOutput):
                        value += "<output value=\"" + part.ref + "\"/>"
                    else:
                        part = force_text(part)
                        part = part.replace('&', '&amp;')
                        part = part.replace('<', '&lt;')
                        part = part.replace('>', '&gt;')
                        value += part
                itext_items[text_id][(lang, value_form)] = value

    app = form.get_app()
    for text_id, values in itext_items.items():
        row = [text_id]
        for value_form in ["default", "image", "audio", "video"]:
            # Get the fallback value for this form
            fallback = ""
            for lang in app.langs:
                fallback = values.get((lang, value_form), fallback)
                if fallback:
                    break
            # Populate the row
            for lang in langs:
                row.append(values.get((lang, value_form), fallback))
        # Don't add empty rows:
        if any(row[1:]):
            rows.append(row)

    return rows
def get_form_question_label_name_media ( langs , form ) : if form . form_type == 'shadow_form' : return [ ] rows = [ ] xform = form . wrapped_xform ( ) itext_items = OrderedDict ( ) nodes = [ ] try : for lang in langs : nodes += xform . itext_node . findall ( "./{f}translation[@lang='%s']" % lang ) except XFormException : pass for translation_node in nodes : lang = translation_node . attrib [ 'lang' ] for text_node in translation_node . findall ( "./{f}text" ) : text_id = text_node . attrib [ 'id' ] itext_items [ text_id ] = itext_items . get ( text_id , { } ) for value_node in text_node . findall ( "./{f}value" ) : value_form = value_node . attrib . get ( "form" , "default" ) value = '' for part in ItextValue . from_node ( value_node ) . parts : if isinstance ( part , ItextOutput ) : value += "<output value=\"" + part . ref + "\"/>" else : part = force_text ( part ) part = part . replace ( '&' , '&amp;' ) part = part . replace ( '<' , '&lt;' ) part = part . replace ( '>' , '&gt;' ) value += part itext_items [ text_id ] [ ( lang , value_form ) ] = value app = form . get_app ( ) for text_id , values in itext_items . items ( ) : row = [ text_id ] for value_form in [ "default" , "image" , "audio" , "video" ] : # Get the fallback value for this form fallback = "" for lang in app . langs : fallback = values . get ( ( lang , value_form ) , fallback ) if fallback : break # Populate the row for lang in langs : row . append ( values . get ( ( lang , value_form ) , fallback ) ) # Don't add empty rows: if any ( row [ 1 : ] ) : rows . append ( row ) return rows