Problem understaning nesting for loops in ODS tempalte

Asked by Ahmed Toulan on 2014-05-19

Hi,

I am trying to create a small reporting engine and want to use pod as my rendering layer. I am having problems understanding how to nest loops, and what is the scope of each loop..

To clarify, my data is a tree-like structure. I have an object that has a details attribute. This attribute is a list to other objects that has details attribute .. and so on.

I would like to be able to render this data in a ODS template as follows:

Group X haeder
--------------
Group Y header
--------------
.
.
.
Details
.
.
.
--------------
Group Y footer
--------------
Group X footer

In django templates I was able to achieve this since I have full control over my loops and its scope. Can you please tell me how to achieve the same result using pod ods templates ? Currently, pod gives me a NameError when I try to use the iterator from a previous for loop.

P.S: I am using appy version 0.8.5 installed from pip in a python2.7 virtualenv.

Thanks.

Question information

Language:
English Edit question
Status:
Answered
For:
Appy Edit question
Assignee:
No assignee Edit question
Last query:
2014-05-19
Last reply:
2014-05-27
Magnus (fcovillarreal) said : #1

I did this, it's very easy.

Just nest lists and make Data Holders (an empty class) or Dictionaries so you can store the data in them. In python is like this:

class DataHolder():
    pass

Then you can add data in it and then pass it to the render. This is an example on the fly:

listX = []
for x in range(10): #Or whatever your cycle is
    groupX = DataHolder()
    groupX.id = x
    groupX.name = 'SomeData'
    listX.append(groupX)

for i in listX:
    groupY = DataHolder()
    groupY.detail = 'More data Data'
    groupY.detailList = ['orange','banana','lemons','etc']
    i.groupY = groupY

At this point you have a list of nested items in listX. This is the list you send to the render and in the appy you need to make a loop. Insert a table and in one row insert a comment. Then type something like this (for this example):

do row for x in listX

And you can print the info in the cells by typing "x.id", "x.name" and "x.groupY.detail" in them with "change control on".

For printing the detail you must insert another table inside one cell and then make another loop. In the firts row add a comment and type something like this:

do row for y in x.groupY.detailList:

This will make a table inside a cell and print in them 'orange','banana','lemons','etc' one of them in each row.

I hope this helped you and sorry for my english, is not my native language.

Regards.

Can you help with this problem?

Provide an answer of your own, or ask Ahmed Toulan for more information if necessary.

To post a message you must log in.