I have a HTML-field in my model.py like this:
from odoo import models, fields
class TestModel(models.model):
_name = 'test.model'
content = fields.HTML()
To display the data of my model I used <field name="content" widget='html'> in the corresponding view file.
Now I want to add predefined data, when the module is first installed.
Normally, I add data inside the datafolder with .xml files.
So I created an .xml with the following content:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="unique_id" model="test.model">
<field name="content">
<p>Some Text</p>
</field>
</record>
</data>
</odoo>
But I end up getting parsing errors like this:
File "/Path/to/my/odoo/installation/odoo/tools/convert.py", line 782, in convert_xml_import
relaxng.assert_(doc)
File "src/lxml/etree.pyx", line 3633, in lxml.etree._Validator.assert_
AssertionError: Element odoo has extra content: data, line 3
What am I doing wrong or do I have a complete wrong understanding of how the HTML-field works?
Any help is appreciated.
Ok, if anyone ever stumbles across this...
One has to specify the type for an HTML-field.
So instead of <field name="content"> it has to be <field name="content" type="html"> and then it works as intended.
Happy Odoo'ing!
Related
I am trying to pass a French word from Controller to View using viewbag (The word that I try to pass is : Espèce), but inside the view when I try to affect the viewbag value's to an HTML input type text all I see is : Espéce .
In Controller
ViewBag.T = "Espèce";
In View : I used Jquery to affect the value
$("#T").val("#ViewBag.T").focus();
The HTML Input
<div>
<input type="type" id="T" value="" />
</div>
The result
Looks like an encoding issue. I'd recommend UTF-8 to ensure you get the accent marks to show up correctly.
From the Microsoft ASP.NET documentation:
To set the encoding for all pages, add a Globalization property to the
Web.config file, and then set its fileEncoding, requestEncoding, and
responseEncoding attributes, as shown in the following example:
<configuration>
<system.web>
<globalization
fileEncoding="utf-8"
requestEncoding="utf-8"
responseEncoding="utf-8"
culture="en-US"
uiCulture="de-DE"
/>
</system.web>
</configuration>
Try the below jquery code it will work as you expected. But it may introduce an XSS vulnerability. You can refer the link.
$("#T").val($("<div/>").html("#ViewBag.T").text()).focus();
For a personal project I need to get information from an excel-sheet into xml-data (xml-schema needed) but if I try to validate it this error shows: "Non-HTML Content-Type: text/xml ."
The excel sheet includes information such as basic text, which is quite simple to transport into xml, but also has long html inside its cells which later should be used as content of a wordpress site/post. So this hmtl begins with visualcomposer elemnts like "[vc_row][vc_column][vc_column_text]" and further more contains very standard html elements like paragraphs or tables. All html is wrapped inside .
So I wonder if this could be the source of my problem as, with my very slim coding and debugging knowledge, this came in my mind first.
Some extra information:
the xml-schema is edited with Dreamweaver CC 2015 which also does the validation
the xml-file is characterized, with: <?xml version="1.0" encoding="utf-8" standalone="yes"?>
<materialData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Data inside the xml is structured like: <matData><ID>3001</ID><author>1</author> ... </matData>
I suspect what you need is to correctly enclose the values that will include html in cdata tags so there not seen as xml.
<exampleOfACDATA>
<![CDATA[
Since this is a CDATA section
I can use all sorts of reserved characters
like > < " and &
or write things like
<foo></bar>
but my document is still well formed!
]]>
</exampleOfACDATA>
see further details here
What does <![CDATA[]]> in XML mean?
I have a requirement to transform the XML format of the SSRS report while exporting. I tried with some XSLT to implement this, but not getting desried output.
Default XML format of my report is
<?xml version="1.0" encoding="utf-8"?>
<Report xsi:schemaLocation="Test http://reportserver? %2FTest&rs%3AFormat=XML&rc%3ASchema=True" Name="Test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="Test">
<Tablix1>
<Details_Collection>
<Details Country="India" Sales="1000.0000" />
</Details_Collection>
</Tablix1>
</Report>
Output Needed (Report Tag is removed and the look and feel should be changed as below):
<?xml version="1.0" encoding="utf-8"?>
<Tablix1>
<Details_Collection>
<Details>
< Country>"India"</COuntry>
<Sales>1000.0000</Sales>
</Details>
</Details_Collection>
</Tablix1>
Br,
Shamsuddeen
I found second part of transformation:
<Details Country="India" Sales="1000.0000" />
->
< Country>"India"</Country>
<Sales>1000.0000</Sales>
For this purpose you should use TexBox Properties.
Press on your Data Filed in Designer mode
Find DataElementOutput - Set Output
Find DataElementStyle -Set Element
After that - you'll receive that you wanted.
But first part of transformation I could'n do.
I mean - remove <Report xsi:schemaLocation="Test http://reportserver?......>
If you already have a solution - advice.
BR,
Timur
In all examples I've seen of custom configurations nobody seems to use elements to store data, e.g.
<data name="1">
<server>aServer</server>
<ip>anipaddress</ip>
</data>
Is this actually possible?
I know I can use attributes like this:
<data name="1" server="aServer" ip="anipaddress"/>
TIA
The default implementation of ConfigurationElement.DeserializeElement does not support nodes of type XmlNodeType.Text or XmlNodeType.CDATA and throws a ConfigurationErrorsException with the following error message: The configuration section cannot contain a CDATA or text element.
Thus, to store information using the element text content, override the ConfigurationElement.DeserializeElement method.
Yes you can do that.
<configuration>
<configSections>
<sectionGroup name="pageAppearanceGroup">
<section
name="pageAppearance"
type="Samples.AspNet.PageAppearanceSection"
allowLocation="true"
allowDefinition="Everywhere"/>
</sectionGroup>
</configSections>
<pageAppearanceGroup>
<pageAppearance remoteOnly="true">
<font name="TimesNewRoman" size="18"/>
<color background="000000" foreground="FFFFFF"/>
</pageAppearance>
</pageAppearanceGroup>
</configuration>
Then to access the variables
Samples.AspNet.PageAppearanceSection config = (Samples.AspNet.PageAppearanceSection)System.Configuration.ConfigurationManager.GetSection(
"pageAppearanceGroup/pageAppearance");
Response.Write("<h2>Settings in the PageAppearance Section:</h2>");
Response.Write(string.Format("RemoteOnly: {0}<br>",
config.RemoteOnly));
etc....
Check this link
http://msdn.microsoft.com/en-us/library/2tw134k3.aspx
I have following XML to parse in SQL Server 2008
<Root>
<Document>
<Body>
<Component>
</Component>
</Body>
</Document>
</Root>
I want to retrieve all the <Component> tags in my xml, the issue is that <Document> tag at times might not come, Hence my xpath query of (root/document/body) won't work. Is there way I can get all <Component> tags irrespective of presence of <Document> tag?
You could always use an XPath query of
//component
to get all <component> elements in your entire document - no matter where they are and what other tags there are around it