Would you show your models... You make complexe queries, maybe your models are not pretty well design for the purpose.
Richard On Wed, May 16, 2012 at 3:22 PM, Fabiano Faver <far...@gmail.com> wrote: > But because of the group by clause it are too slow and I curious to know > if I can query each company separately do what i must with the data and > show the result on page as soon as they are ready > > > 2012/5/16 Fabiano Faver <far...@gmail.com> > >> I'm trying to display a table with the name of some companies with the >> background color of each TD or DIV dependent of the last day the printers >> company were checked >> >> this it what I have now: >> >> def exibicao_empresas(): >> #get companies >> empr = db(auth.accessible_query('**read', db.empresa, >> auth.user_id)).select() >> tabela_empresa = TABLE( _class='grid_color') >> tr = TR() >> columns = 6 >> count_cl = 0 >> #for each company get all their printers and the last date it were >> checked >> for td in empr: >> lista_1 = [] >> count_menos = count_mais = 0 >> #getting printers >> impress = db((db.impressora.id_filial_**empresa== >> db.filial_empresa.id)**&(db.filial_empresa.id_**empresa==td.id))._select( >> db.**impressora.id <http://db.impressora.id/>) >> >> quant_impressoras = len(impress) >> maxdata = db.contadores.data.max() >> #getting dates >> dias = db(db.contadores.id_**impressora.belongs(impress)).**select( >> maxdata,db.contadores.id_**impressora, groupby=db.contadores.id_** >> impressora) >> >> # checking to show the indicative background-color >> for dia in dias: >> if (((dia_hoje-dia[maxdata]).days >= 1) and >> ((dia_hoje-dia[maxdata]).days < 5)): count_menos = count_menos+1 >> if ((dia_hoje-dia[maxdata]).days > 5): count_mais = >> count_mais+1 >> bg_td = 'background-color: #99FFCC' >> if count_menos: bg_td = 'background-color: #EAEA9F' >> if count_mais == len(dias): bg_td = 'background-color: #FF9999' >> >> tr.append(TD(td.nome_fantasia, _style = bg_td)) >> count_cl = count_cl + 1 >> if count_cl==columns: >> tabela_empresa.append(tr) >> tr=TR() >> else: >> if len(tr): tabela_empresa.append(tr) >> >> return dict(tabela_empresa =tabela_empresa ) >> >>> >>> >