def get_report(ar, today=None, weeksback=1, weeksforth=0, datefmt=dd.fds): if not ar.user.profile.has_required_roles([SiteUser]): return E.p() if today is None: today = dd.today() start_date = today - ONE_DAY * today.weekday() - weeksback * SEVEN_DAYS numweeks = weeksback + weeksforth + 1 days = dict() cd = start_date numdays = numweeks * 7 for i in range(numdays): days[cd] = [] cd += ONE_DAY end_date = cd for r in REPORTERS: r(days, ar, start_date, end_date) headers = [E.th(Weekdays.choices[i][1], **ar.cellattrs) for i in range(7)] rows = [E.tr(*headers)] cd = start_date for week in range(numweeks): week = [] for weekday in range(7): chunks = days[cd] chunks.insert(0, datefmt(cd)) week.append(E.td(*chunks, **ar.cellattrs)) cd += ONE_DAY rows.append(E.tr(*week)) # print 20150420, rows return E.table(*rows, **ar.tableattrs)
def row2html(self,recno,columns,row,sums,**cellattrs): #~ logger.info("20130123 row2html %s",fields) #~ for i,fld in enumerate(self.list_fields): has_numeric_value = False cells = [] for i,col in enumerate(columns): #~ if fld.name == 'person__gsm': #~ logger.info("20120406 Store.row2list %s -> %s", fld, fld.field) #~ import pdb; pdb.set_trace() v = col.field._lino_atomizer.full_value_from_object(row,self) if v is None: td = E.td(**cellattrs) else: nv = col.value2num(v) if nv != 0: sums[i] += nv #~ try: #~ sums[i] += nv #~ except TypeError as e: #~ raise Exception("Cannot compute %r + %r" % (sums[i],nv)) has_numeric_value = True td = col.value2html(self,v,**cellattrs) col.apply_cell_format(td) self.actor.apply_cell_format(self,row,col,recno,td) cells.append(td) if self.actor.hide_zero_rows and not has_numeric_value: return None return cells
def results(self, ar): if ar is None: return cells = [] for sf in StatisticalFields.objects(): v = getattr(self, sf.field_name) cells.append(E.td( unicode(sf.text), E.br(), unicode(v), **ar.renderer.cellattrs)) return E.table(E.tr(*cells), **ar.renderer.tableattrs)
def row2html(self, recno, columns, row, sums, **cellattrs): has_numeric_value = False cells = [] for i, col in enumerate(columns): v = col.field._lino_atomizer.full_value_from_object(row, self) if v is None: td = E.td(**cellattrs) else: nv = col.value2num(v) if nv != 0: sums[i] += nv has_numeric_value = True td = col.value2html(self, v, **cellattrs) col.apply_cell_format(td) self.actor.apply_cell_format(self, row, col, recno, td) cells.append(td) if self.actor.hide_zero_rows and not has_numeric_value: return None return cells
def row2html(self, recno, columns, row, sums, **cellattrs): has_numeric_value = False cells = [] for i, col in enumerate(columns): v = col.field._lino_atomizer.full_value_from_object(row, self) if v is None: td = E.td(**cellattrs) else: nv = col.value2num(v) if nv != 0: sums[i] += nv has_numeric_value = True td = col.value2html(self, v, **cellattrs) col.apply_cell_format(td) self.actor.apply_cell_format(self, row, col, recno, td) cells.append(td) if self.actor.hide_zero_rows and not has_numeric_value: return None return cells