示例#1
0
def get_csv_sources(json_request):
    csv_sources = []
    for award_level in json_request['award_levels']:
        queryset = VALUE_MAPPINGS[award_level]['filter_function'](json_request['filters'])
        award_level_table = VALUE_MAPPINGS[award_level]['table']

        award_type_codes = set(json_request['filters']['award_type_codes'])
        d1_award_type_codes = set(contract_type_mapping.keys())
        d2_award_type_codes = set(assistance_type_mapping.keys())

        if award_type_codes & d1_award_type_codes:
            # only generate d1 files if the user is asking for contract data
            d1_source = CsvSource(VALUE_MAPPINGS[award_level]['table_name'], 'd1', award_level)
            d1_filters = {'{}__isnull'.format(VALUE_MAPPINGS[award_level]['contract_data']): False}
            d1_source.queryset = queryset & award_level_table.objects.filter(**d1_filters)
            csv_sources.append(d1_source)

        if award_type_codes & d2_award_type_codes:
            # only generate d2 files if the user is asking for assistance data
            d2_source = CsvSource(VALUE_MAPPINGS[award_level]['table_name'], 'd2', award_level)
            d2_filters = {'{}__isnull'.format(VALUE_MAPPINGS[award_level]['assistance_data']): False}
            d2_source.queryset = queryset & award_level_table.objects.filter(**d2_filters)
            csv_sources.append(d2_source)

        verify_requested_columns_available(tuple(csv_sources), json_request.get('columns', []))

    return csv_sources
def get_csv_sources(json_request):
    csv_sources = []
    for download_type in json_request['download_types']:
        agency_id = json_request['filters'].get('agency', 'all')
        filter_function = VALUE_MAPPINGS[download_type]['filter_function']
        download_type_table = VALUE_MAPPINGS[download_type]['table']

        if VALUE_MAPPINGS[download_type]['source_type'] == 'award':
            # Award downloads
            queryset = filter_function(json_request['filters'])
            award_type_codes = set(json_request['filters']['award_type_codes'])

            if award_type_codes & (set(contract_type_mapping.keys())
                                   | set(idv_type_mapping.keys())):
                # only generate d1 files if the user is asking for contract data
                d1_source = CsvSource(
                    VALUE_MAPPINGS[download_type]['table_name'], 'd1',
                    download_type, agency_id)
                d1_filters = {
                    '{}__isnull'.format(VALUE_MAPPINGS[download_type]['contract_data']):
                    False
                }
                d1_source.queryset = queryset & download_type_table.objects.filter(
                    **d1_filters)
                csv_sources.append(d1_source)

            if award_type_codes & set(assistance_type_mapping.keys()):
                # only generate d2 files if the user is asking for assistance data
                d2_source = CsvSource(
                    VALUE_MAPPINGS[download_type]['table_name'], 'd2',
                    download_type, agency_id)
                d2_filters = {
                    '{}__isnull'.format(VALUE_MAPPINGS[download_type]['assistance_data']):
                    False
                }
                d2_source.queryset = queryset & download_type_table.objects.filter(
                    **d2_filters)
                csv_sources.append(d2_source)

            verify_requested_columns_available(tuple(csv_sources),
                                               json_request.get('columns', []))
        elif VALUE_MAPPINGS[download_type]['source_type'] == 'account':
            # Account downloads
            account_source = CsvSource(
                VALUE_MAPPINGS[download_type]['table_name'],
                json_request['account_level'], download_type, agency_id)
            account_source.queryset = filter_function(
                download_type, VALUE_MAPPINGS[download_type]['table'],
                json_request['filters'], json_request['account_level'])
            csv_sources.append(account_source)

    return csv_sources
