• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.node函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utils.node函数的典型用法代码示例。如果您正苦于以下问题:Python node函数的具体用法?Python node怎么用?Python node使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了node函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: xml_hint

 def xml_hint(self):
     if type(self.get_hint()) == dict:
         d = self.get_translation_keys()
         return node(u"hint", ref="jr:itext('%s')" % d[u"hint"])
     else:
         hint, outputInserted = self.get_root().insert_output_values(self.get_hint())
         return node(u"hint", hint, toParseString=outputInserted)
开发者ID:ChandniD,项目名称:pyxform,代码行数:7,代码来源:survey_element.py


示例2: xml_control

    def xml_control(self):
        """
        <group>
        <label>Fav Color</label>
        <repeat nodeset="fav-color">
          <select1 ref=".">
            <label ref="jr:itext('fav')" />
            <item><label ref="jr:itext('red')" /><value>red</value></item>
            <item><label ref="jr:itext('green')" /><value>green</value></item>
            <item><label ref="jr:itext('yellow')" /><value>yellow</value></item>
          </select1>
        </repeat>
        </group>
        """
        control_dict = self.control
        kwargs = {}
        if u"jr:count" in self and self[u"jr:count"] != "":
            kwargs = {u"jr:count": self[u"jr:count"]}
        if u"appearance" in control_dict:
            repeat_node = node(u"repeat", nodeset=self.get_xpath(), appearance=control_dict[u"appearance"], **kwargs)
        else:
            repeat_node = node(u"repeat", nodeset=self.get_xpath(), **kwargs)
        for n in Section.xml_control(self):
            repeat_node.appendChild(n)

        label = self.xml_label()
        if label:
            return node(u"group", self.xml_label(), repeat_node, ref=self.get_xpath())
        return node(u"group", repeat_node, ref=self.get_xpath())
开发者ID:Topol,项目名称:pyxform,代码行数:29,代码来源:section.py


示例3: xml_hint

 def xml_hint(self):
     if type(self.hint) == dict:
         path = self._translation_path("hint")
         return node(u"hint", ref="jr:itext('%s')" % path)
     else:
         hint, outputInserted = self.get_root().insert_output_values(self.hint)
         return node(u"hint", hint, toParseString=outputInserted)
开发者ID:bderenzi,项目名称:pyxform,代码行数:7,代码来源:survey_element.py


示例4: xml_control

    def xml_control(self):
        assert self.bind[u"type"] in [u"select", u"select1"]
        survey = self.get_root()
        control_dict = self.control.copy()
        # Resolve field references in attributes
        for key, value in control_dict.items():
            control_dict[key] = survey.insert_xpaths(value)
        control_dict['ref'] = self.get_xpath()

        result = node(**control_dict)
        for element in self.xml_label_and_hint():
            result.appendChild(element)
        # itemset are only supposed to be strings,
        # check to prevent the rare dicts that show up
        if self['itemset'] and isinstance(self['itemset'], basestring):
            choice_filter = self.get('choice_filter')
            nodeset = "instance('" + self['itemset'] + "')/root/item"
            choice_filter = survey.insert_xpaths(choice_filter)
            if choice_filter:
                nodeset += '[' + choice_filter + ']'
            itemset_label_ref = "jr:itext(itextId)"
            itemset_children = [node('value', ref='name'),
                                node('label', ref=itemset_label_ref)]
            result.appendChild(node('itemset', *itemset_children,
                                    nodeset=nodeset))
        else:
            for n in [o.xml() for o in self.children]:
                result.appendChild(n)
        return result
开发者ID:alxndrsn,项目名称:pyxform,代码行数:29,代码来源:question.py


