def autocomplete_tag_name(): report_id = request.get_json()['report_id'] term = request.get_json()['term'] check_access(lambda: auth.access_report_instances(report_id)) report = Report.select(report_id) tags = report.fetch_tags_sample(term, AUTOCOMPLETE_TAG_NAME_LIMIT) return success(result=dict(data=tags))
def render_series_spec_creator_spec(): report_id = request.get_json()['report_id'] report_instance_id = request.get_json()['report_instance_id'] template_ss = request.get_json()['template_ss'] check_access(lambda: auth.access_report_instances(report_id)) report = Report.select(report_id) report_instance = report.fetch_single_instance(report_instance_id) html = get_template_attribute('m.html', 'series_spec_creator_spec')(template_ss, report_instance) return success(result=dict(html=html))
def test_insert_and_select(self): owner_id = uuid.uuid4() r1 = Report.insert(owner_id, 'rep') self.assertIsNotNone(r1) r2 = Report.insert(owner_id, 'rep') self.assertIsNone(r2) rs = Report.select_by_name(owner_id, 'rep') self.assertEqual(r1, rs) rs2 = Report.select(rs.report_id) self.assertEqual(rs2, rs) r2 = Report.insert(owner_id, 'rep_2') self.assertIsNotNone(r2) self.assertNotEqual(r2, rs) r3 = Report.select_or_insert(owner_id, 'rep_3') r3_2 = Report.select(r3.report_id) r3_3 = Report.select_or_insert(owner_id, 'rep_3') self.assertEqual(r3, r3_2) self.assertEqual(r3, r3_3)
def test_delete_simple(self): owner_id = uuid.uuid1() r1 = Report.insert(owner_id, 'r1') r1.process_input('1') r2 = Report.insert(owner_id, 'r2') r2.process_input('2') ids = reports.fetch_reports_by_name(owner_id, 'r') self.assertEqual(2, len(ids)) r2.delete() reps = reports.fetch_reports_by_name(owner_id, 'r') self.assertEqual([r1], reps) self.assertIsNone(Report.select(r2.report_id))
def compute_series_spec(): report_id = request.get_json()['report_id'] report_instance_id = request.get_json()['report_instance_id'] sample = request.get_json()['sample'] check_access(lambda: auth.access_report_instances(report_id)) report = Report.select(report_id) report_instance = report.fetch_single_instance(report_instance_id) series_spec = dataseries.guess_series_spec(report, report_instance, sample['rowno'], sample['colno']) if series_spec is None: return error() series_spec_html = get_template_attribute('m.html', 'series_spec')(series_spec, report_instance) return success(result=dict(series_spec=series_spec, series_spec_html=series_spec_html))
def render_empty_series_spec(): report_id = request.get_json()['report_id'] report_instance_id = request.get_json()['report_instance_id'] check_access(lambda: auth.access_report_instances(report_id)) report = Report.select(report_id) report_instance = report.fetch_single_instance(report_instance_id) if report_instance.table.num_columns > 1: series_spec = dataseries.SeriesSpec(0, 0, {'op': 'eq', 'args': []}) else: series_spec = dataseries.SeriesSpec(0, -1, {'op': 'eq', 'args': ['0']}) series_spec.set_name('') series_spec_html = get_template_attribute('m.html', 'series_spec')(series_spec, report_instance) return success(result=dict(series_spec_html=series_spec_html))
def matching_cell_for_series_spec(): report_id = request.get_json()['report_id'] report_instance_id = request.get_json()['report_instance_id'] series_spec = request.get_json()['series_spec'] check_access(lambda: auth.access_report_instances(report_id)) report = Report.select(report_id) report_instance = report.fetch_single_instance(report_instance_id) if not report_instance: return error('No report instance') cell = series_spec.get_cell(report_instance) if not cell: return success() return success(result=dict(rowno=cell.rowno, colno=cell.colno))
def selected_tags_change(): report_id = request.get_json()['report_id'] tags = request.get_json()['tags'] check_access(lambda: auth.access_report_instances(report_id)) report = Report.select(report_id) latest_instance_id = report.fetch_latest_instance_id(tags) if not latest_instance_id: return error() ri = report.fetch_single_instance(latest_instance_id, tags) if not ri: return error('No report instance %s' % latest_instance_id) res = {} res['html_newest_table'] = get_template_attribute('m.html', 'table_as_html_table')(ri.table) res['latest_instance_id'] = latest_instance_id return success(result=res)
def _report_list(filter_s, last_report_id): if not filter_s: filter_s = None if last_report_id: last_report_name = Report.select(last_report_id).report_name else: last_report_name = None report_list = reports.fetch_reports_by_name(auth.logged_owner_id(), filter_s, last_report_name, REPORTS_PER_PAGE) res = [{'report': report} for report in report_list] # fill latest_instance_dt for report_d in res: report_d['latest_instance_dt'] = None latest_instance_id = report_d['report'].fetch_latest_instance_id() if latest_instance_id: latest_ri = report_d['report'].fetch_single_instance(latest_instance_id) if latest_ri: report_d['latest_instance_dt'] = latest_ri.created return res