Esempio n. 1
0
    def setUpClass(cls):
        delete_all_users()
        cls.report_id = '7b97e8b53d00d43ca126b10093215a9d'
        cls.report_config_uuid = 'a98c812873986df34fd1b4ceb45e6164ae9cc664'
        cls.domain = 'report-filter-test-domain'
        cls.user = create_restore_user(
            domain=cls.domain,
            username='******',
        )
        update_toggle_cache(MOBILE_UCR.slug, cls.domain, True,
                            NAMESPACE_DOMAIN)

        report_configuration = cls.make_report_config(cls.domain,
                                                      cls.report_id)
        cls.report_configs_by_id = {cls.report_id: report_configuration}
        cls.app = Application.new_app(cls.domain, "Report Filter Test App",
                                      APP_V2)
        module = cls.app.add_module(
            ReportModule.new_module("Report Module", 'en'))
        module.report_configs.append(
            ReportAppConfig(
                report_id=cls.report_id,
                header={},
                description="",
                graph_configs={
                    '7451243209119342931':
                    ReportGraphConfig(series_configs={'count': {}})
                },
                filters={
                    'computed_owner_name_40cc88a0_1': MobileSelectFilter()
                },
                uuid=cls.report_config_uuid,
            ))
        with mock_report_configurations(cls.report_configs_by_id):
            cls.suite = cls.app.create_suite()
        cls.data = [
            {
                'color_94ec39e6': 'red',
                'count': 2,
                'computed_owner_name_40cc88a0': 'cory'
            },
            {
                'color_94ec39e6': 'black',
                'count': 1,
                'computed_owner_name_40cc88a0': 'ctsims'
            },
            {
                'color_94ec39e6': 'red',
                'count': 3,
                'computed_owner_name_40cc88a0': 'daniel'
            },
        ]
        with mock_report_data(cls.data):
            with mock_report_configuration_get(cls.report_configs_by_id):
                with mock.patch(
                        'corehq.apps.app_manager.fixtures.mobile_ucr.get_apps_in_domain',
                        lambda domain, include_remote: [cls.app]):
                    fixture, = report_fixture_generator(cls.user, '2.0')
        cls.fixture = ElementTree.tostring(fixture)
Esempio n. 2
0
    def _get_graph_fields():
        from corehq.apps.userreports.reports.specs import MultibarChartSpec
        # todo: make this less hard-coded
        for chart_config in config.report(domain).charts:
            if isinstance(chart_config, MultibarChartSpec):
                graph_config = config.graph_configs.get(
                    chart_config.chart_id, ReportGraphConfig())

                def _column_to_series(column):
                    return Series(nodeset=(
                        "instance('reports')/reports/report[@id='{}']/rows/row[@is_total_row='False']{}"
                        .format(
                            config.uuid,
                            _MobileSelectFilterHelpers.get_data_filter_xpath(
                                config, domain))),
                                  x_function="column[@id='{}']".format(
                                      chart_config.x_axis_column),
                                  y_function="column[@id='{}']".format(column),
                                  configuration=ConfigurationGroup(configs=[
                                      ConfigurationItem(id=key,
                                                        xpath_function=value)
                                      for key, value in graph_config.
                                      series_configs.get(column, {}).items()
                                  ]))

                yield Field(
                    header=Header(text=Text()),
                    template=GraphTemplate(
                        form='graph',
                        graph=Graph(
                            type=graph_config.graph_type,
                            series=[
                                _column_to_series(c.column_id)
                                for c in chart_config.y_axis_columns
                            ],
                            configuration=ConfigurationGroup(configs=[
                                ConfigurationItem(id=key, xpath_function=value)
                                for key, value in graph_config.config.items()
                            ]),
                        ),
                    ))