示例5: xml_control

    def xml_control(self):
        """
        <group>
        <label>Fav Color</label>
        <repeat nodeset="fav-color">
          <select1 ref=".">
            <label ref="jr:itext('fav')" />
            <item><label ref="jr:itext('red')" /><value>red</value></item>
            <item><label ref="jr:itext('green')" /><value>green</value></item>
            <item><label ref="jr:itext('yellow')" /><value>yellow</value></item>
          </select1>
        </repeat>
        </group>
        """
        control_dict = self.control.copy()
        jrcount = control_dict.get('jr:count')
        if jrcount:
            survey = self.get_root()
            control_dict['jr:count'] = survey.insert_xpaths(jrcount)
        repeat_node = node(u"repeat", nodeset=self.get_xpath(), **control_dict)

        for n in Section.xml_control(self):
            repeat_node.appendChild(n)

        label = self.xml_label()
        if label:
            return node(
                u"group", self.xml_label(), repeat_node,
                ref=self.get_xpath()
                )
        return node(u"group", repeat_node, ref=self.get_xpath())
开发者ID:andreasmitrou,项目名称:pyxform,代码行数:31,代码来源:section.py


示例6: xml_control

    def xml_control(self):
        """
        <group>
        <label>Fav Color</label>
        <repeat nodeset="fav-color">
          <select1 ref=".">
            <label ref="jr:itext('fav')" />
            <item><label ref="jr:itext('red')" /><value>red</value></item>
            <item><label ref="jr:itext('green')" /><value>green</value></item>
            <item><label ref="jr:itext('yellow')" /><value>yellow</value></item>
          </select1>
        </repeat>
        </group>
        """
        control_dict = self.control.copy()
        survey = self.get_root()
        # Resolve field references in attributes
        for key, value in control_dict.items():
            control_dict[key] = survey.insert_xpaths(value)
        repeat_node = node(u"repeat", nodeset=self.get_xpath(), **control_dict)

        for n in Section.xml_control(self):
            repeat_node.appendChild(n)

        label = self.xml_label()
        if label:
            return node(
                u"group", self.xml_label(), repeat_node,
                ref=self.get_xpath()
                )
        return node(u"group", repeat_node, ref=self.get_xpath(), **self.control)
开发者ID:Cadasta,项目名称:cadasta-provider-ona,代码行数:31,代码来源:section.py


示例7: xml_model

    def xml_model(self):
        """
        Generate the xform <model> element
        """
        self._setup_translations()
        self._setup_media()
        self._add_empty_translations()

        model_children = []
        if self._translations:
            model_children.append(self.itext())
        model_children += [node("instance", self.xml_instance())]
        model_children += list(self._generate_static_instances())
        model_children += list(self._generate_pulldata_instances())
        model_children += self.xml_bindings()

        if self.submission_url or self.public_key:
            submission_attrs = dict()
            if self.submission_url:
                submission_attrs["action"] = self.submission_url
            if self.public_key:
                submission_attrs["base64RsaPublicKey"] = self.public_key
            submission_node = node("submission", method="form-data-post",
                                   **submission_attrs)
            model_children.insert(0, submission_node)

        return node("model",  *model_children)
开发者ID:henriquechehad,项目名称:pyxform,代码行数:27,代码来源:survey.py


示例8: _generate_static_instances

    def _generate_static_instances(self):
        """
        Generates <instance> elements for static data
        (e.g. choices for select type questions)
        """
        for list_name, choice_list in self.choices.items():
            instance_element_list = []
            for idx, choice in zip(range(len(choice_list)), choice_list):
                choice_element_list = []
                # Add a unique id to the choice element incase there is itext
                # it refrences
                itextId = '-'.join(['static_instance', list_name, str(idx)])
                choice_element_list.append(node("itextId", itextId))

                for choicePropertyName, choicePropertyValue in choice.items():
                    if isinstance(choicePropertyValue, basestring) \
                            and choicePropertyName != 'label':
                        choice_element_list.append(
                            node(choicePropertyName,
                                 unicode(choicePropertyValue))
                        )
                instance_element_list.append(node("item",
                                                  *choice_element_list))
            yield node("instance", node("root", *instance_element_list),
                       id=list_name)
开发者ID:henriquechehad,项目名称:pyxform,代码行数:25,代码来源:survey.py


