示例#1
0
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])
示例#2
0
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])