Let me try a simple example first ...

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):
 
link=A('download',_href=URL(r=request,f='animals.csv',vars=request.vars)))
    else: link=None
    return dict(form=form,link=link)

def animals():
    query=db.animal.name.like('%'+form.vars.name+'%')
    return str(db(query).select()) # as csv

The only issue here is how to pass a form from index to animals. You
see how this is achieved here

   vars=request.vars in index().... form.vars.name in animals().

How more complicated do you need it? Can you provide a concrete
example?


Massimo

On 12 Lug, 14:18, Johann Spies <[email protected]> wrote:
> I could after several months not advance further than the "animals"
> example in the manual in using csv for downloads.  Several questions
> and help from members on this list did not help me to achieve a single
> csv download in the following scenario:
>
> *      user uses a form to define a selection
> *      result of selection showed on screen with button to download as csv.
>
> It should be simple and is simple in the "animals"  example where
> there are one controller and one (csv) view directly related to each
> other.  In all the examples and documentation I have seen where forms
> are used, redirection to other functions where the variables of the
> form get handled come into play and that is where my problem starts.
> I don' t know how to get the result of the secondary function to the
> cStringIO.StringIO()-stream.
>
> I do not have problem doing the csv-thing in the shell but as soon as
> this jumping from " form-function ->  form-view ->  back to secondary
> function with secondary view"  comes into play, I lost the plot with
> csv.
>
> If I do not get help within the next day this is a showstopper for me.
>  Please help me.
>
> Regards
> Johann
> --
> "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