xml search and update using python - python-3.x

my sample xml object is:
<Assessment version="10" dateCreated="4/19/2020 10:41:20 PM">
<Section name="Space">
<Glossary>
<Item name="***"><b>Indicates high priority data that is required</b></Item>
</Glossary>
<InputNumber type="int" min="0" max="100" title="[1a] q2 some data">
<Value>20</Value>
</InputNumber>
<InputNumber type="int" min="0" max="10000" title="[2] some data">
<Value>1</Value>
</InputNumber>
<InputNumber type="int" min="0" max="10000" title="[3] some text">
<Value>2</Value>
</InputNumber>
</Section>
<Section name="Power">
<Glossary>
<Item name="***"><b>Indicates high priority data that is required</b></Item>
</Glossary>
<InputNumber type="int" min="0" max="100000" title="[8] some text">
<Value>15</Value>
</InputNumber>
<PickList title="[11] some text">
<Option selected="true">Yes</Option>
<Option>No</Option>
<Option>there is no UPS</Option>
</PickList>
</Section>
<Section name="Cooling">
<Glossary>
<Item name="***"><b>Indicates high priority data that is required</b></Item>
</Glossary>
<InputNumber type="int" min="0" max="100000" title="[18] some text">
<Value>30</Value>
</InputNumber>
</InputText>
<InputText title="[21] some data">
<Value>3</Value>
</InputText>
</Section>
<Section name="Comments">
<InputTextArea title="[22] General Comments" format="normal">
<Value>test value for capacity assessment test by monika</Value>
</InputTextArea>
</Section>
</Assessment>
i get this from database
In my python script:
template= cursor.fetchall()
for row in template:
#xmlTemplate = ET.ElementTree(ET.fromstring(row[6]))
xmlTemplateStr = row[6]
xmlTemplate = ET.ElementTree(ET.fromstring(xmlTemplateStr))
root = ET.fromstring(xmlTemplateStr)
i need to find the node based on the number and update the value of that perticular node
for example:
if in need to update the following value to 4:
</InputText>
<InputText title="[21] some data">
<Value>3</Value>
</InputText>
i need to search the node with key as [21] and update the value of that node to 4
</InputText>
<InputText title="[21] some data">
<Value>4</Value>
</InputText>
How do i do it?

You can do this with lxml, using xpath:
assess = """[your xml above - corrected]""" #note: the sample xml in the question was invalid because it had an extra tag
from lxml import etree
doc = etree.XML(assess.encode('utf-8'))
val = doc.xpath('//InputText[#title="[21] some data"]/Value')
val[0].text = '4'
print(etree.tostring(doc).decode())
Relevant part of the output:
<InputText title="[21] some data">
<Value>4</Value>
</InputText>

Related

How to withdraw either currency or a percentage of odoo depending on selector

How to withdraw either currency or a percentage of odoo depending on selector.
.py
#api.depends('discount_type', 'discount_rate', 'amount_total')
def _compute_amount_discount(self):
for act in self:
amount_untaxed = amount_discount = discount_rate = 0.0
for line in act.reconciliation_act_line_ids:
amount_untaxed += line.price_subtotal
if self.discount_type == 'percent':
amount_discount = amount_untaxed * self.discount_rate / 100
else:
amount_discount = self.discount_rate
act.update({
'amount_total_with_discount': amount_untaxed - amount_discount,
'amount_discount': - amount_discount,
'amount_total': amount_untaxed,
})
.xml
<div class="container">
<div class="row justify-content-between">
<div class="col-4">
<group name="discount"
attrs="{'invisible': [('apply_discount', '=', False)]}">
<field name="discount_type"/>
<field name="discount_rate"/>
</group>
</div>
<div class="col-4">
<group>
<field name="amount_total" nolabel="0" widget='monetary'
options="{'currency_field': 'currency_id'}"/>
<field name="amount_discount" widget='monetary'
attrs="{'invisible': [('apply_discount', '=', False)]}"/>
<field name="amount_total_with_discount" widget='monetary'
attrs="{'invisible': [('apply_discount', '=', False)]}"/>
<field name="amount_total_executors" nolabel="0" widget='monetary'
options="{'currency_field': 'currency_id'}"/>
</group>
</div>
</div>
</div>
I can add a fixed currency, but when I switch to percentages, the currency stays there, of course (widget='monetary')
You need to convert the field data-type which I don't recommend. It may have a chance to lose data.
If a field declared with Monetary data-type, it will ignore your xml changes. But if you convert that field into Float and then remove the widget. It should work.
EDIT
Add one more field called discount_rate_percent. Display that field based on selector. Something like:
<!-- $ Discount rate display -->
<label for="discount_rate" attrs="{'invisible':[('apply_discount', '=', 'percentage')]}"/>
<div attrs="{'invisible':[('apply_discount', '=', 'percentage')]}">
<field name="discount_rate" class="oe_inline" attrs="{'invisible':[('apply_discount', '=', 'percentage')]}"/>
$
</div>
<!-- % Discount rate display -->
<label for="discount_rate_percent" attrs="{'invisible':[('apply_discount', '=', 'fixed')]}"/>
<div attrs="{'invisible':[('apply_discount', '=', 'fixed')]}">
<field name="discount_rate_percent" class="oe_inline" attrs="{'invisible':[('apply_discount', '=', 'fixed')]}"/>
%
</div>

