예제 #1
0
    def set_template_args(self):
        include_timeseries = self.should_include_timeseries()
        report_object = build_report(self.metadata)
        report_template, report_kwargs = get_template_and_kwargs(
            report_object, request.url_root.rstrip('/'), include_timeseries,
            True)
        report_kwargs.update({
            'report_template': report_template,
            'dash_url': request.url_root.rstrip('/'),
            'include_metrics_toc': False,
            'metadata': {
                'report_parameters': self.metadata['report_parameters']
            },
        })
        report_status = self.metadata.get('status')

        # display a message about omitting timeseries
        if not include_timeseries and report_status == 'complete':
            download_link = url_for('data_dashboard.download_report_html',
                                    uuid=self.metadata['report_id'])
            flash(
                f"""<strong>Warning</strong> Too many timeseries points
                detected. To improve performance time series plots have
                been omitted from this report. You may download a copy
                of this report with the timeseries plots included:
                <a href="{download_link}">Download HTML Report.</a>""",
                'warning')
        elif not self.metadata['values'] and report_status == 'complete':
            flash(
                'Could not load any time series values of observations '
                'or forecasts. Timeseries and scatter plots will not '
                'be included. You may require the `read_values` '
                'permission on this report, or the included forecasts '
                'and observations.', 'warning')
        self.template_args = report_kwargs
def test_get_template_and_kwargs(good_or_bad_report, dash_url, with_series,
                                 expected_kwargs, mocked_timeseries_plots,
                                 with_body):
    html_template, kwargs = template.get_template_and_kwargs(
        good_or_bad_report, dash_url, with_series, with_body)
    base = kwargs.pop('base_template')
    kwargs.pop('report')
    assert type(base) == jinja2.environment.Template
    assert type(html_template) == jinja2.environment.Template
    assert kwargs == expected_kwargs(good_or_bad_report, with_series, False)
예제 #3
0
def test_get_template_and_kwargs_no_stats(
        no_stats_report, dash_url, with_series, with_body,
        expected_kwargs, mocked_timeseries_plots):
    html_template, kwargs = template.get_template_and_kwargs(
        no_stats_report,
        dash_url,
        with_series,
        with_body
    )
    base = kwargs.pop('base_template')
    kwargs.pop('report')
    assert type(base) == jinja2.environment.Template
    assert type(html_template) == jinja2.environment.Template
    ek = expected_kwargs(no_stats_report,
                         with_series, False)
    ek['templating_messages'] = [
        'No data summary statistics were calculated with this report.']
    ek['summary_stats'] = '[]'
    assert kwargs == ek
예제 #4
0
def test_get_template_and_kwargs_bad_status(
        report_with_raw, dash_url, mocked_timeseries_plots):
    inp = report_with_raw.replace(status='notokay')
    with pytest.raises(ValueError):
        template.get_template_and_kwargs(
            inp, dash_url, False, True)