def test_get_by_domain(self):
        results = RegistryDataSourceConfiguration.by_domain('foo')
        self.assertEqual(2, len(results))
        for item in results:
            self.assertTrue(item.table_id in ('foo1', 'foo2'))

        results = RegistryDataSourceConfiguration.by_domain('not-foo')
        self.assertEqual(0, len(results))
Example #2
0
def get_datasources_for_domain(domain,
                               referenced_doc_type=None,
                               include_static=False,
                               include_aggregate=False):
    from corehq.apps.userreports.models import DataSourceConfiguration, StaticDataSourceConfiguration, \
        RegistryDataSourceConfiguration
    key = [domain]
    if referenced_doc_type:
        key.append(referenced_doc_type)
    datasources = sorted(DataSourceConfiguration.view(
        'userreports/data_sources_by_build_info',
        startkey=key,
        endkey=key + [{}],
        reduce=False,
        include_docs=True),
                         key=lambda config: config.display_name or '')
    datasources.extend(
        sorted(RegistryDataSourceConfiguration.by_domain(domain),
               key=lambda config: config.display_name or ''))

    if include_static:
        static_ds = StaticDataSourceConfiguration.by_domain(domain)
        if referenced_doc_type:
            static_ds = [
                ds for ds in static_ds
                if ds.referenced_doc_type == referenced_doc_type
            ]
        datasources.extend(
            sorted(static_ds, key=lambda config: config.display_name))

    if include_aggregate:
        from corehq.apps.aggregate_ucrs.models import AggregateTableDefinition
        datasources.extend(
            AggregateTableDefinition.objects.filter(domain=domain).all())
    return datasources
Example #3
0
 def __init__(self, domain, *args, **kwargs):
     self.domain = domain
     standard_sources = DataSourceConfiguration.by_domain(self.domain)
     registry_sources = RegistryDataSourceConfiguration.by_domain(
         self.domain)
     custom_sources = list(StaticDataSourceConfiguration.by_domain(domain))
     available_data_sources = standard_sources + registry_sources + custom_sources
     if toggles.AGGREGATE_UCRS.enabled(domain):
         from corehq.apps.aggregate_ucrs.models import AggregateTableDefinition
         available_data_sources += AggregateTableDefinition.objects.filter(
             domain=self.domain)
     super(ReportDataSourceField,
           self).__init__(choices=[(src.data_source_id, src.display_name)
                                   for src in available_data_sources],
                          *args,
                          **kwargs)