示例#3
0
def get_csv_sources(json_request):
    csv_sources = []
    for download_type in json_request["download_types"]:
        agency_id = json_request["filters"].get("agency", "all")
        filter_function = VALUE_MAPPINGS[download_type]["filter_function"]
        download_type_table = VALUE_MAPPINGS[download_type]["table"]

        if VALUE_MAPPINGS[download_type]["source_type"] == "award":
            # Award downloads

            # Use correct date range columns for advanced search
            # (Will not change anything for keyword search since "time_period" is not provided))
            filters = add_date_range_comparison_types(
                json_request["filters"],
                is_subaward=download_type != "awards",
                gte_date_type="action_date",
                lte_date_type="date_signed",
            )

            queryset = filter_function(filters)
            award_type_codes = set(filters["award_type_codes"])

            if award_type_codes & (set(contract_type_mapping.keys()) | set(idv_type_mapping.keys())):
                # only generate d1 files if the user is asking for contract data
                d1_source = CsvSource(VALUE_MAPPINGS[download_type]["table_name"], "d1", download_type, agency_id)
                d1_filters = {"{}__isnull".format(VALUE_MAPPINGS[download_type]["contract_data"]): False}
                d1_source.queryset = queryset & download_type_table.objects.filter(**d1_filters)
                csv_sources.append(d1_source)

            if award_type_codes & set(assistance_type_mapping.keys()):
                # only generate d2 files if the user is asking for assistance data
                d2_source = CsvSource(VALUE_MAPPINGS[download_type]["table_name"], "d2", download_type, agency_id)
                d2_filters = {"{}__isnull".format(VALUE_MAPPINGS[download_type]["assistance_data"]): False}
                d2_source.queryset = queryset & download_type_table.objects.filter(**d2_filters)
                csv_sources.append(d2_source)

            verify_requested_columns_available(tuple(csv_sources), json_request.get("columns", []))
        elif VALUE_MAPPINGS[download_type]["source_type"] == "account":
            # Account downloads
            account_source = CsvSource(
                VALUE_MAPPINGS[download_type]["table_name"], json_request["account_level"], download_type, agency_id
            )
            account_source.queryset = filter_function(
                download_type,
                VALUE_MAPPINGS[download_type]["table"],
                json_request["filters"],
                json_request["account_level"],
            )
            csv_sources.append(account_source)

    return csv_sources
示例#4
0
def get_download_sources(json_request: dict,
                         origination: Optional[str] = None):
    download_sources = []
    for download_type in json_request["download_types"]:
        agency_id = json_request.get("agency", "all")
        filter_function = VALUE_MAPPINGS[download_type]["filter_function"]
        download_type_table = VALUE_MAPPINGS[download_type]["table"]

        if VALUE_MAPPINGS[download_type]["source_type"] == "award":
            # Award downloads

            # Use correct date range columns for advanced search
            # (Will not change anything for keyword search since "time_period" is not provided))
            filters = add_date_range_comparison_types(
                json_request["filters"],
                is_subaward=download_type != "awards",
                gte_date_type="action_date",
                lte_date_type="date_signed",
            )

            queryset = filter_function(filters)
            if filters.get("prime_and_sub_award_types") is not None:
                award_type_codes = set(
                    filters["prime_and_sub_award_types"][download_type])
            else:
                award_type_codes = set(filters["award_type_codes"])

            if (award_type_codes & (set(contract_type_mapping.keys())
                                    | set(idv_type_mapping.keys()))
                    or "procurement" in award_type_codes):
                # only generate d1 files if the user is asking for contract data
                d1_source = DownloadSource(
                    VALUE_MAPPINGS[download_type]["table_name"], "d1",
                    download_type, agency_id)
                d1_filters = {
                    f"{VALUE_MAPPINGS[download_type]['contract_data']}__isnull":
                    False
                }
                d1_source.queryset = queryset & download_type_table.objects.filter(
                    **d1_filters)
                download_sources.append(d1_source)

            if award_type_codes & set(assistance_type_mapping.keys()) or (
                    "grant" in award_type_codes):
                # only generate d2 files if the user is asking for assistance data
                d2_source = DownloadSource(
                    VALUE_MAPPINGS[download_type]["table_name"], "d2",
                    download_type, agency_id)
                d2_filters = {
                    f"{VALUE_MAPPINGS[download_type]['assistance_data']}__isnull":
                    False
                }
                d2_source.queryset = queryset & download_type_table.objects.filter(
                    **d2_filters)
                download_sources.append(d2_source)

        elif VALUE_MAPPINGS[download_type]["source_type"] == "account":
            # Account downloads
            account_source = DownloadSource(
                VALUE_MAPPINGS[download_type]["table_name"],
                json_request["account_level"], download_type, agency_id)
            account_source.queryset = filter_function(
                download_type,
                VALUE_MAPPINGS[download_type]["table"],
                json_request["filters"],
                json_request["account_level"],
            )
            download_sources.append(account_source)

    verify_requested_columns_available(tuple(download_sources),
                                       json_request.get("columns", []))

    return download_sources