Exemplo n.º 1
0
def get_all_report_configs():
    from corehq.apps.userreports.models import ReportConfiguration
    ids = [res['id'] for res in ReportConfiguration.view(
        'userreports/report_configs_by_domain',
        reduce=False,
        include_docs=False,
    )]
    for result in iter_docs(ReportConfiguration.get_db(), ids):
        yield ReportConfiguration.wrap(result)
Exemplo n.º 2
0
def get_number_of_report_configs_by_data_source(domain, data_source_id):
    """
    Return the number of report configurations that use the given data source.
    """
    from corehq.apps.userreports.models import ReportConfiguration
    return ReportConfiguration.view(
        'userreports/report_configs_by_data_source',
        reduce=True,
        key=[domain, data_source_id]).one()['value']
Exemplo n.º 3
0
def get_number_of_report_configs_by_data_source(domain, data_source_id):
    """
    Return the number of report configurations that use the given data source.
    """
    from corehq.apps.userreports.models import ReportConfiguration
    return ReportConfiguration.view(
        'userreports/report_configs_by_data_source',
        reduce=True,
        key=[domain, data_source_id]
    ).one()['value']
Exemplo n.º 4
0
def get_report_configs_for_domain(domain):
    from corehq.apps.userreports.models import ReportConfiguration
    return sorted(
        ReportConfiguration.view(
            'userreports/report_configs_by_domain',
            key=domain,
            reduce=False,
            include_docs=True,
        ),
        key=lambda report: report.title,
    )
Exemplo n.º 5
0
def get_report_configs_for_domain(domain):
    from corehq.apps.userreports.models import ReportConfiguration
    return sorted(
        ReportConfiguration.view(
            'userreports/report_configs_by_domain',
            key=domain,
            reduce=False,
            include_docs=True,
        ),
        key=lambda report: report.title,
    )
Exemplo n.º 6
0
def get_all_report_configs():
    from corehq.apps.userreports.models import ReportConfiguration
    ids = [
        res['id'] for res in ReportConfiguration.view(
            'userreports/report_configs_by_domain',
            reduce=False,
            include_docs=False,
        )
    ]
    for result in iter_docs(ReportConfiguration.get_db(), ids):
        yield ReportConfiguration.wrap(result)
Exemplo n.º 7
0
def delete_report(request, domain, report_id):
    config = get_document_or_404(ReportConfiguration, domain, report_id)

    # Delete the data source too if it's not being used by any other reports.
    data_source_id = config.config_id

    report_count = ReportConfiguration.view(
        'userreports/report_configs_by_data_source',
        reduce=True,
        key=[domain, data_source_id]
    ).one()['value']

    if report_count <= 1:
        # No other reports reference this data source.
        try:
            _delete_data_source_shared(request, domain, data_source_id)
        except Http404:
            # It's possible the data source has already been deleted, but
            # that's fine with us.
            pass

    config.delete()
    messages.success(request, _(u'Report "{}" deleted!').format(config.title))
    return HttpResponseRedirect(reverse('configurable_reports_home', args=[domain]))