示例#1
0
def prepare_export_reports(domain, selected_date, next_month_start,
                           selected_location, selected_ministry,
                           beneficiary_type):
    location_filters = build_location_filters(selected_location,
                                              selected_ministry,
                                              with_child=False)
    sort_column = 'name'

    selected_date = force_to_date(selected_date)
    next_month_start = force_to_date(next_month_start)

    columns = []
    data = []

    if beneficiary_type == 'child':
        columns = (
            ('name', 'Name'),
            ('age', 'Age'),
            ('gender', 'Gender'),
            ('lastImmunizationType', 'Last Immunization Type'),
            ('lastImmunizationDate', 'Last Immunization Date'),
        )
        data = ChildQueryHelper.list(domain, next_month_start,
                                     location_filters, sort_column)
    elif beneficiary_type == 'eligible_couple':
        columns = (
            ('name', 'Name'),
            ('age', 'Age'),
            ('currentFamilyPlanningMethod', 'Current Family Planing Method'),
            ('adoptionDateOfFamilyPlaning',
             'Adoption Date Of Family Planning'),
        )
        data = EligibleCoupleQueryHelper.list(domain, selected_date,
                                              location_filters, sort_column)
        month_end = selected_date + relativedelta(months=1) - relativedelta(
            days=1)
        data = EligibleCoupleQueryHelper.update_list(data, month_end)
    elif beneficiary_type == 'pregnant_women':
        columns = (
            ('name', 'Name'),
            ('age', 'Age'),
            ('pregMonth', 'Preg. Month'),
            ('highRiskPregnancy', 'High Risk Pregnancy'),
            ('noOfAncCheckUps', 'No. Of ANC Check-Ups'),
        )
        data = PregnantWomanQueryHelper.list(domain, selected_date,
                                             location_filters, sort_column)

    export_columns = [col[1] for col in columns]

    export_data = [export_columns]
    for row in data:
        row_data = [row[col[0]] or 'N/A' for col in columns]
        export_data.append(row_data)
    return create_excel_file(domain, [[beneficiary_type, export_data]],
                             beneficiary_type, 'xlsx')
示例#2
0
    def post(self, request, *args, **kwargs):
        selected_month = int(self.request.POST.get('selectedMonth'))
        selected_year = int(self.request.POST.get('selectedYear'))
        selected_date = date(selected_year, selected_month, 1)
        next_month_start = selected_date + relativedelta(months=1)
        selected_location = self.request.POST.get('selectedLocation')
        selected_ministry = self.request.POST.get('selectedMinistry')
        beneficiary_type = self.request.POST.get('selectedBeneficiaryType')
        draw = self.request.POST.get('draw', 0)
        length = int(self.request.POST.get('length', 0))
        start = int(self.request.POST.get('start', 0))
        sort_column = self.request.POST.get('sortColumn', 'name')
        sort_column_dir = self.request.POST.get('sortColumnDir', 'asc')

        location_filters = build_location_filters(selected_location,
                                                  selected_ministry,
                                                  with_child=False)
        sort_column_with_dir = sort_column
        if sort_column_dir == 'desc':
            sort_column_with_dir = '-' + sort_column
        data = []
        if beneficiary_type == 'child':
            data = ChildQueryHelper.list(request.domain, next_month_start,
                                         location_filters,
                                         sort_column_with_dir)
        elif beneficiary_type == 'eligible_couple':
            data = EligibleCoupleQueryHelper.list(request.domain,
                                                  selected_date,
                                                  location_filters,
                                                  sort_column_with_dir)
        elif beneficiary_type == 'pregnant_women':
            sort_column_with_dir = '"%s" %s' % (sort_column, sort_column_dir)
            data = PregnantWomanQueryHelper.list(request.domain, selected_date,
                                                 location_filters,
                                                 sort_column_with_dir)
        if data:
            number_of_data = len(data)
            data = data[start:start + length]
        else:
            number_of_data = 0
        if beneficiary_type == 'eligible_couple':
            month_end = date(selected_year, selected_month, 1) + relativedelta(
                months=1) - relativedelta(days=1)
            data = EligibleCoupleQueryHelper.update_list(data, month_end)
        data = list(data)
        return JsonResponse(
            data={
                'rows': data,
                'draw': draw,
                'recordsTotal': number_of_data,
                'recordsFiltered': number_of_data,
            })
