Inline notation of TYPO3 Fluid view helper `f:for` - fluid

I would like to fill an attribute value in a TYPO3 Fluid template with a loop (f:for) by using its inline notation:
<div class="one two three">[...]</div>
Does anybody know how to do that?

In the meanwhile I found a solution for my problem. To print all items of an array you could do something like {x -> f:for(each: {0: 'one', 1: 'two', 2: 'three'}, as: 'x')}. But this will result in: onetwothree. To fix that the view helper f:if helps:
<div class="{f:if(condition: i.isLast, then: '{x}', else: '{x} ')
-> f:for(each: {0: 'one', 1: 'two', 2: 'three'}, as: 'x', iteration: 'i')}">
[...]
</div>

You can tweak the solution of #witrin a litte more and write ind completely inline:
{f:if(condition: i.isLast, then: '{x}', else: '{x} ') -> f:for(each: '{item.thing}', as: 'x', iteration: 'i')}

Please find following inline notations,
It helps you lot.
Inline Notation for for loop
Original -> `<f:for each="{data.title}" as="title"> {title} </f:for>`
Inline Notation -> {title -> f:for(each: '{data.title}', as: 'title')}
Inline Notation for date
Date :-> `<f:format.date cldrFormat="MMMM y" forceLocale="{true}" localeFormatType="date">1-{calendar.month}-{calendar.year} 00:00:00</f:format.date>`
Inline Notation :-> {f:format.date(date:'1-{calendar.month}-{calendar.year} 00:00:00',cldrFormat:'MMMM y',localeFormatType: 'date', forceLocale: true)}
so on...

I guess you are looking for some 'advanced' array handeling in fluid?
have a look at https://fluidtypo3.org/viewhelpers/vhs/master.html.

Related

How to write/update some inherited fields in product category to multicompany

I was inherited some fields in product.category model and i want to show that some other fields on my other companies.. I am tried to give the answer on create function and Also tried on other Button But i can't write the values that i give in the main company to other companies.. Please Help me to find the Answer..
#api.model
def create(self, vals_list):
res = super(ProductCentralized, self).create(vals_list)
vals = []
vals.append({
'property_cost_method': res.property_cost_method,
'name':res.name,
'property_valuation': res.property_valuation,
'property_stock_valuation_account_id': res.property_stock_valuation_account_id,
'property_stock_journal': res.property_stock_journal,
'property_stock_account_input_categ_id': res.property_stock_account_input_categ_id,
'property_stock_account_output_categ_id': res.property_stock_account_output_categ_id,
})
res.sudo().create({'property_cost_method': self.property_cost_method,
'name': self.name,
'property_valuation': self.property_valuation,
'property_stock_valuation_account_id': self.property_stock_valuation_account_id,
'property_stock_journal': self.property_stock_journal,
'property_stock_account_input_categ_id': self.property_stock_account_input_categ_id,
'property_stock_account_output_categ_id': self.property_stock_account_output_categ_id})
return res
Please Help me to correct this code or using another button.. Thanks in Advance..
Consider changing the corresponding view : "res.partner.form" instead. You can find it this way : in App Settings, switch to debug mode by adding "?debug=1" in your url, reload the page, then go to the new Technical Menu-tab > View.
Then you can display your partner/company(id= 1344 ) fields, using :
For Back-Office :
<t t-esc="self.env['res.partner'].browse(1344).name" />
For Front-Office :
<t t-esc="request.env['res.partner'].browse(1344).name" />
Or you can display your product_template (id= 135 ) fields, using :
<t t-esc="self.env['product.template'].browse(135).property_valuation" />
Or you can display your stock fields, using :
<t t-esc="self.env['stock.quant'].search([('product_id','=','5')]).location_id.name" />

Odoo 11: How to correctly implement #api.onchange?