示例9: xml_label

 def xml_label(self):
     if self.needs_itext_ref():
         #If there is a dictionary label, or non-empty media dict, then we need to make a label with an itext ref
         ref = "jr:itext('%s')" % self._translation_path(u"label")
         return node(u"label", ref=ref)
     else:
         survey = self.get_root()
         label, outputInserted = survey.insert_output_values(self.label)
         return node(u"label", label, toParseString=outputInserted)
开发者ID:bderenzi,项目名称:pyxform,代码行数:9,代码来源:survey_element.py


示例10: xml_instance

 def xml_instance(self):
     result = Section.xml_instance(self)
     result.setAttribute(u"id", self.id_string)
     
     #We need to add a unique form instance id if the form is to be submitted.
     if self.submission_url:
         result.appendChild(node("orx:meta", node("orx:instanceID")))
         
     return result
开发者ID:Topol,项目名称:pyxform,代码行数:9,代码来源:survey.py


示例11: xml_label

    def xml_label(self):
        if not self.get_label() and not self.get(self.TYPE) == "group"and len(self.get('media')) == 0:
            return None

        if type(self.get_label()) == dict or not len(self.get('media')) == 0:
            if len(self.get_label()) == 0 and self.get(self.TYPE) == "group":
                return None
            return node(u"label", ref="jr:itext('%s')" % self._translation_path(u"label"))
        else:
            label, outputInserted = self.get_root().insert_output_values(self.get_label())
            return node(u"label", label, toParseString=outputInserted)
开发者ID:ChandniD,项目名称:pyxform,代码行数:11,代码来源:survey_element.py


示例12: xml_instance

 def xml_instance(self):
     survey = self.get_root()
     attributes = {}
     attributes.update(self.get(u'instance', {}))
     for key, value in attributes.items():
         attributes[key] = survey.insert_xpaths(value)
     if self.get(u"default"):
         return node(
             self.name, unicode(self.get(u"default")), **attributes
         )
     return node(self.name, **attributes)
开发者ID:alxndrsn,项目名称:pyxform,代码行数:11,代码来源:question.py


示例13: xml_translations

 def xml_translations(self):
     result = []
     for lang in self._translations.keys():
         result.append( node("translation", lang=lang) )
         for name in self._translations[lang].keys():
             result[-1].appendChild(
                 node("text",
                     node("value", self._translations[lang][name]),
                     id=name
                     )
                 )
     return node("itext", *result)
开发者ID:aptivate,项目名称:pyxform,代码行数:12,代码来源:survey.py


示例14: xml_model

 def xml_model(self):
     self._setup_translations()
     if self._translations:
         return node("model",
                     self.xml_translations(),
                     node("instance", self.xml_instance()),
                     *self.xml_bindings()
                     )
     return node("model",
                 node("instance", self.xml_instance()),
                 *self.xml_bindings()
                 )
开发者ID:aptivate,项目名称:pyxform,代码行数:12,代码来源:survey.py


示例15: _generate_from_file_instances

 def _generate_from_file_instances(self):
     for i in self.iter_descendants():
         itemset = i.get('itemset')
         if itemset and \
                 (itemset.endswith('.csv') or itemset.endswith('.xml')):
             file_id, file_extension = os.path.splitext(itemset)
             yield node(
                 "instance",
                 node("root", node("item", node("name"), node("label"))),
                 id=file_id,
                 src="jr://file-%s/%s" % (file_extension[1:], itemset)
             )
开发者ID:onaio,项目名称:pyxform,代码行数:12,代码来源:survey.py


示例16: xml

 def xml(self):
     """
     calls necessary preparation methods, then returns the xml.
     """
     self.validate()
     self._setup_xpath_dictionary()
     return node(
         u"h:html",
         node(u"h:head", node(u"h:title", self.title), self.xml_model()),
         node(u"h:body", *self.xml_control()),
         **nsmap
     )
开发者ID:reyrodrigues,项目名称:pyxform,代码行数:12,代码来源:survey.py


示例17: xml_control

 def xml_control(self):
     control_dict = self.get_control()
     if self.APPEARANCE in control_dict:
         return node(
             u"trigger", ref=self.get_xpath(),
             appearance=control_dict[self.APPEARANCE],
             *self.xml_label_and_hint()
             )
     else:
         return node(u"trigger",
             ref=self.get_xpath(),
             *self.xml_label_and_hint()
             )
