<commit_before>from corehq.apps.reports.schedule import BasicReportSchedule, ReportSchedule, CustomReportSchedule
from corehq.apps.hqadmin.views import domain_list
from corehq.apps.reports.standard import DailySubmissionsReport, DailyFormCompletionsReport, SubmissionsByFormReport, CaseActivityReport
from django.conf import settings
from dimagi.utils.modules import to_function

SCHEDULABLE_REPORTS = ["daily_submissions",
                       "daily_completions",
                       "submissions_by_form",
                       "admin_domains",
                       "case_activity"]

class ScheduledReportFactory(object):
    """
    Factory access for scheduled reports
    """
    
    @classmethod
    def get_report(cls, slug):
        if slug.startswith("custom/"):
            custom_reports = {}
            for domain, values in settings.CUSTOM_REPORT_MAP.items():
                for heading, models in values.items():
                    for model in models:
                        klass = to_function(model)
                        custom_reports[klass.slug] = CustomReportSchedule(klass)
            return custom_reports[slug[len("custom/"):]]
        else:
            return getattr(cls, "_%s" % slug)()
        
    @classmethod
    def get_reports(cls, domain=None):
        reports = dict((rep, cls.get_report(rep)) for rep in SCHEDULABLE_REPORTS)
        if domain is not None:
            for heading, models in settings.CUSTOM_REPORT_MAP.get(domain, {}).items():
                for model in models:
                    klass = to_function(model)
                    slug = "custom/" + klass.slug
                    reports[slug] = CustomReportSchedule(klass)
        return reports
    
    @classmethod
    def _daily_submissions(cls):
        return BasicReportSchedule(DailySubmissionsReport)
    
    @classmethod
    def _daily_completions(cls):
        return BasicReportSchedule(DailyFormCompletionsReport)
        
    @classmethod
    def _submissions_by_form(cls):
        return BasicReportSchedule(SubmissionsByFormReport)

    @classmethod
    def _case_activity(cls):
        return BasicReportSchedule(CaseActivityReport)
<commit_msg>Fixes bug where scheduled custom reports couldn't be deleted<commit_after>from corehq.apps.reports.schedule import BasicReportSchedule, ReportSchedule, CustomReportSchedule
from corehq.apps.hqadmin.views import domain_list
from corehq.apps.reports.standard import DailySubmissionsReport, DailyFormCompletionsReport, SubmissionsByFormReport, CaseActivityReport
from django.conf import settings
from dimagi.utils.modules import to_function

SCHEDULABLE_REPORTS = ["daily_submissions",
                       "daily_completions",
                       "submissions_by_form",
                       "admin_domains",
                       "case_activity"]

class ScheduledReportFactory(object):
    """
    Factory access for scheduled reports
    """
    
    @classmethod
    def get_report(cls, slug):
        if slug.startswith("custom-"):
            custom_reports = {}
            for domain, values in settings.CUSTOM_REPORT_MAP.items():
                for heading, models in values.items():
                    for model in models:
                        klass = to_function(model)
                        custom_reports[klass.slug] = CustomReportSchedule(klass)
            return custom_reports[slug[len("custom-"):]]
        else:
            return getattr(cls, "_%s" % slug)()
        
    @classmethod
    def get_reports(cls, domain=None):
        reports = dict((rep, cls.get_report(rep)) for rep in SCHEDULABLE_REPORTS)
        if domain is not None:
            for heading, models in settings.CUSTOM_REPORT_MAP.get(domain, {}).items():
                for model in models:
                    klass = to_function(model)
                    slug = "custom-" + klass.slug
                    reports[slug] = CustomReportSchedule(klass)
        return reports
    
    @classmethod
    def _daily_submissions(cls):
        return BasicReportSchedule(DailySubmissionsReport)
    
    @classmethod
    def _daily_completions(cls):
        return BasicReportSchedule(DailyFormCompletionsReport)
        
    @classmethod
    def _submissions_by_form(cls):
        return BasicReportSchedule(SubmissionsByFormReport)

    @classmethod
    def _case_activity(cls):
        return BasicReportSchedule(CaseActivityReport)

{'fraction_non_alphanumeric': 0.0767836919592299, 'fraction_numerical': 0.0, 'mean_word_length': 2.41003861003861, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3816759', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1146, 'n_words': 258}