I have a generic 'show_data'  function in my controller using the .represent
functions in the models to show linked fields correctly.

The clients wants the same now in the csv-downloads from the same data shown
by show_data.

There are many tables involved - it might be more than 20 and I do not want
to define a separate function or query for each one of them.  I am looking
for a way to adjust the query if any of those fields contained the
referenced data in question.

I do not know whether something like the following pseudocode is possible or
how to do it:

def csv_query(table):
    refs = []
     queryfields = db[table].fields()
     if 'teacher' in queryfields:
        refs.append('teacher')
        index = queryfields('teacher')
        queryfields.remove('teacher')
        queryfields.insert(index-1,teacher.name)
     if 'school' in queryfields:
        (you get the idea)

     return dict(queryfields=queryfields, refs = refs)

and then use the return value like this:

refs, queyfields = csv_query[table]
db(build this part of the query from refs eg (db.esp04.teacher ==
db.teacher.id) & db.esp04.school == db.school.id).select(build this part of
the query from queryfields eg(db.esp04.all the fields except 'school' and
'teacher' and those two replaced by db.school.name and db.teacher.name) )

Regards

Johann


-- 
 May grace and peace be yours in abundance through the full knowledge of God
and of Jesus our Lord!  His divine power has given us everything we need for
life and godliness through the full knowledge of the one who called us by
his own glory and excellence.
                                                    2 Pet. 1:2b,3a

Reply via email to