Odoo - 查找并删除 <p> 标签
Odoo - Find and remove <p> tag
我想删除 <p>
元素:
<record model="ir.ui.view" id="helpdesk_support_form_view">
<field name="name">Helpdesk form</field>
<field name="model">helpdesk.support</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<group>
<field name="total_spend_hours" widget="float_time" attrs="{'readonly': [('stage_type', '=', 'closed')]}"/>
<p style="color:grey;" colspan="3">Some text here</p>
</group>
</group>
</sheet>
</form>
</field>
</record>
我怎样才能做到这一点?
我继承了视图并尝试添加:
<xpath expr="//p" position="replace">
<span></span>
</xpath>
但是我得到这个错误:
File "src/lxml/lxml.etree.pyx", line 3501, in lxml.etree._Validator.assert_ (src/lxml/lxml.etree.c:184715)
AssertionError: Element odoo has extra content: data, line 2
谢谢
转换成字符串,然后使用split方法查找信息。
如果所有消息/一行
标记具有相同的格式,则以下代码将起作用
a = """<p style="color:grey;" colspan="3">Some text here</p>"""
a.split("<p ")[1].split(">")[1].split("</p")[0]
你可以使用Odoo XPath,所以你需要继承基础视图。您的 xml 代码将类似于以下内容:
<!-- could be used for qweb templates -->
<template id="custom_template" inherit_id="base_module.base_view">
<xpath expr="//p" position="replace">
<span></span>
</xpath>
</template>
如果模型视图中的段落您的代码可能如下所示:
<record id="custom_view" model="ir.ui.view">
<field name="name">custom.view</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="base_module.base_view"/>
<field name="arch" type="xml">
<xpath expr="//p" position="replace">
<span></span>
</xpath>
</field>
</record>
请注意,您必须在 xpath
标签内添加数据。它不能为空。所以在提供的代码中添加一个 span
元素。
解决方案是:
<xpath expr="//form/sheet/group/group/p" position="replace">
<p></p>
</xpath>
我想删除 <p>
元素:
<record model="ir.ui.view" id="helpdesk_support_form_view">
<field name="name">Helpdesk form</field>
<field name="model">helpdesk.support</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<group>
<field name="total_spend_hours" widget="float_time" attrs="{'readonly': [('stage_type', '=', 'closed')]}"/>
<p style="color:grey;" colspan="3">Some text here</p>
</group>
</group>
</sheet>
</form>
</field>
</record>
我怎样才能做到这一点?
我继承了视图并尝试添加:
<xpath expr="//p" position="replace">
<span></span>
</xpath>
但是我得到这个错误:
File "src/lxml/lxml.etree.pyx", line 3501, in lxml.etree._Validator.assert_ (src/lxml/lxml.etree.c:184715)
AssertionError: Element odoo has extra content: data, line 2
谢谢
转换成字符串,然后使用split方法查找信息。
如果所有消息/一行
标记具有相同的格式,则以下代码将起作用
a = """<p style="color:grey;" colspan="3">Some text here</p>"""
a.split("<p ")[1].split(">")[1].split("</p")[0]
你可以使用Odoo XPath,所以你需要继承基础视图。您的 xml 代码将类似于以下内容:
<!-- could be used for qweb templates -->
<template id="custom_template" inherit_id="base_module.base_view">
<xpath expr="//p" position="replace">
<span></span>
</xpath>
</template>
如果模型视图中的段落您的代码可能如下所示:
<record id="custom_view" model="ir.ui.view">
<field name="name">custom.view</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="base_module.base_view"/>
<field name="arch" type="xml">
<xpath expr="//p" position="replace">
<span></span>
</xpath>
</field>
</record>
请注意,您必须在 xpath
标签内添加数据。它不能为空。所以在提供的代码中添加一个 span
元素。
解决方案是:
<xpath expr="//form/sheet/group/group/p" position="replace">
<p></p>
</xpath>