On Sunday, November 13, 2016 at 8:57:28 PM UTC-8, lucas wrote:
>
> hey one and all,
>
> i'm reading chapter 10 in the book and it doesn't make sense and i don't 
> know how to structure my code to fit the framework.  it is confusing.
>
> so how about, if i explain what i'm trying to do and you'll tell me if i'm 
> crazy or direct me to a direction.
>
> i have a form that allows the output of the table based on various custom 
> parameters.  and i allow for the choice of the output format through a 
> radio input, either xml, cvs, or py.  once the parameters are received from 
> the form, the code queries the database, processes a custom dict based on 
> the users customs parameters from the form, and then attempts to export 
> that dict as a one of the three formats and sends the stream to the 
> requesting user for them to have on their computer.
>
> the main snippet looks like:
>
>             dct = {}
>             dct['version'] = qry[0][3]
>             dct['chromosome'] = qry[0][1]
>             dct['sequence_i'] = seqi
>             dct['binary_sequence'] = bseq
>             dct = [dct]
>             if (file_return == 'xml'):
>                 response.dct = dct
>                 return dict("hsDNA_%s_IQa.xml" % (qry[0][1]), dct)
>             elif (file_return == 'csv'):
>                 response.view = 'generic.csv'
>                 return dict(filename="hsDNA_%s_IQa.csv" % (qry[0][1]), 
> csvdata=dct)
>             else:
>                 pass
>  
> i get a 405 error on the cvs try and i don't know how to write the code 
> under the xml section.  i'm not ready to tackle the py section where pass 
> is yet.
>
> ok, let me know, lucas
>


If it's any help, the appadmin.py for returning a CSV is

def csv():
    import gluon.contenttype
    response.headers['Content-Type'] = \
        gluon.contenttype.contenttype('.csv')
    db = get_database(request)
    query = get_query(request)
    if not query:
        return None
    response.headers['Content-disposition'] = 'attachment; 
filename=%s_%s.csv'\
        % tuple(request.vars.query.split('.')[:2])
    return str(db(query, ignore_common_filters=True).select())




 In this case, query is from the form where you say something like 
"(db.tablenm.id > 400) & (db.tablenm.fault.contains("user")"


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to