When using SQLFORM.grid  selectable with multiple button I get the 
following phenomena:

- When I click the buttons the associated action is properly performed. 
which is the download of a zip file or excel file.
- After the download the button text of the second button changed and 
becomes equal to the first one.  
- When I click the button again, no action is performed but the text 
changes back to the original.

- If there is no row selected a flash message is show to instruct the user. 
In this case the buttons remain unchanged.  

- The problem is probably related to the " raise HTTP" part of the download 
see below.

- I do not understand what happens after the raise HTTP.

Can anybody help me with this?

Thanks, A3


Here is a fragment of the code:

@auth.requires_login()
def view_report_simple():
    qr = (db.reports.Customerid=="020030")
    fields = (db.reports.id,db.reports.Reportdate, db.reports.Reportnr, 
db.reports.Reference,db.reports.Sample_date)
    list_of_names_to_include = ['Reportdate','Reportnr','Reference']
    [setattr(f, 'readable', False) for f in db.reports if f.name not in 
list_of_names_to_include]
    left = None
    links = [dict(header='',body=lambda row: A('Pdf', 
_class='btn',_href=(URL('default','showpdf',vars=dict(id=row.reports.id, 
Reportnr= row.reports.Reportnr))),
                                               user_signature=True)),
            ]
    grid = SQLFORM.grid(qr,fields =fields,
                        orderby= 
~db.reports.Reportdate|~db.reports.Reportnr,
                        groupby = db.reports.Reportnr,
                        left = left,
                        create = False,
                        deletable = False,
                        editable = False,
                        showbuttontext=False,
                        csv=False,
                        maxtextlength = 64,
                        paginate = 10,
                        links_in_grid=True,
                        links = links,
                        selectable = [('Download selected PDFs as 
ZIP',lambda row : mapping_multiple(row)), 
                                       ('Download selected as EXCEL',lambda 
row : mapping_multiple_excel(row))
                                      ]
                       )
    heading=grid.elements('th')
    if heading:
        heading[0].append(INPUT(_type='checkbox', 
                                _id = 'check_all',
                                
_onclick="""jQuery('input[type=checkbox][name="records"]').each(function(k)
                                                {if 
($("#check_all").prop("checked")){
                                                                            
             jQuery(this).prop('checked', true);
                                                                            
         }else{
                                                                            
             jQuery(this).prop('checked', false);
                                                                            
              }
                                                });"""))
    details = DIV("Details",_id="details")
    return dict(grid=grid, details=details, reportnr="123456")

@auth.requires_login()
def mapping_multiple_excel(ids):
    #ids is equal to Reportnr because groupby = db.reports.Reportnr,
    if ids<>None and ids<>'' and len(ids)<>0:
        book = None
        buff = None
        import xlwt
        import StringIO
        buff = StringIO.StringIO()
        # This is my excel file:
        book = xlwt.Workbook()
        lent = len(ids)
        if len(ids) > 1:
            start = ids[0]
            end = ids[-1]
            filename = "Reports {start}_{end}".format(start=start, end=end)
        else:
            start = ids[0]
            filename = "Reports {start}".format(start=start)
        sheet1 = book.add_sheet('Reports')
        fields = customheaderlist
        for col in range(len(fields)):
            sheet1.write(0,col,fields[col])
        r = 1      
        for row in ids:
            Rnr = row
            q = (db.reports.Reportnr==Rnr)
            s = db(q)
            xlsrow = s.select(cache=(cache.ram, 1800)).first()
            if xlsrow == None:
                return 'Report nr %s not found' % Rnr
            report=xlsrow.get('reports')
            data = [ reports.field1, reports.field2,   ]
            for col in range(len(data)):
                sheet1.write(r,col,data[col])
            r = r + 1
        book.save(buff)
        response.headers['Content-Type']='application/vnd.ms-excel'
        response.headers['Content-Disposition'] = 'attachment; 
filename="%s.xls"' % filename
        raise HTTP(200, buff.getvalue(), **response.headers)
        #return
    else:
        session.flash = DIV("Select one or more reports")
        return
    return

-- 
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