abarb
(Ana Bárbara)
February 6, 2023, 5:21pm
1
Hi, I've been having trouble to get this part of my custom view to work. So, my goal is to generate a python dictionary with the generateTableStats () function on my python file, which returns the dictionary I want to generate a table with. This is what I have on mine .pt file, that its not working currently.
<div id="processosContainer" class="tab autotoc-section">
<table id="processos-statistic" tal:define="dict python:generateTableStats()">
<tr>
<th i18n:translate="" style="width:50%; padding:5px; text-align:center;">Tipo de Processo</th>
<th i18n:translate="processos_estrutura" style="width:50%; padding:5px; text-align:center;">Número de Processos a tratar</th>
</tr>
<tr tal:repeat="entry dict">
<td tal:content="entry">1</td>
<td tal:content="form[entry]">Outro</td>
</tr>
</table><br />
</div>
mekell
(me-kell)
February 6, 2023, 5:31pm
2
If your function generateTableStats()
returns a dictionary you could iterate its items via (key, value) tuples:
<tr tal:repeat="(key, value) python:generateTableStats().items()">
<td tal:content="key">key</td>
<td tal:content="value">value</td>
</tr>
1 Like
abarb
(Ana Bárbara)
February 6, 2023, 5:35pm
3
Seems like it should work, but when I try it, this appears:
NameError: generateTableStats
- Expression: "python:generateTableStats().items()"
- Filename: ... uster/src/ip.reunioes/ip/reunioes/browser/reuniaoview.pt
- Location: (line 197: col 35)
- Source: ... at="(key,value) python:generateTableStats().items()">
mekell
(me-kell)
February 6, 2023, 5:39pm
4
Is the function defined in the view? Then use:
view.generateTableStats().items()
abarb
(Ana Bárbara)
February 6, 2023, 5:53pm
5
It's defined on the src/ip.example/ip/example/browser/reuniaoview.py file, still doesn't work!!
Thank you for the help btw!!
abarb
(Ana Bárbara)
February 6, 2023, 5:54pm
6
Now it says is an Attribute Error!
mekell
(me-kell)
February 6, 2023, 6:32pm
7
Did you reloaded your code or restarted your instance after the changes?
If you have the following in your reuniaoview.pt
<table>
<tr tal:repeat="(key, value) python:view.generateTableStats().items()">
<td tal:content="key"></td>
<td tal:content="value"></td>
</tr>
</table>
and a function like the following in your reuniaoview.py
def generateTableStats(self):
return {1: 2, 3: 4}
you should get a table.