I want to compute a telephone number, if the number in the 8 position is either "0" or "1" I want to print just the last 4 numbers with a "(3)" before them, otherwise just print the 4 numbers, but what is happening is that my code is printing "0.0" and I don't know why, I'll appreciate your help...
This is my python code:
class Employee(models.Model):
_inherit = "hr.employee"
marcado_rapido = fields.Float("MarcadoRapido",compute='_compute_marcado_rapido')
#api.onchange("emp.marcado_rapido")
def onchange_compute_marcado_rapido(self):
for num in self:
num = "809-257-1457"
if num[8] in ('0','1'):
"(3)"+num[8:]
This is my xml code:
<td>
<t t-foreach="env['hr.employee'].search([('department_id', '=', dep.id)])" t-as="emp">
<div class="contact_form">
<img t-if="emp.image" t-att-src="'data:image/png;base64,%s' % to_text(emp.image)"/>
<div class="bloqueP">
<div class="bloque" t-field="emp.marcado_rapido"/>
</div>
</div>
</t>
</td>
#onchange only supports simple field names, dotted names (fields of relational fields e.g. partner_id.tz) are not supported and will be ignored
You can check the official documentation on how the onchange decorator works and what are the limitations.
0.0 is the default value for float fields and the value of marcado_rapido is computed using _compute_marcado_rapido function. If the field updated in onchange method depends on marcado_rapido field value, you can compute its value using the same method
You should use compute decoration instead of onchange, but compute method aproach always depend in someone else field. My sugestion is use a another computed field, something like this:
class Employee(models.Model):
_inherit = 'hr.employee'
# If your number contains special characters(like '-') you should use `Char` insted of `float`
num_telefono = fields.Char('Num. Telefono')
marcado_rapido = fields.Char('MarcadoRapido', compute='_compute_marcado_rapido')
#api.depends('num_telefono')
def _compute_marcado_rapido(self):
for rec in self:
num = rec.num_telefono[-4:]
rec.marcado_rapido = '(3){}'.format(num) if num[:1] in ('0','1') else num
Now you can call marcado_rapido from your XML.
I hope this answer can be helful for you.

List of dictionarys to dataframe