开发者ID:ChandniD,项目名称:pyxform,代码行数:13,代码来源:question.py


示例18: xml_control

 def xml_control(self):
     control_dict = self.control
     if u"appearance" in control_dict:
         return node(
             u"trigger", ref=self.get_xpath(),
             appearance=control_dict[u"appearance"],
             *self.xml_label_and_hint()
             )
     else:
         return node(u"trigger",
             ref=self.get_xpath(),
             *self.xml_label_and_hint()
             )
开发者ID:calo1,项目名称:pyxform,代码行数:13,代码来源:question.py


示例19: itext

    def itext(self):
        """
        This function creates the survey's itext nodes from _translations
        @see _setup_media _setup_translations
        itext nodes are localized images/audio/video/text
        @see http://code.google.com/p/opendatakit/wiki/XFormDesignGuidelines
        """
        result = []
        for lang, translation in self._translations.items():
            if lang == self.default_language:
                result.append(
                    node("translation", lang=lang, default=u"true()"))
            else:
                result.append(node("translation", lang=lang))

            for label_name, content in translation.items():
                itext_nodes = []
                label_type = label_name.partition(":")[-1]

                if type(content) is not dict:
                    raise Exception()

                for media_type, media_value in content.items():

                    # There is a odk/jr bug where hints can't have a value
                    # for the "form" attribute.
                    # This is my workaround.
                    if label_type == u"hint":
                        value, outputInserted = \
                            self.insert_output_values(media_value)
                        itext_nodes.append(
                            node("value", value, toParseString=outputInserted))
                        continue

                    if media_type == "long":
                        value, outputInserted = \
                            self.insert_output_values(media_value)
                        # I'm ignoring long types for now because I don't know
                        # how they are supposed to work.
                        itext_nodes.append(
                            node("value", value, toParseString=outputInserted))
                    elif media_type == "image":
                        value, outputInserted = \
                            self.insert_output_values(media_value)
                        itext_nodes.append(
                            node("value", "jr://images/" + value,
                                 form=media_type, toParseString=outputInserted)
                        )
                    else:
                        value, outputInserted = \
                            self.insert_output_values(media_value)
                        itext_nodes.append(
                            node("value", "jr://" + media_type + "/" + value,
                                 form=media_type,
                                 toParseString=outputInserted))

                result[-1].appendChild(
                    node("text", *itext_nodes, id=label_name))

        return node("itext", *result)
开发者ID:henriquechehad,项目名称:pyxform,代码行数:60,代码来源:survey.py


示例20: xml_binding

 def xml_binding(self):
     """
     Return the binding for this survey element.
     """
     survey = self.get_root()
     bind_dict = self.bind.copy()
     if self.get('flat'):
         # Don't generate bind element for flat groups.
         return None
     if bind_dict:
         for k, v in bind_dict.items():
             # I think all the binding conversions should be happening on
             # the xls2json side.
             if hashable(v) and v in self.binding_conversions:
                 v = self.binding_conversions[v]
             if k == u'jr:constraintMsg' and type(v) is dict:
                 v = "jr:itext('%s')" % self._translation_path(
                     u'jr:constraintMsg')
             if k == u'jr:requiredMsg' and type(v) is dict:
                 v = "jr:itext('%s')" % self._translation_path(
                     u'jr:requiredMsg')
             if k == u'jr:noAppErrorString' and type(v) is dict:
                 v = "jr:itext('%s')" % self._translation_path(
                     u'jr:noAppErrorString')
             bind_dict[k] = survey.insert_xpaths(v)
         return node(u"bind", nodeset=self.get_xpath(), **bind_dict)
     return None
开发者ID:ivangayton,项目名称:pyxform,代码行数:27,代码来源:survey_element.py



注:本文中的utils.node函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.norm_geometric_average函数代码示例发布时间:2022-05-26
下一篇:
Python utils.new_std_map函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap