How to access a TinyMCE template in python code or TAL? - templates

In Plone 5 you can make use of html templates in the TinyMCE editor by registering the template plugin. The templates are html snippets living in the file system which are also registered in the plone ressource registry. Here is an example:
<?xml version="1.0"?>
<registry>
<record name="plone.templates" interface="Products.CMFPlone.interfaces.controlpanel.ITinyMCESchema" field="templates">
<field type="plone.registry.field.Text">
<default></default>
<description xmlns:ns0="http://xml.zope.org/namespaces/i18n" ns0:domain="plone" ns0:translate="help_tinymce_templates">
Enter the list of templates in json format http://www.tinymce.com/wiki.php/Plugin:template
</description>
<required>False</required>
<title xmlns:ns0="http://xml.zope.org/namespaces/i18n" ns0:domain="plone" ns0:translate="label_tinymce_templates">Templates</title>
</field>
<value>[
{"title": "Template 1", "url": "++theme++mytheme/tinymce-templates/tmpl1.html"},
{"title": "Template 2", "url": "++theme++mytheme/tinymce-templates/tmpl2.html"}
]</value>
</record>
<record name="plone.custom_plugins" interface="Products.CMFPlone.interfaces.controlpanel.ITinyMCESchema" field="custom_plugins">
<field type="plone.registry.field.List">
<default/>
<description xmlns:ns0="http://xml.zope.org/namespaces/i18n" ns0:domain="plone" ns0:translate="">
Enter a list of custom plugins which will be loaded in the editor. Format is pluginname|location, one per line.
</description>
<required>False</required>
<title xmlns:ns0="http://xml.zope.org/namespaces/i18n" ns0:domain="plone" ns0:translate="">Custom plugins</title>
<value_type type="plone.registry.field.TextLine"/>
</field>
<value>
<element>template|+plone+static/components/tinymce-builded/js/tinymce/plugins/template</element>
</value>
</record>
</registry>
My question is: How can the templates be accessed from python code or from TAL? First possibility is to read the file from the filesystem. But then the security layer will be passed by. The second is to request the templates by http. In this case safety is taken into account. But it is rather expensive. Is there a way to access the templates (plone resources) direct without bypassing security?

You can access the templates direcly by the url.
Something like:
portal.restrictedTraverse('++theme++mytheme/tinymce-templates/tmpl2.html')
The same applies to page templates.

Related

Odoo - How to get a pre-created record/value in many2one field

How can I select/get a pre created record/value in many2one field
for example: the holidays_status_id in hr_holidays module is a many2one field and it has already 4 values of
Legal Leaves
Sick Leaves
Compensatory Days
Unpaid
what I need to do is dynamically select the legal leaves and customize it in another module.
How can I do it?
Basically the data is coming after once you are installing the module of your hr_holidays.It means the part of first time of module installation.
It is basically a part of the data file which is named as hr_holidays_data.xml file in hr_holidays module.
It must need to add that file location on 'data' key attribute of value in __openerp__.py file
'data': ['hr_holidays_data.xml']
which is part of added into our module menifiest file of each module in Odoo (Formally OpenERP).
<!-- Casual leave -->
<record model="hr.holidays.status" id="holiday_status_cl">
<field name="name" eval="'Legal Leaves '+time.strftime('%Y')"/>
<field name="color_name">black</field>
</record>
<!-- Sick leave -->
<record model="hr.holidays.status" id="holiday_status_sl">
<field name="name">Sick Leaves</field>
<field name="limit">True</field>
<field name="color_name">red</field>
</record>
<!-- Compensatory Days -->
<record model="hr.holidays.status" id="holiday_status_comp">
<field name="name">Compensatory Days</field>
<field name="limit">True</field>
<field name="color_name">lavender</field>
</record>
<!--Unpaid Leave -->
<record model="hr.holidays.status" id="holiday_status_unpaid">
<field name="name">Unpaid</field>
<field name="limit">True</field>
<field name="color_name">brown</field>
</record>
Need to understand the following attribute for more clarification.
1. model :-
which is part of the your own model (class name) or use the existing Odoo Model class.which is basically mentioned on each class of _name attribute in your class.
2. id :
unique id of each record
2.field name:
what ever field you want to add a new record (insert a new record) which is part of the model class fields name.
Each record contain the number of child field name so you can add as per your requirement and do to check after install or upgrade the module.
You may also add our own custom leave with our module with our own separate .xml file and add it as per your need.
I hope my answer may helpful for you :)

Solr : importing dynamic field names from XML with DIH and xpath