im trying to make a dataframe out of a list of dictionaries. I am quite new at this whole programming thing, and google just makes me more confused. That is why i am turning to you guys hoping for some assistance.
The first two list values (YV01', '3nP3RFgGnBrOfILK4DF2Tp) i would like to have under columns called: Name and GlobalId. I would lie to drop Pset_wallcommon, AC_Pset_RenovationAndPhasing, and BaseQuantities. And use the rest of the keys(if that what they are called) as column names.
It would be great if someone could give me the right push :)
For the record: Im am parsing an Ifc file with the IfcOpenshell package
The data:
['YV01', '3nP3RFgGnBrOfILK4DF2Tp', {'Pset_WallCommon': {'Combustible': False, 'Compartmentation': False, 'ExtendToStructure': False, 'SurfaceSpreadOfFlame': '', 'ThermalTransmittance': 0.0, 'Reference': '', 'AcousticRating': '', 'FireRating': '', 'LoadBearing': False, 'IsExternal': False}, 'AC_Pset_RenovationAndPhasing': {'Renovation Status': 'New'}, 'BaseQuantities': {'Length': 13786.7314346, 'Height': 2700.0, 'Width': 276.0, 'GrossFootprintArea': 3.88131387595, 'NetFootprintArea': 3.88131387595, 'GrossSideArea': 37.9693748734, 'NetSideArea': 37.9693748734, 'GrossVolume': 10.4795474651, 'NetVolume': 10.4795474651}}, 'YV01', '1M4JyBJhXD5xt8fBFUcjUU', {'Pset_WallCommon': {'Combustible': False, 'Compartmentation': False, 'ExtendToStructure': False, 'SurfaceSpreadOfFlame': '', 'ThermalTransmittance': 0.0, 'Reference': '', 'AcousticRating': '', 'FireRating': '', 'LoadBearing': False, 'IsExternal': False}, 'AC_Pset_RenovationAndPhasing': {'Renovation Status': 'New'}, 'BaseQuantities': {'Length': 6166.67382573, 'Height': 2700.0, 'Width': 276.0, 'GrossFootprintArea': 1.6258259759, 'NetFootprintArea': 1.6258259759, 'GrossSideArea': 15.9048193295, 'NetSideArea': 15.9048193295, 'GrossVolume': 4.38973013494, 'NetVolume': 4.38973013494}}
all_walls = ifc_file.by_type('IfcWall')
wallList = []
for wall in all_walls:
propertySets = (ifcopenshell.util.element.get_psets(wall))
wallList.append(wall.Name)
wallList.append(wall.GlobalId)
wallList.append(propertySets)
print(wallList)
wall_table = pd.DataFrame.from_records(wallList)
print(wall_table)
I have tried these basic pd.DataFrame.from_dict/records/arrays(data)
but the output looks like this
enter image description here
UPDATE: Thank you so much for your help, i am learning alot from this!
So i made a dictionary out of the wallList, and flattened the dict. like this:
#list of walls
for wall in all_walls:
propertySets = (ifcopenshell.util.element.get_psets(wall))
wallList.append(wall.Name)
wallList.append(wall.GlobalId)
wallList.append(propertySets)
#dict from list
wall_dict = {i: wallList[i] for i in range(0, len(wallList))}
new_dict = {}
#flattening dict
for key, value in wall_dict.items():
if isinstance(value, dict):
for key in value.keys():
for key2 in value[key].keys():
new_dict[key + '_' + key2] = value[key][key2]
else:
new_dict[key] = value
wall_table = pd.DataFrame.from_dict(new_dict, orient='index')
print(wall_table)
It seems to work pretty good, the only problem is that the dataframe contains all walls, but only propertyset data from the first in the list. I cant seem to understand how the dict flattening loop works. I would also like the index names (Pset_WallCommon_Combustible, and so on) to be the columns in my dataframe. Is that possible?
enter image description here
EDIT : Simply flattening a list as i did goes nowhere. Actually, i think you should drop this list thing altogether and try to load the Dataframe from a dictionnary. We'd need to see what does all_walls look like to help you for that, tho.
Have you tried directly loading the all_walls dictionary into a dataframe : df = pd.Dataframe.from_dict(all_walls) ?
I think if that doesnt work, flattening the dictionnaries in a fashion similar to the following should do the trick.
new_dict = {}
for key, value in all_walls.items():
if isinstance(value, dict):
for key in value.keys():
for key2 in value[key].keys():
new_dict[key + '_' + key2] = value[key][key2]
else:
new_dict[key] = value

Typo3 Fluid: elseif inline notation

Is there an inline notation for the following example?
<f:if condition="{value}==1">
<f:then>Value is 1</f:then>
<f:else if="{value}==2">Value is 2</f:else>
</f:if>
Thanks for your help
probably it will be the cascading of if-viewhelpers:
{f:if(condition:'{value}==1',
then:'Value is 1',
else:'{f:if(condition:\'{value}=2\', then:\'Value is 2\')}'
)}
with the usual drawback of escaping string-delimiter for stacked inline viewhelpers.
your condition will default to 'Value is 2' although the value might not be ... this is not true, anyhow a bit more complete:
<f:if condition="{value}==1">
<f:then>Value is 1</f:then>
<f:else if="{value}==2">Value is 2</f:else>
<f:else>Value is not valid</f:else>
</f:if>
simple inline annotation that does not output anything if the two conditions are not met:
{f:if(condition:'{value}==1',
then: 'Value is 1',
else: '{f:if(condition:\'{value}==2\',then: \'Value is 2\')}'
)}
add the else clause in the second condition:
{f:if(condition:'{value}==1',
then: 'Value is 1',
else: '{f:if(condition:\'{value}==2\',
then: \'Value is 2\',
else: \'Value is not valid\'
)}'
)}

Beautiful Soup (Python) : find all kind of div, p, span, etc, with a given class

Given a specific URL rendered with Python/requests, I need to findAll kind of div, h3, p, etc with class name "Specific".
This works partially :
data = soup.findAll("div", { "class" : "Specific" })
because it only finds div.
I am looking for something like :
data = soup.findAll("*", { "class" : "Specific" })
Good answer from soon :
data = soup.find_all(class_='Specific')
You should specify class_ parameter in the find_all method. name parameter may be omitted as well:
In [12]: html = '''<div class='Specific'><span class='Specific c1'></span><p class='NonSpecific'></p></div>'''
In [13]: soup = bs4.BeautifulSoup(html, 'html.parser')
In [14]: soup.find_all(class_='Specific')
Out[14]:
[<div class="Specific"><span class="Specific c1"></span><p class="NonSpecific"></p></div>,
<span class="Specific c1"></span>]