Dialog box shows blank UI5

I have defined my dialog view as follows. For some reason it gives blank dialog box. If I uncomment the already commented control and comment the entire , then it works fine. I do not understand what is possible problem with the . Same code works for another dialog with the
View.xml
<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core" xmlns:l="sap.ui.layout">
<Dialog id="editCompanyDialog" contentWidth="800px" contentHeight="100%" afterClose="onCancelEditCompanyDialog"
busy="{sharedApp>/oBusy/busy}" busyIndicatorDelay="{sharedApp/oBusy/delay}">
<!--<Toolbar class="modal-header">-->
<!-- <Text text="Edit Company Information" class="modal-title"/>-->
<!-- <core:Icon class="modal-logo" src="sap-icon://edit-icon"/>-->
<!-- <Button text="x" class="btn-link modal-close-button" press="onCancelEditCompanyDialog"/>-->
<!--</Toolbar>-->
<subHeader>
<Toolbar>
<Text class="sapUiSmallMarginBegin dialogTitle" text="{/headerText}"/>
<ToolbarSpacer></ToolbarSpacer>
<Button class="btn-link-grey" custdata:name="maDialog" icon="sap-icon://decline" tooltip="{i18n>GB_Close}" press="onCloseDialog"/>
</Toolbar>
</subHeader>
<Panel>
<content>
<l:BlockLayout id="editCompanyBlockLayout">
<l:BlockLayoutRow>
<l:BlockLayoutCell>
<VBox>
<ObjectIdentifier text="Edit your company information"/>
</VBox>
</l:BlockLayoutCell>
</l:BlockLayoutRow>
<l:BlockLayoutRow>
<l:BlockLayoutCell>
<VBox>
<Label text="{i18n>CC_Company}" labelFor="Name1"/>
<Input id="Name1" textAlign="Left" value="{EditCompany>/Input/Name1}" fieldGroupIds="FC"/>
</VBox>
</l:BlockLayoutCell>
</l:BlockLayoutRow>
</content>
</Panel>
In your button, you're using the custom data namespace, but haven't declared it.
Add
xmlns:custdata="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1"
to the top of your view in the core:FragmentDefinition tag

Accessibility issue with p:select

