Please show the full traceback as well as the rest of the relevant code (i.e., table definition and grid code).
Anthony On Saturday, September 23, 2017 at 3:17:24 PM UTC-4, Alex Beskopilny wrote: > > > Hi All, > Why It's code work from controller and does error from class Exporter ? > How to access table_name ? > ( AttributeError: 'DAL' object has no attribute '"table_name"' > <https://sun.minfindnr.ru/admin/default/errors/dmlic#> ) > > class ExporterXLS(ExportClass): > label = 'XLS' > file_ext = "xls" > content_type = ".xls" > > def __init__(self, rows): > ExportClass.__init__(self, rows) > > def export(self): > import xlwt, cStringIO > > table_name= self.rows.colnames[0].split('.')[0] > tbl2=[]; row_flds=[]; row_labs=[] > > for col in self.rows.colnames: > (t,f) = col.split('.') > row_flds.append(f) > row_labs.append ( self.rows.db[t][f].label ) > > tbl2.append(row_labs) # table headres > for row in self.rows: > llist=[ row[x] for x in row_flds] > tbl2.append(llist) > #------------------------------------------------------------ > book = xlwt.Workbook() > sheet1 = book.add_sheet(table_name.decode('utf8')) > > for i, l in enumerate(tbl2): > for j, col in enumerate(l): > if isinstance(col, str): > col=col.decode('utf8') > elif isinstance(col, datetime.datetime) or isinstance(col, > datetime.date): > col = col.strftime('%d.%m.%Y') > else: > col='' > s = cStringIO.StringIO() > book.save(s) > > #------------------------------------------------------------------------- > response.headers['Content-Type'] = '.xls' > response.headers['Content-disposition'] = \ > 'attachment; filename=\"%s_%s.xls\"' % ( > request.now.strftime("%d.%m.%Y_%H%M%S") , table_name) > return s.getvalue() > > -- 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.