There are MANY ways to do what you ask. Here is one:

db.define_table('animal',Field('name'))

def index():

form=SQLFORM.factory(Field('name',default=request.vars.keywords,requires=IS_NOT_EMPTY()))
    if form.accepts(request.vars):
        redirect(URL(r=request,f='animals',vars=request.vars))
    return dict(form=form)

def animals():
    query=db.animal.name.like('%'+form.vars.name+'%')
    rows = db(query).select()
    if request.extension=='csv' return str(rows) # as csv
    link =
A('download',_href=URL(r=request,f='animals.html',vars=request.vars))
    return dict(table=SQLTABLE(rows),link=link)




On 12 Lug, 15:31, Johann Spies <[email protected]> wrote:
> Thanks Massimo,
>
> I think I am beginning understanding a bit better.
>
> Please take your example further and show the result on the screen in
> a normal html-view on which there is a link to download the stuff to
> csv-file like in the appadmin-interface.
>
> Say rows = db(query).select()) normally I would return dict(rows=rows)
> to the html-view. BTW why is is it a 'dict(x=x)' in all the examples
> and not just a return (rows)?
>
> So If I want to show it on the screen using the
> 'return(dict(rows=rows)',  how do I return the ' str(rows)'  with
> that, or do I do that in the view when the link for downloading the
> result is clicked - something like
> href="{{=URL(r=request,f='animals',args = str(rows))}}">Download as
> csv-file</a>
>
> A further question:  Is it necessary for the *.csv view to to have the
> same name as the controller lilke your
> def animals()
>
> and the view
>
> animals.csv
>
> Regards
> Johann
>
> Thanks for your patience.
>
> --
> "Finally, brethren, whatsoever things are true,  whatsoever things are
> honest, whatsoever things are  just, whatsoever things are pure,
> whatsoever things are lovely, whatsoever things are of good report; if
> there be any virtue, and if there be any praise, think on these
> things."    Philippians 4:8

Reply via email to