I'm indexing data from a XML file, with many fields like these declared in DataImportHandler's dataconfig.xml :
<field column="pos_A" xpath="/positions/pos_A/#pos" />
<field column="pos_B" xpath="/positions/pos_B/#pos" />
<field column="pos_C" xpath="/positions/pos_C/#pos" />
...
And one matching dynamicField declaration in schema.xml :
<dynamicField name="pos_*" type="sint" indexed="true" stored="true" />
I'm wondering if it's possible to use a transformer to dynamically generate the field names in dataconfig.xml, and have a single line, kinda like :
<field column="pos_{$1}" xpath="/positions/pos_(*)/#pos" />
(pardon my xpath and regex syntax :)
https://issues.apache.org/jira/browse/SOLR-3251 The latest release claims that you can dynamically add fields to the schema. I tried to find documentation for the public interface, but not much luck so far.
>
SOLR-4658: In preparation for REST API requests that can modify the schema,
126 a "managed schema" is introduced.
127 Add '<schemaFactory class="ManagedSchemaFactory" mutable="true"/>' to solrconfig.xml
128 in order to use it, and to enable schema modifications via REST API requests.
129 (Steve Rowe, Robert Muir)

Sharepoint batch for MultiChoice field value insertion

So i have a problem regarding usage of sharepoint list webservices.
I need to get the syntax right for Sharepoint batch script for insertion of new items.
Everyhing works fine except multichoice field type.
I insert the data, but nomatter how i do it, it shows up on SP list item details OK, but when trying to edit item in SP, i see, that SP have taken the value i sent to this field as text string, and does not check the items i have saved as selected.
The script for now is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<Batch OnError="Return">
<Method ID='1' Cmd='New'>
<Field Name='SecurityCheckpoints'>1st checkpoint;2nd checkpoint</Field>
</Method>
</Batch>
Definition for that field is like this:
<Field Type="MultiChoice"
DisplayName="Checkpoints allowed"
Required="TRUE"
FillInChoice="FALSE"
ID="{guid-guid-guid-guid-guid}"
SourceID="{guid-guid-guid-guid-guid}"
StaticName="SecurityCheckpoints"
Name="SecurityCheckpoints"
ColName="ntext2"
RowOrdinal="0"
Version="4">
<CHOICES>
<CHOICE>1st checkpoint</CHOICE>
<CHOICE>2nd checkpoint</CHOICE>
<CHOICE>3rd checkpoint</CHOICE>
</CHOICES>
<Default>1st checkpoint</Default>
</Field>
I have to implement something like custom UI for sharepoint in different-purpouse silverlight app, and so i am using my own webservice to be a proxy between SP and SL, i retrieve SP list definition and dinamicaly build UI controls, so user can fill in the forms.
How do i form the script, so items are selected(ticked) in the SP instead of SP saving them as just string value?
If I use script with only one item ("1st checkpoint"), SP processes it ok, it there is many, data is saved as text string?
What i am doing wrong? How do i correctly seperate multiple values?
I have searched high and low, but have not found example of SP update script, where multichoice sample is included.
Thank You in advance!
I found the sollution - it was too easy:
instead of seperating the choice values using semicolon ";", they had to be seperated using ";#", and putting it in front and in behind the whole list.
So rather than using this:
1st checkpoint;2nd checkpoint
<?xml version="1.0" encoding="UTF-8"?>
<Batch OnError="Return">
<Method ID='1' Cmd='New'>
<Field Name='SecurityCheckpoints'>1st checkpoint;2nd checkpoint</Field>
</Method>
</Batch>
It had to be done like this:
;#1st checkpoint;#2nd checkpoint;#
<?xml version="1.0" encoding="UTF-8"?>
<Batch OnError="Return">
<Method ID='1' Cmd='New'>
<Field Name='SecurityCheckpoints'>;#1st checkpoint;#2nd checkpoint;#</Field>
</Method>
</Batch>
PS:I dont know was it correct way to do this, but I answered my own question. Just for others to know.
I run code below successfully.
<?xml version="1.0" encoding="UTF-8"?><ows:Batch OnError="Return">
<Method ID="0"><SetList>3933c528-5747-4fc7-bdec-6465294997dd</SetList>
<SetVar Name="Cmd">Save</SetVar>
<SetVar Name="ID">New</SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#Temp_UNID">8D8DE35CFFE9EEEAC12570920052A8FD</SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#Title"> - Birch Data Exchange Specification</SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#C0370A_Agora_DocNum">8AL020210178ZZASB</SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#C0370A_Agora_Phase"></SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#C0370A_Agora_Author">Jerome BOURGER</SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#C0370A_Agora_ServicesOri"> </SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#C0370A_Agora_Type">;#3 - Quality Plan;#Objectives;#Progress Plan;#Follow-up;#Reports;#</SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#C0370A_Agora_Keywords"></SetVar> </Method></ows:Batch>

How do I rename a file using the SharePoint web services?