示例#3
0
def prepare_export_reports(domain, selected_date, next_month_start, selected_location,
                           selected_ministry, beneficiary_type):
    location_filters = build_location_filters(selected_location, selected_ministry, with_child=False)
    sort_column = 'name'

    selected_date = force_to_date(selected_date)
    next_month_start = force_to_date(next_month_start)

    columns = []
    data = []

    if beneficiary_type == 'child':
        columns = (
            ('name', 'Name'),
            ('age', 'Age'),
            ('gender', 'Gender'),
            ('lastImmunizationType', 'Last Immunization Type'),
            ('lastImmunizationDate', 'Last Immunization Date'),
        )
        data = ChildQueryHelper.list(domain, next_month_start, location_filters, sort_column)
    elif beneficiary_type == 'eligible_couple':
        columns = (
            ('name', 'Name'),
            ('age', 'Age'),
            ('currentFamilyPlanningMethod', 'Current Family Planing Method'),
            ('adoptionDateOfFamilyPlaning', 'Adoption Date Of Family Planning'),
        )
        data = EligibleCoupleQueryHelper.list(domain, selected_date, location_filters, sort_column)
    elif beneficiary_type == 'pregnant_women':
        columns = (
            ('name', 'Name'),
            ('age', 'Age'),
            ('pregMonth', 'Preg. Month'),
            ('highRiskPregnancy', 'High Risk Pregnancy'),
            ('noOfAncCheckUps', 'No. Of ANC Check-Ups'),
        )
        data = PregnantWomanQueryHelper.list(domain, selected_date, location_filters, sort_column)

    export_columns = [col[1] for col in columns]

    export_data = [export_columns]
    for row in data:
        row_data = [row[col[0]] or 'N/A' for col in columns]
        export_data.append(row_data)
    return create_excel_file(
        domain,
        [[beneficiary_type, export_data]],
        beneficiary_type,
        'xlsx'
    )
示例#4
0
    def post(self, request, *args, **kwargs):
        selected_month = int(self.request.POST.get('selectedMonth'))
        selected_year = int(self.request.POST.get('selectedYear'))
        selected_date = date(selected_year, selected_month, 1)
        next_month_start = selected_date + relativedelta(months=1)
        selected_location = self.request.POST.get('selectedLocation')
        selected_ministry = self.request.POST.get('selectedMinistry')
        beneficiary_type = self.request.POST.get('selectedBeneficiaryType')
        draw = self.request.POST.get('draw', 0)
        length = int(self.request.POST.get('length', 0))
        start = int(self.request.POST.get('start', 0))
        sort_column = self.request.POST.get('sortColumn', 'name')
        sort_column_dir = self.request.POST.get('sortColumnDir', 'asc')

        location_filters = build_location_filters(selected_location, selected_ministry, with_child=False)
        sort_column_with_dir = sort_column
        if sort_column_dir == 'desc':
            sort_column_with_dir = '-' + sort_column
        data = []
        if beneficiary_type == 'child':
            data = ChildQueryHelper.list(request.domain, next_month_start, location_filters, sort_column_with_dir)
        elif beneficiary_type == 'eligible_couple':
            sort_column_with_dir = '"%s" %s' % (sort_column, sort_column_dir)
            data = EligibleCoupleQueryHelper.list(
                request.domain,
                selected_date,
                location_filters,
                sort_column_with_dir
            )
        elif beneficiary_type == 'pregnant_women':
            sort_column_with_dir = '"%s" %s' % (sort_column, sort_column_dir)
            data = PregnantWomanQueryHelper.list(
                request.domain,
                selected_date,
                location_filters,
                sort_column_with_dir
            )
        if data:
            number_of_data = len(data)
            data = data[start:start + length]
        else:
            number_of_data = 0
        data = list(data)
        return JsonResponse(data={
            'rows': data,
            'draw': draw,
            'recordsTotal': number_of_data,
            'recordsFiltered': number_of_data,
        })