def _build_date_filter(spec, report): wrapped = DateFilterSpec.wrap(spec) return DatespanFilter( name=wrapped.slug, label=wrapped.get_display(), compare_as_string=wrapped.compare_as_string, )
def _build_date_filter(spec): wrapped = DateFilterSpec.wrap(spec) return DatespanFilter( name=wrapped.slug, label=wrapped.get_display(), required=wrapped.required, )
class TestReportData(ReportDataSource): title = "Test Report" slug = "test_report" filters = [ DatespanFilter(name='datespan', required=False), ] def columns(self): return [ Column(slug="date", display_name="Date", sortable=True), Column(slug="people_tested", display_name="People Tested", sortable=False), ] @property def total_days(self): return int((self.config['datespan'].enddate - self.config['datespan'].startdate).days) def daterange(self): p = self.config['pagination'] days = range(self.total_days)[p.start:p.offset] order = self.config['ordering'].get('date', None) desc = order and order.desc for n in days: if desc: yield self.config['datespan'].enddate - timedelta(n) else: yield self.config['datespan'].startdate + timedelta(n) def get_data(self): # replace this with a generic has_parameter method if hasattr(self, 'datespan'): for date in self.daterange(): yield {'date': date, 'people_tested': random.randint(0, 50)} def get_total_records(self): return self.total_days