Esempio n. 1
0
def prepare_issnip_monthly_register_reports(domain, user, awcs, pdf_format, month, year):

    utc_now = datetime.now(pytz.utc)
    india_now = utc_now.astimezone(india_timezone)

    selected_date = date(year, month, 1)
    report_context = {
        'reports': []
    }

    pdf_files = []

    for awc in awcs:
        pdf_hash = uuid.uuid4().hex

        awc_location = SQLLocation.objects.get(location_id=awc)
        pdf_files.append({
            'uuid': pdf_hash,
            'location_name': awc_location.name.replace(' ', '_')
        })
        report = ISSNIPMonthlyReport(config={
            'awc_id': awc_location.location_id,
            'month': selected_date,
            'domain': domain
        })
        qrcode = get_qrcode("{} {}".format(
            awc_location.site_code,
            india_now.strftime('%d %b %Y')
        ))
        context = {
            'qrcode_64': b64encode(qrcode),
            'report': report
        }

        if pdf_format == 'one':
            report_context['reports'].append(context)
        else:
            report_context['reports'] = [context]
            create_pdf_file(
                pdf_hash,
                report_context
            )

    if pdf_format == 'many':
        cache_key = zip_folder(pdf_files)
    else:
        cache_key = create_pdf_file(uuid.uuid4().hex, report_context)

    params = {
        'domain': domain,
        'uuid': cache_key,
        'format': pdf_format
    }

    return {
        'domain': domain,
        'uuid': cache_key,
        'format': pdf_format,
        'link': reverse('icds_download_pdf', params=params, absolute=True, kwargs={'domain': domain})
    }
Esempio n. 2
0
def prepare_issnip_monthly_register_reports(domain, awcs, pdf_format, month,
                                            year, couch_user):
    selected_date = date(year, month, 1)
    report_context = {
        'reports': [],
        'user_have_access_to_features': icds_pre_release_features(couch_user),
    }

    pdf_files = []

    report_data = ISSNIPMonthlyReport(
        config={
            'awc_id': awcs,
            'month': selected_date,
            'domain': domain
        },
        icds_feature_flag=icds_pre_release_features(couch_user)).to_pdf_format

    if pdf_format == 'one':
        report_context['reports'] = report_data
        cache_key = create_pdf_file(report_context)
    else:
        for data in report_data:
            report_context['reports'] = [data]
            pdf_hash = create_pdf_file(report_context)
            pdf_files.append({
                'uuid': pdf_hash,
                'location_name': data['awc_name']
            })
        cache_key = zip_folder(pdf_files)

    params = {'domain': domain, 'uuid': cache_key, 'format': pdf_format}

    return {
        'domain':
        domain,
        'uuid':
        cache_key,
        'format':
        pdf_format,
        'link':
        reverse('icds_download_pdf',
                params=params,
                absolute=True,
                kwargs={'domain': domain})
    }
Esempio n. 3
0
def prepare_issnip_monthly_register_reports(domain, awcs, pdf_format, month, year, couch_user):
    selected_date = date(year, month, 1)
    report_context = {
        'reports': [],
        'user_have_access_to_features': icds_pre_release_features(couch_user),
    }

    pdf_files = {}

    report_data = ISSNIPMonthlyReport(config={
        'awc_id': awcs,
        'month': selected_date,
        'domain': domain
    }, icds_feature_flag=icds_pre_release_features(couch_user)).to_pdf_format

    if pdf_format == 'one':
        report_context['reports'] = report_data
        cache_key = create_pdf_file(report_context)
    else:
        for data in report_data:
            report_context['reports'] = [data]
            pdf_hash = create_pdf_file(report_context)
            pdf_files.update({
                pdf_hash: data['awc_name']
            })
        cache_key = zip_folder(pdf_files)

    params = {
        'domain': domain,
        'uuid': cache_key,
        'format': pdf_format
    }

    return {
        'domain': domain,
        'uuid': cache_key,
        'format': pdf_format,
        'link': reverse('icds_download_pdf', params=params, absolute=True, kwargs={'domain': domain})
    }