def prepare_excel_reports(config, aggregation_level, include_test, beta, location, domain, file_format, indicator): if indicator == CHILDREN_EXPORT: data_type = 'Children' excel_data = ChildrenExport(config=config, loc_level=aggregation_level, show_test=include_test, beta=beta).get_excel_data(location) elif indicator == PREGNANT_WOMEN_EXPORT: data_type = 'Pregnant_Women' excel_data = PregnantWomenExport( config=config, loc_level=aggregation_level, show_test=include_test).get_excel_data(location) elif indicator == DEMOGRAPHICS_EXPORT: data_type = 'Demographics' excel_data = DemographicsExport(config=config, loc_level=aggregation_level, show_test=include_test, beta=beta).get_excel_data(location) elif indicator == SYSTEM_USAGE_EXPORT: data_type = 'System_Usage' excel_data = SystemUsageExport( config=config, loc_level=aggregation_level, show_test=include_test).get_excel_data(location) elif indicator == AWC_INFRASTRUCTURE_EXPORT: data_type = 'AWC_Infrastructure' excel_data = AWCInfrastructureExport( config=config, loc_level=aggregation_level, show_test=include_test).get_excel_data(location) elif indicator == BENEFICIARY_LIST_EXPORT: # this report doesn't use this configuration config.pop('aggregation_level', None) data_type = 'Beneficiary_List' excel_data = BeneficiaryExport(config=config, loc_level=aggregation_level, show_test=include_test, beta=beta).get_excel_data(location) cache_key = create_excel_file(excel_data, data_type, file_format) params = { 'domain': domain, 'uuid': cache_key, 'file_format': file_format, 'data_type': data_type, } return { 'domain': domain, 'uuid': cache_key, 'file_format': file_format, 'data_type': data_type, 'link': reverse('icds_download_excel', params=params, absolute=True, kwargs={'domain': domain}) }
def prepare_excel_reports(config, aggregation_level, include_test, beta, location, domain, file_format, indicator): if indicator == CHILDREN_EXPORT: data_type = 'Children' excel_data = ChildrenExport( config=config, loc_level=aggregation_level, show_test=include_test, beta=beta ).get_excel_data(location) elif indicator == PREGNANT_WOMEN_EXPORT: data_type = 'Pregnant_Women' excel_data = PregnantWomenExport( config=config, loc_level=aggregation_level, show_test=include_test ).get_excel_data(location) elif indicator == DEMOGRAPHICS_EXPORT: data_type = 'Demographics' excel_data = DemographicsExport( config=config, loc_level=aggregation_level, show_test=include_test, beta=beta ).get_excel_data(location) elif indicator == SYSTEM_USAGE_EXPORT: data_type = 'System_Usage' excel_data = SystemUsageExport( config=config, loc_level=aggregation_level, show_test=include_test ).get_excel_data( location, system_usage_num_launched_awcs_formatting_at_awc_level=aggregation_level > 4 and beta ) elif indicator == AWC_INFRASTRUCTURE_EXPORT: data_type = 'AWC_Infrastructure' excel_data = AWCInfrastructureExport( config=config, loc_level=aggregation_level, show_test=include_test, beta=beta, ).get_excel_data(location) elif indicator == BENEFICIARY_LIST_EXPORT: # this report doesn't use this configuration config.pop('aggregation_level', None) data_type = 'Beneficiary_List' excel_data = BeneficiaryExport( config=config, loc_level=aggregation_level, show_test=include_test, beta=beta ).get_excel_data(location) elif indicator == AWW_INCENTIVE_REPORT: data_type = 'AWW_Performance' excel_data = IncentiveReport( location=location, month=config['month'], aggregation_level=aggregation_level ).get_excel_data() if file_format == 'xlsx': cache_key = create_aww_performance_excel_file( excel_data, data_type, config['month'].strftime("%B %Y"), state=SQLLocation.objects.get( location_id=config['state_id'], domain=config['domain'] ).name, district=SQLLocation.objects.get( location_id=config['district_id'], domain=config['domain'] ).name if aggregation_level >= 2 else None, block=SQLLocation.objects.get( location_id=config['block_id'], domain=config['domain'] ).name if aggregation_level == 3 else None, ) else: cache_key = create_excel_file(excel_data, data_type, file_format) if indicator != AWW_INCENTIVE_REPORT: if file_format == 'xlsx' and beta: cache_key = create_excel_file_in_openpyxl(excel_data, data_type) else: cache_key = create_excel_file(excel_data, data_type, file_format) params = { 'domain': domain, 'uuid': cache_key, 'file_format': file_format, 'data_type': data_type, } return { 'domain': domain, 'uuid': cache_key, 'file_format': file_format, 'data_type': data_type, 'link': reverse('icds_download_excel', params=params, absolute=True, kwargs={'domain': domain}) }