Using primefaces 5.1, i'm testing my app with WCAG validator and the following code is breaking a guideline:
<p:outputLabel for="selectHowMuch" value="Do you feel edgy lately ?" />
<p:selectOneMenu id="selectHowMuch" value="Yes">
<f:selectItem itemLabel="Argggg" itemValue="3" />
<f:selectItem itemLabel="Yes" itemValue="2" />
<f:selectItem itemLabel="hmmm" itemValue="1" />
<f:selectItem itemLabel="NO!" itemValue="0" />
</p:selectOneMenu>
the broken guideline is
Success Criteria 1.3.1 Info and Relationships (A) Check 91: select
element missing an associated label.
Repair: Add a label element that surrounds the control's label. Set
the for attribute on the label element to the same value as the id
attribute of the control. And/or add a title attribute to the input
element. And/or create a label element that contains the input
element.
Error Line 1, Column 16711:
<select id="_testapp_WAR_testapp001SNAPSHOT_:j_idt3:selectHowMuch_input"
Note that the p:outputLabel actually did help (if i remove it, i get more errors), but it looks like it's not covering the <select> _input label
I also noticed that the same happens for other select components.
Any ideas to get around this ?
Edit: here's my generated code:
<label id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:j_idt62" class="ui-outputlabel ui-widget"
for="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_focus">Do you feel edgy lately ?</label>
<div id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch" class="ui-selectonemenu ui-widget ui-state-default ui-corner-all">
<div class="ui-helper-hidden-accessible">
<input
id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_focus"
name="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_focus"
type="text" autocomplete="off" />
</div>
<div class="ui-helper-hidden-accessible">
<select
id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_input"
name="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_input"
tabindex="-1"><option value="3">Argggg</option>
<option value="2">Yes</option>
<option value="1">hmmm</option>
<option value="0">NO!</option></select>
</div>
<label
id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_label"
class="ui-selectonemenu-label ui-inputfield ui-corner-all"> </label>
<div
class="ui-selectonemenu-trigger ui-state-default ui-corner-right">
<span class="ui-icon ui-icon-triangle-1-s ui-c"></span>
</div>
<div
id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_panel"
class="ui-selectonemenu-panel ui-widget-content ui-corner-all ui-helper-hidden ui-shadow">
<div class="ui-selectonemenu-items-wrapper"
style="height: auto">
<ul
class="ui-selectonemenu-items ui-selectonemenu-list ui-widget-content ui-widget ui-corner-all ui-helper-reset">
<li
class="ui-selectonemenu-item ui-selectonemenu-list-item ui-corner-all"
data-label="Argggg">Argggg</li>
<li
class="ui-selectonemenu-item ui-selectonemenu-list-item ui-corner-all"
data-label="Yes">Yes</li>
<li
class="ui-selectonemenu-item ui-selectonemenu-list-item ui-corner-all"
data-label="hmmm">hmmm</li>
<li
class="ui-selectonemenu-item ui-selectonemenu-list-item ui-corner-all"
data-label="NO!">NO!</li>
</ul>
</div>
</div>
</div>
<script id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_s"
type="text/javascript">$(function(){PrimeFaces.cw("SelectOneMenu","widget__tutorial_WAR_tutorial001SNAPSHOT__j_idt3_selectHowMuch",{id:"_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch",widgetVar:"widget__tutorial_WAR_tutorial001SNAPSHOT__j_idt3_selectHowMuch"})});</script>
Sorry, i have to contrast with the last answer...
In your example, this select does not have an associated label
<select
id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_input"
name="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_input"
tabindex="-1"><option value="3">Argggg</option>
<option value="2">Yes</option>
<option value="1">hmmm</option>
<option value="0">NO!</option></select>
There is one label after it who might have been thought for it, but it does not have a for attribute and does not contain the select tag.
<label
id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_label"
class="ui-selectonemenu-label ui-inputfield ui-corner-all"> </label>
As I understand, both the input and the select are generated for this one field and only one label is correctly associated with the input. This looks like a bug in primefaces, and you should ask their staff to make some corrections...
Also there would be more correction to do, because the first label should be associated with the select element, and the input element be invisible to screenreaders if I correctly understand.
There is nothing wrong with your markup per se. It conforms to one of the accepted techniques.
http://www.w3.org/TR/2015/NOTE-WCAG20-TECHS-20150226/H44#H44-ex1
Although that example shows use with an <input> element, it is equally valid with a <select> element.
This looks like a bug in your validator. I suggest trying FireEyes http://www.deque.com/products/fireeyes/fireeyes-installation/

ExpressionEngine Zoo Visitor field with Channel Images outputs four images for every one

