コード例 #1
0
ファイル: dbaccessors.py プロジェクト: dimagi/commcare-hq
def get_datasources_for_domain(domain, referenced_doc_type=None, include_static=False, include_aggregate=False):
    from corehq.apps.userreports.models import DataSourceConfiguration, StaticDataSourceConfiguration
    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 '')

    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
コード例 #2
0
ファイル: dbaccessors.py プロジェクト: tstalka/commcare-hq
def get_datasources_for_domain(domain,
                               referenced_doc_type=None,
                               include_static=False,
                               include_aggregate=False):
    from corehq.apps.userreports.models import DataSourceConfiguration, StaticDataSourceConfiguration
    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 '')

    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
コード例 #3
0
def _get_all_data_sources():
    from corehq.apps.userreports.models import DataSourceConfiguration
    return DataSourceConfiguration.view(
        'userreports/data_sources_by_build_info',
        reduce=False,
        include_docs=True
    )
コード例 #4
0
 def get_data_sources_modified_since(self, timestamp):
     return DataSourceConfiguration.view(
         'userreports/data_sources_by_last_modified',
         startkey=[timestamp.isoformat()],
         endkey=[{}],
         reduce=False,
         include_docs=True).all()
コード例 #5
0
def _get_old_new_tablenames(engine_id=None):
    by_engine_id = defaultdict(list)
    seen_tables = defaultdict(set)
    for ds in StaticDataSourceConfiguration.all():
        ds_engine_id = ds['engine_id']
        if engine_id and ds_engine_id != engine_id:
            continue
        old, new = _table_names(ds.domain, ds.table_id)
        if old in seen_tables[ds_engine_id]:
            logger.warning('Duplicate table: %s - %s', ds.get_id, old)
            continue
        seen_tables[ds_engine_id].add(old)
        by_engine_id[ds_engine_id].append(DSConf(old, new, ds))

    data_source_ids = [
        row['id'] for row in DataSourceConfiguration.view(
            'userreports/active_data_sources',
            reduce=False,
            include_docs=False)
    ]
    for ds in iter_docs(DataSourceConfiguration.get_db(), data_source_ids):
        ds = DataSourceConfiguration.wrap(ds)
        ds_engine_id = ds['engine_id']
        if engine_id and ds_engine_id != engine_id:
            continue

        old, new = _table_names(ds.domain, ds.table_id)
        if old in seen_tables[ds_engine_id]:
            logger.warning('Duplicate table: %s - %s', ds.get_id, old)
            continue
        seen_tables[ds_engine_id].add(old)
        by_engine_id[ds_engine_id].append(DSConf(old, new, ds))

    return by_engine_id
コード例 #6
0
ファイル: forms.py プロジェクト: ekush/commcare-hq
 def get_existing_match(self):
     return DataSourceConfiguration.view(
         'userreports/data_sources_by_build_info',
         key=[
             self.domain, self.source_doc_type, self.source_id,
             self.app._id, self.app.version
         ],
         reduce=False).one()
コード例 #7
0
def get_datasources_for_domain(domain):
    from corehq.apps.userreports.models import DataSourceConfiguration
    return sorted(DataSourceConfiguration.view(
        'userreports/data_sources_by_build_info',
        start_key=[domain],
        end_key=[domain, {}],
        reduce=False,
        include_docs=True),
                  key=lambda config: config.display_name)
コード例 #8
0
ファイル: forms.py プロジェクト: johan--/commcare-hq
 def get_existing_match(self):
     return DataSourceConfiguration.view(
         'userreports/data_sources_by_build_info',
         key=[
             self.domain,
             self.source_doc_type,
             self.source_id,
             self.app._id,
             self.app.version
         ],
         reduce=False
     ).one()
コード例 #9
0
def get_datasources_for_domain(domain):
    from corehq.apps.userreports.models import DataSourceConfiguration
    return sorted(
        DataSourceConfiguration.view(
            'userreports/data_sources_by_build_info',
            start_key=[domain],
            end_key=[domain, {}],
            reduce=False,
            include_docs=True
        ),
        key=lambda config: config.display_name
    )
コード例 #10
0
ファイル: dbaccessors.py プロジェクト: bderenzi/commcare-hq
def get_datasources_for_domain(domain, referenced_doc_type=None):
    from corehq.apps.userreports.models import DataSourceConfiguration
    key = [domain]
    if referenced_doc_type:
        key.append(referenced_doc_type)
    return sorted(DataSourceConfiguration.view(
        'userreports/data_sources_by_build_info',
        start_key=key,
        end_key=key + [{}],
        reduce=False,
        include_docs=True),
                  key=lambda config: config.display_name)
コード例 #11
0
 def get_all_data_sources(self):
     return DataSourceConfiguration.view('userreports/active_data_sources',
                                         reduce=False,
                                         include_docs=True).all()
コード例 #12
0
def _get_all_data_sources():
    from corehq.apps.userreports.models import DataSourceConfiguration
    return DataSourceConfiguration.view(
        'userreports/data_sources_by_build_info',
        reduce=False,
        include_docs=True)
コード例 #13
0
 def get_all_data_sources(self):
     return DataSourceConfiguration.view(
         'userreports/active_data_sources', reduce=False, include_docs=True).all()
コード例 #14
0
 def by_domain(self, domain):
     return DataSourceConfiguration.view('userreports/active_data_sources',
                                         startkey=[domain],
                                         endkey=[domain, {}],
                                         reduce=False,
                                         include_docs=True).all()