(self, recipient_emails, domain, report_slug, report_type,
                      request_data, once, cleaned_data)
Function invokes send_HTML_email to email the html text report.
    If the report is too large to fit into email then a download link is
    sent via email to download report
    :Parameter recipient_list:
            list of recipient to whom email is to be sent
    :Parameter domain:
            domain name
    :Parameter report_slug:
            report slug
    :Parameter report_type:
            type of the report
    :Parameter request_data:
            Dict containing request data
    :Parameter once
            boolean argument specifying whether the report is once off report
            or scheduled report
    :Parameter cleaned_data:
            Dict containing cleaned data from the submitted form
Function invokes send_HTML_email to email the html text report.
    If the report is too large to fit into email then a download link is
    sent via email to download report
    :Parameter recipient_list:
            list of recipient to whom email is to be sent
    :Parameter domain:
            domain name
    :Parameter report_slug:
            report slug
    :Parameter report_type:
            type of the report
    :Parameter request_data:
            Dict containing request data
    :Parameter once
            boolean argument specifying whether the report is once off report
            or scheduled report
    :Parameter cleaned_data:
            Dict containing cleaned data from the submitted form
Function invokes send_HTML_email to email the html text report . If the report is too large to fit into email then a download link is sent via email to download report : Parameter recipient_list : list of recipient to whom email is to be sent : Parameter domain : domain name : Parameter report_slug : report slug : Parameter report_type : type of the report : Parameter request_data : Dict containing request data : Parameter once boolean argument specifying whether the report is once off report or scheduled report : Parameter cleaned_data : Dict containing cleaned data from the submitted form
def send_email_report(self, recipient_emails, domain, report_slug, report_type,
                      request_data, once, cleaned_data):
    """
    Function invokes send_HTML_email to email the html text report.
    If the report is too large to fit into email then a download link is
    sent via email to download report
    :Parameter recipient_list:
            list of recipient to whom email is to be sent
    :Parameter domain:
            domain name
    :Parameter report_slug:
            report slug
    :Parameter report_type:
            type of the report
    :Parameter request_data:
            Dict containing request data
    :Parameter once
            boolean argument specifying whether the report is once off report
            or scheduled report
    :Parameter cleaned_data:
            Dict containing cleaned data from the submitted form
    """
    from corehq.apps.reports.views import _render_report_configs, render_full_report_notification

    user_id = request_data['couch_user']
    couch_user = CouchUser.get_by_user_id(user_id)
    mock_request = HttpRequest()

    mock_request.method = 'GET'
    mock_request.GET = request_data['GET']

    config = ReportConfig()

    # see ReportConfig.query_string()
    object.__setattr__(config, '_id', 'dummy')
    config.name = _("Emailed report")
    config.report_type = report_type
    config.report_slug = report_slug
    config.owner_id = user_id
    config.domain = domain

    config.start_date = request_data['datespan'].startdate.date()
    if request_data['datespan'].enddate:
        config.date_range = 'range'
        config.end_date = request_data['datespan'].enddate.date()
    else:
        config.date_range = 'since'

    GET = dict(six.iterlists(request_data['GET']))
    exclude = ['startdate', 'enddate', 'subject', 'send_to_owner', 'notes', 'recipient_emails']
    filters = {}
    for field in GET:
        if field not in exclude:
            filters[field] = GET.get(field)

    config.filters = filters

    subject = cleaned_data['subject'] or _("Email report from CommCare HQ")

    try:
        report_text = _render_report_configs(
            mock_request, [config], domain, user_id, couch_user, True, lang=couch_user.language,
            notes=cleaned_data['notes'], once=once
        )[0]
        body = render_full_report_notification(None, report_text).content

        for recipient in recipient_emails:
            send_HTML_email(subject, recipient,
                            body, email_from=settings.DEFAULT_FROM_EMAIL,
                            smtp_exception_skip_list=LARGE_FILE_SIZE_ERROR_CODES)

    except Exception as er:
        notify_exception(
            None,
            message="Encountered error while generating report or sending email",
            details={
                'subject': subject,
                'recipients': str(recipient_emails),
                'error': er,
            }
        )
        if getattr(er, 'smtp_code', None) in LARGE_FILE_SIZE_ERROR_CODES or type(er) == ESError:
            # If the email doesn't work because it is too large to fit in the HTML body,
            # send it as an excel attachment.
            report_state = {
                'request': request_data,
                'request_params': json_request(request_data['GET']),
                'domain': domain,
                'context': {},
            }
            export_all_rows_task(config.report, report_state, recipient_list=recipient_emails)
        else:
            self.retry(exc=er)
def send_email_report ( self , recipient_emails , domain , report_slug , report_type , request_data , once , cleaned_data ) : from corehq . apps . reports . views import _render_report_configs , render_full_report_notification user_id = request_data [ 'couch_user' ] couch_user = CouchUser . get_by_user_id ( user_id ) mock_request = HttpRequest ( ) mock_request . method = 'GET' mock_request . GET = request_data [ 'GET' ] config = ReportConfig ( ) # see ReportConfig.query_string() object . __setattr__ ( config , '_id' , 'dummy' ) config . name = _ ( "Emailed report" ) config . report_type = report_type config . report_slug = report_slug config . owner_id = user_id config . domain = domain config . start_date = request_data [ 'datespan' ] . startdate . date ( ) if request_data [ 'datespan' ] . enddate : config . date_range = 'range' config . end_date = request_data [ 'datespan' ] . enddate . date ( ) else : config . date_range = 'since' GET = dict ( six . iterlists ( request_data [ 'GET' ] ) ) exclude = [ 'startdate' , 'enddate' , 'subject' , 'send_to_owner' , 'notes' , 'recipient_emails' ] filters = { } for field in GET : if field not in exclude : filters [ field ] = GET . get ( field ) config . filters = filters subject = cleaned_data [ 'subject' ] or _ ( "Email report from CommCare HQ" ) try : report_text = _render_report_configs ( mock_request , [ config ] , domain , user_id , couch_user , True , lang = couch_user . language , notes = cleaned_data [ 'notes' ] , once = once ) [ 0 ] body = render_full_report_notification ( None , report_text ) . content for recipient in recipient_emails : send_HTML_email ( subject , recipient , body , email_from = settings . DEFAULT_FROM_EMAIL , smtp_exception_skip_list = LARGE_FILE_SIZE_ERROR_CODES ) except Exception as er : notify_exception ( None , message = "Encountered error while generating report or sending email" , details = { 'subject' : subject , 'recipients' : str ( recipient_emails ) , 'error' : er , } ) if getattr ( er , 'smtp_code' , None ) in LARGE_FILE_SIZE_ERROR_CODES or type ( er ) == ESError : # If the email doesn't work because it is too large to fit in the HTML body, # send it as an excel attachment. report_state = { 'request' : request_data , 'request_params' : json_request ( request_data [ 'GET' ] ) , 'domain' : domain , 'context' : { } , } export_all_rows_task ( config . report , report_state , recipient_list = recipient_emails ) else : self . retry ( exc = er )