I have a Zoo Visitor field called "member_gallery" which is a channel images field. Whenever I show the images, it creates 4 images for each one. However I do not want to output 4 images for each one. I want to output one image for each one. Here is the code I write:
{visitor:member_gallery}
{exp:channel_images:images entry_id="{entry_id}"}
<img src="{image:url:large}" alt="{image:title}" />
{/exp:channel_images:images}
{/visitor:member_gallery}
Here is the markup it spits out
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(1)__large.jpeg" alt="Images (1)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(1)__large.jpeg" alt="Images (1)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(1)__large.jpeg" alt="Images (1)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(1)__large.jpeg" alt="Images (1)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(2)__large.jpeg" alt="Images (2)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(2)__large.jpeg" alt="Images (2)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(2)__large.jpeg" alt="Images (2)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(2)__large.jpeg" alt="Images (2)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(3)__large.jpeg" alt="Images (3)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(3)__large.jpeg" alt="Images (3)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(3)__large.jpeg" alt="Images (3)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(3)__large.jpeg" alt="Images (3)" />
To be clear, I do not want to display 4 images for every one. If you couldn't figure that out. To be extremely EXTREMELY clear, here is my question; How do I write this so I only get 1 image for each one I have uploaded, rather than 4? Thank you. I apologize for any confusion.
You don't need to use the channel entries tag within Zoo Visitor...
It looks as though you have a loop inside a loop, hence the duplication. Have you tried removing the channel entries tag?

Ribbon button should be hidden based on lead status - CRM 2011

I have custom button in lead ribbon. The custom button should be hidden when lead is qualified. How can I do that? Can any one please explain. I appreciate.
You can actually accomplish this entirely with built-in DisplayRule functionality. When a Lead is qualified, the StatusCode property is set to "Qualified", which translates into an OptionSet value of "3". You can check for the value of this property in a ValueRule and display/hide the control appropriately. I can think of two ways to achieve this:
Erik Pool's Visual Ribbon Editor
RibbonXml
<RibbonDiffXml>
<CustomActions>
<CustomAction Id="CompanyName.Form.lead.MainTab.Actions.Sample.CustomAction" Location="Mscrm.Form.lead.MainTab.Actions.Controls._children" Sequence="41">
<CommandUIDefinition>
<Button Id="CompanyName.Form.lead.MainTab.Actions.Sample" Command="CompanyName.Form.lead.MainTab.Actions.Sample.Command" Sequence="29" ToolTipTitle="$LocLabels:CompanyName.Form.lead.MainTab.Actions.Sample.LabelText" LabelText="$LocLabels:CompanyName.Form.lead.MainTab.Actions.Sample.LabelText" ToolTipDescription="$LocLabels:CompanyName.Form.lead.MainTab.Actions.Sample.Description" TemplateAlias="isv" />
</CommandUIDefinition>
</CustomAction>
</CustomActions>
<Templates>
<RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
</Templates>
<CommandDefinitions>
<CommandDefinition Id="CompanyName.Form.lead.MainTab.Actions.Sample.Command">
<EnableRules />
<DisplayRules>
<DisplayRule Id="CompanyName.Form.lead.MainTab.Actions.Sample.Command.DisplayRule.ValueRule" />
</DisplayRules>
<Actions>
<Url Address="http://www.bing.com" />
</Actions>
</CommandDefinition>
</CommandDefinitions>
<RuleDefinitions>
<TabDisplayRules />
<DisplayRules>
<DisplayRule Id="CompanyName.Form.lead.MainTab.Actions.Sample.Command.DisplayRule.ValueRule">
<ValueRule Field="statuscode" Value="3" />
</DisplayRule>
</DisplayRules>
<EnableRules />
</RuleDefinitions>
<LocLabels>
<LocLabel Id="CompanyName.Form.lead.MainTab.Actions.Sample.LabelText">
<Titles>
<Title languagecode="1033" description="Sample" />
</Titles>
</LocLabel>
<LocLabel Id="CompanyName.Form.lead.MainTab.Actions.Sample.Description">
<Titles>
<Title languagecode="1033" description="Sample Description" />
</Titles>
</LocLabel>
</LocLabels>
</RibbonDiffXml>

Resources