I have a custom definition for a document library and I am trying to rename documents within the library using only the out of the box web services. Having defined a view with the "Name" field supplied and trying the "LinkFilename", my calls to rename a file are respectively returning a failure or ignoring the new value.
How do I rename a file using the SharePoint web services?
Use the Lists.UpdateListItems web method. The XML request should look like:
<Batch OnError="Continue" PreCalc="TRUE" ListVersion="0">
<Method ID="1" Cmd="Update">
<!-- List item ID of document -->
<Field Name="ID">2</Field>
<!-- Full URL to document -->
<Field Name="FileRef">http://Server/FullUrl/File.doc</Field>
<!-- New filename -->
<Field Name="BaseName">NewName</Field>
</Method>
</Batch>
You should be able to use UpdateListItems. Here's an example.
Per comment: So the actual question is "how do I call a web service?" Take a look a this example. Some more good walkthroughs here.

MSXML Select Nodes Not Working

I am working on an automated testing app, and am currently in the process of writing a function that compares values between two XML files that should be identical, but may not be. Here is a sample of the XML I'm trying to process:
<?xml version="1.0" encoding="utf-8"?>
<report xmlns="http://www.**.com/**">
<subreport name="RBDReport">
<record rowNumber="1">
<field name="Time">
<value>0</value>
</field>
<field name="Reliability">
<value>1.000000</value>
</field>
<field name="Unreliability">
<value>0.000000</value>
</field>
<field name="Availability">
<value> </value>
</field>
<field name="Unavailability">
<value> </value>
</field>
<field name="Failure Rate">
<value>N/A</value>
</field>
<field name="Number of Failures">
<value> </value>
</field>
<field name="Total Downtime">
<value> </value>
</field>
</record>
(Note there may be multiple <subreport> elements and within those, multiple <record> elements.)
What I'd like is to extract the <value> tags of two documents and then compare their values. That part I know how to do. The problem is the extraction itself.
Since I'm stuck in C++, I'm using MSXML, and have written a wrapper to allow my app to abstract away the actual XML manipulation, in case I ever decide to change my data format.
That wrapper, CSimpleXMLParser, loads an XML document and sets its "top record" to the document element of the XML document. (CRecord being an abstract class with CXMLRecord one of its subclasses, and which gives access to child records singularly or by group, and also allowing access to the "value" of the Record (values for child elements or attributes, in the case of CXMLRecord.) A CXMLRecord contains an MSXML::MSXMLDOMNodePtr and a pointer to an instance of a CSimpleXMLParser.) The wrapper also contains utility functions for returning children, which the CXMLRecord uses to return its child records.
In my code, I do the following (trying to return all <subreport> nodes just to see if it works):
CSimpleXMLParser parserReportData;
parserReportData.OpenXMLDocument(strPathToXML);
bool bGetChildrenSuccess = parserReportData.GetFirstRecord()->GetChildRecords(listpChildren, _T("subreport"));
This is always returning false. The meat of the implementation of CXMLRecord::GetChildRecords() is basically
MSXML2::IXMLDOMNodeListPtr pListChildren = m_pParser->SelectNodes(strPath, m_pXMLNode);
if (pListChildren->Getlength() == 0)
{
return false;
}
for (long l = 0; l < pListChildren->Getlength(); ++l)
{
listRecords.push_back(new CXMLRecord(pListChildren->Getitem(l), m_pParser));
}
return true;
And CSimpleXMLParser::SelectNodes() is:
MSXML2::IXMLDOMNodeListPtr CSimpleXMLParser::SelectNodes(LPCTSTR strXPathFilter, MSXML2::IXMLDOMNodePtr pXMLNode)
{
return pXMLNode->selectNodes(_bstr_t(strXPathFilter));
}
When run, the top record is definitely being set to the <report> element properly. I can do all sorts of things with it, like getting its child nodes (through the MSXML interface, not through my wrapper) or its name, etc. I know that my wrapper can work, because I use it elsewhere in the app for parsing an XML configuration file, and that works flawlessly.
I thought maybe I was doing something faulty with the XPath query expression, but every permutation I could think of gives no joy. The MSXML::IXMLDOMNodeListPtr returned by IXMLDOMNodePtr::SelectNodes() is always of length 0 when I try to deal with this XML file.
This is driving me crazy.
I'm used to doing this with .NET's XmlDocument objects, but I think the effect is the same here:
If the XML document includes a namespace -- even an unnamed one -- then the Xpath query has to use one as well. So, you'll have to add the namespace to the XMLDoument which you might as well give a name in the code, and the include the prefix in the XPATH query (it doesn't matter that the prefixes are different between the xml document and the xpath, as long as the namespaces sort it out)
SO, while you are using an XPath like /report/subreport/record/field/value, you actually need to first set the namespace of your document:
pXMLDoc->setProperty(_bstr_t("SelectionNamespaces"),
_bstr_t("xmlns:r="http://www.**.com/**"));
and then selectNodes() using /r:report/r:subreport/r:record/r:field/r:value
I see no reference to a namespace when you're selecting nodes. I'd expect this to be the fundamental problem.