Ejemplo n.º 1
0
def report_instances_days():
    report_name = request.get_json()['report_name']
    tags = request.get_json().get('tags')

    check_access(lambda: auth.access_profile())

    report = Report.select_by_name(auth.logged_owner_id(), report_name)
    days_dts = report.fetch_days(tags)
    days = [dt.strftime('%Y-%m-%d') for dt in days_dts]

    return success(result=dict(days=days))
Ejemplo n.º 2
0
def report_instance_for_viewer():
    report_name = request.get_json()['report_name']
    tags = request.get_json().get('tags')
    curr_report_instance_id = request.get_json()['curr_report_instance_id']
    direction = request.get_json().get('direction')
    search_date = request.get_json().get('search_date')

    check_access(lambda: auth.access_profile())

    report = Report.select_by_name(auth.logged_owner_id(), report_name)

    if not curr_report_instance_id:
        curr_report_instance_id = report.fetch_latest_instance_id(tags)
        if not curr_report_instance_id:
            return error()
    if not direction:
        if search_date is not None:
            ri = report.find_report_instance_by_dt(search_date, tags)
        else:
            ri = report.fetch_single_instance(curr_report_instance_id)
    elif direction == 'next':
        ri = report.fetch_next_instance(curr_report_instance_id, tags)
    elif direction == 'prev':
        ri = report.fetch_prev_instance(curr_report_instance_id, tags)
    else:
        return error('Wrong direction')
    res = {}
    res['report_id'] = report.report_id
    res['report_has_tags'] = report.has_tags()
    if ri:
        res['html_newest_table'] = get_template_attribute('m.html', 'table_as_html_table')(ri.table)
        res['created_raw'] = datetime_from_uuid1(ri.report_instance_id)
        res['created'] = format_datetime(datetime_from_uuid1(ri.report_instance_id))
        res['tags'] = Markup(' '.join('<span class="selected-tag-name clickable">%s</span>' % tag for tag in ri.all_tags))
        res['curr_report_instance_id'] = ri.report_instance_id
        res['has_next'] = report.fetch_next_instance(ri.report_instance_id, tags) is not None
        res['has_prev'] = report.fetch_prev_instance(ri.report_instance_id, tags) is not None
    else:
        res['html_newest_table'] = ''
        res['created_raw'] = ''
        res['created'] = ''
        res['tags'] = ''
        res['curr_report_instance_id'] = None
        res['has_next'] = False
        res['has_prev'] = False

    return success(result=res)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
def add_report_name_entered():
    report_name = request.get_json()['report_name']

    check_access(lambda: auth.access_profile())

    report = Report.select_by_name(auth.logged_owner_id(), report_name)
    if not report:
        return error(message='Incomplete report name')
    latest_instance_id = report.fetch_latest_instance_id()
    if not latest_instance_id:
        return error()
    ri = report.fetch_single_instance(latest_instance_id)
    tags = report.fetch_tags_sample('', TAGS_SAMPLE_LIMIT)

    res = {}
    res['has_tags'] = bool(tags)
    res['tag_sample'] = get_template_attribute('m.html', 'tag_sample')(tags)
    res['html_newest_table'] = get_template_attribute('m.html', 'table_as_html_table')(ri.table)
    res['report_id'] = report.report_id
    res['latest_instance_id'] = latest_instance_id
    res['latest_instance_tags'] = ri.all_tags
    return success(result=res)