def _get_configurable_reports(project): """ User configurable reports """ configs = ReportConfiguration.by_domain( project.name) + CustomReportConfiguration.by_domain(project.name) if configs: def _make_report_class(config): from corehq.apps.reports.generic import GenericReportView # this is really annoying. # the report metadata should really be pulled outside of the report classes @classmethod def get_url(cls, domain, **kwargs): return reverse(ConfigurableReport.slug, args=[domain, config._id]) @classmethod def show_in_navigation(cls, domain=None, project=None, user=None): return config.visible or ( user and toggles.USER_CONFIGURABLE_REPORTS.enabled( user.username)) return type( 'DynamicReport{}'.format(config._id), (GenericReportView, ), { 'name': config.title, 'description': config.description or None, 'get_url': get_url, 'show_in_navigation': show_in_navigation, }) yield (_('Reports'), [_make_report_class(config) for config in configs])
def _get_configurable_reports(project): """ User configurable reports """ configs = ReportConfiguration.by_domain(project.name) + CustomReportConfiguration.by_domain(project.name) if configs: def _make_report_class(config): from corehq.apps.reports.generic import GenericReportView # this is really annoying. # the report metadata should really be pulled outside of the report classes @classmethod def get_url(cls, domain, **kwargs): return reverse(ConfigurableReport.slug, args=[domain, config._id]) @classmethod def show_in_navigation(cls, domain=None, project=None, user=None): return config.visible or (user and toggles.USER_CONFIGURABLE_REPORTS.enabled(user.username)) return type('DynamicReport{}'.format(config._id), (GenericReportView, ), { 'name': config.title, 'description': config.description or None, 'get_url': get_url, 'show_in_navigation': show_in_navigation, }) yield (_('Reports'), [_make_report_class(config) for config in configs])
def test_get_all(self): with override_settings(CUSTOM_UCR_REPORTS=[self.get_path('custom_report_config', 'json')]): all = list(CustomReportConfiguration.all()) self.assertEqual(2, len(all)) example, dimagi = all self.assertEqual('example', example.domain) self.assertEqual('dimagi', dimagi.domain) for config in all: self.assertEqual('Custom Title', config.title)
def spec(self): if self.is_custom: return CustomReportConfiguration.by_id(self.report_config_id) else: return get_document_or_not_found(ReportConfiguration, self.domain, self.report_config_id)
def test_wrap(self): wrapped = CustomReportConfiguration.wrap(self.get_json('custom_report_config')) self.assertEqual(["example", "dimagi"], wrapped.domains)