Exemplo n.º 1
0
    def get(self, request):

        context = dict(LANGUAGE_CODE=request.LANGUAGE_CODE, )
        context["cdts_version"] = settings.CDTS_VERSION
        context["od_en_url"] = settings.OPEN_DATA_EN_URL_BASE
        context["od_fr_url"] = settings.OPEN_DATA_FR_URL_BASE
        context["ei_ds_id"] = settings.EI_DATASET_ID
        context["ei_ds_title_en"] = settings.EI_DATASET_TITLE_EN
        context["ei_ds_title_fr"] = settings.EI_DATASET_TITLE_FR
        context["adobe_analytics_url"] = settings.ADOBE_ANALYTICS_URL
        if request.LANGUAGE_CODE == 'fr':
            context['about_msg'] = settings.EI_ABOUT_FR
        else:
            context['about_msg'] = settings.EI_ABOUT_EN
        # Get any search terms
        solr_search_terms = search_util.get_search_terms(request)
        context['search_text'] = str(request.GET.get('search_text', ''))
        items_per_page = 15
        # Allow for, but do not require, a custom alert message
        if hasattr(settings, 'OPEN_DATA_PORTAL_ALERT_BASE'):
            context['od_portal_alert_base'] = settings.OPEN_DATA_PORTAL_ALERT_BASE
        else:
            context['od_portal_alert_base'] = "/data/static/_site_messaging/header_od_ckan."

        # Retrieve search sort order
        solr_search_sort = request.GET.get('sort', 'score desc')
        if solr_search_sort not in ['score desc', 'contract_delivery_s desc', 'contract_value_f desc']:
            solr_search_sort = 'score desc'
        context['sortby'] = solr_search_sort

        # Get current page
        start_row, page = search_util.calc_starting_row(request.GET.get('page', 1))

        # Retrieve any selected search facets and convert to lists, and create a facets dictionary
        solr_area: str = request.GET.get('ei-area', '')
        solr_design: str = request.GET.get('ei-design', '')
        solr_status: str = request.GET.get('ei-status', '')
        solr_search_orgs: str = request.GET.get('ei-search-orgs', '')
        context['area_selected'] = solr_area
        context['area_selected_list'] = solr_area.split('|')
        context['method_selected'] = solr_design
        context['method_selected_list'] = solr_design.split('|')
        context['status_selected'] = solr_status
        context['status_selected_list'] = solr_status.split('|')
        context["organizations_selected"] = solr_search_orgs
        context["organizations_selected_list"] = solr_search_orgs.split('|')

        if request.LANGUAGE_CODE == 'fr':
            facets_dict = dict(owner_org_fr_s=solr_search_orgs,
                               experimental_area_fr_s=solr_area,
                               research_design_fr_s=solr_design,
                               status_fr_s=solr_status)
        else:
            facets_dict = dict(owner_org_en_s=solr_search_orgs,
                               experimental_area_en_s=solr_area,
                               research_design_en_s=solr_design,
                               status_en_s=solr_status)

        # Query Solr
        if request.LANGUAGE_CODE == 'fr':
            search_results = search_util.solr_query(solr_search_terms,
                                                    settings.SOLR_EI,
                                                    self.solr_fields_fr,
                                                    self.solr_query_fields_fr,
                                                    self.solr_facet_fields_fr,
                                                    self.phrase_xtras_fr,
                                                    start_row=str(start_row), pagesize=str(items_per_page),
                                                    facets=facets_dict,
                                                    sort_order=solr_search_sort,
                                                    facet_limit={'facet.limit': 200})
        else:
            search_results = search_util.solr_query(solr_search_terms,
                                                    settings.SOLR_EI,
                                                    self.solr_fields_en,
                                                    self.solr_query_fields_en,
                                                    self.solr_facet_fields_en,
                                                    self.phrase_xtras_en,
                                                    start_row=str(start_row), pagesize=str(items_per_page),
                                                    facets=facets_dict,
                                                    sort_order=solr_search_sort,
                                                    facet_limit={'facet.limit': 200})

        context['results'] = search_results
        export_url = "/{0}/ei/export/?{1}".format(request.LANGUAGE_CODE, request.GET.urlencode())
        context['export_url'] = export_url

        # Set pagination values for the page
        pagination = search_util.calc_pagination_range(context['results'], items_per_page, page)
        context['pagination'] = pagination
        context['previous_page'] = (1 if page == 1 else page - 1)
        last_page = (pagination[len(pagination) - 1] if len(pagination) > 0 else 1)
        last_page = (1 if last_page < 1 else last_page)
        context['last_page'] = last_page
        next_page = page + 1
        next_page = (last_page if next_page > last_page else next_page)
        context['next_page'] = next_page
        context['currentpage'] = page

        # Set search result facets results
        if request.LANGUAGE_CODE == 'fr':
            context['experimental_area_fr_s'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['experimental_area_fr_s'])
            context['research_design_fr_s'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['research_design_fr_s'])
            context['status_fr_s'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['status_fr_s'])
            context['owner_org_fr_s'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_fr_s'])
        else:
            context['experimental_area_en_s'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['experimental_area_en_s'])
            context['research_design_en_s'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['research_design_en_s'])
            context['status_en_s'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['status_en_s'])
            context['owner_org_en_s'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_en_s'])

        return render(request, "ei_search.html", context)
Exemplo n.º 2
0
 def test_calc_starting_row(self):
     start_page = calc_starting_row(34, 10)
     self.assertEqual(start_page[0], 330)
Exemplo n.º 3
0
    def get(self, request):

        context = dict(LANGUAGE_CODE=request.LANGUAGE_CODE, )
        context["cdts_version"] = settings.CDTS_VERSION
        context["adobe_analytics_url"] = settings.ADOBE_ANALYTICS_URL
        if request.LANGUAGE_CODE == 'fr':
            context['about_msg'] = settings.SD_ABOUT_FR
        else:
            context['about_msg'] = settings.SD_ABOUT_EN

        items_per_page = int(settings.OPEN_DATA_ITEMS_PER_PAGE)

        # Allow for, but do not require, a custom alert message
        if hasattr(settings, 'OPEN_DATA_PORTAL_ALERT_BASE'):
            context[
                'od_portal_alert_base'] = settings.OPEN_DATA_PORTAL_ALERT_BASE
        else:
            context[
                'od_portal_alert_base'] = "/data/static/_site_messaging/header_od_ckan."

        # Get any search terms

        solr_search_terms = search_util.get_search_terms(request)
        context['search_text'] = str(request.GET.get('search_text', ''))

        # Retrieve search results and transform facets results to python dict

        solr_search_orgs: str = request.GET.get('sd-search-orgs', '')
        solr_search_subject: str = request.GET.get('sd-subject', '')
        solr_search_status: str = request.GET.get('sd-status', '')
        context["organizations_selected"] = solr_search_orgs
        context["organizations_selected_list"] = solr_search_orgs.split('|')
        context["subjects_selected"] = solr_search_subject
        context["subjects_selected_list"] = solr_search_subject.split('|')
        context["status_selected"] = solr_search_status
        context["status_selected_list"] = solr_search_status.split('|')
        context["suggest_a_dataset_en"] = settings.SD_SUGGEST_A_DATASET_EN
        context["suggest_a_dataset_fr"] = settings.SD_SUGGEST_A_DATASET_FR

        start_row, page = search_util.calc_starting_row(
            request.GET.get('page', 1))

        # Retrieve search sort order
        solr_search_sort = request.GET.get('sort', 'score desc')
        if solr_search_sort not in [
                'score desc', 'date_received_dt desc', 'date_recieved_dt asc',
                'votes asc', 'votes desc'
        ]:
            solr_search_sort = 'score desc'
        context['sortby'] = solr_search_sort

        if request.LANGUAGE_CODE == 'fr':
            facets_dict = dict(
                owner_org_fr_s=context['organizations_selected'],
                status_fr_s=context['status_selected'],
                subjects_fr_s=context['subjects_selected'])
        else:
            facets_dict = dict(
                owner_org_en_s=context['organizations_selected'],
                status_en_s=context['status_selected'],
                subjects_en_s=context['subjects_selected'])

        if request.LANGUAGE_CODE == 'fr':
            search_results = search_util.solr_query(
                solr_search_terms,
                settings.SOLR_SD,
                self.solr_fields_fr,
                self.solr_query_fields_fr,
                self.solr_facet_fields_fr,
                self.phrase_xtras_fr,
                start_row=str(start_row),
                pagesize=str(items_per_page),
                facets=facets_dict,
                sort_order=solr_search_sort)
        else:
            search_results = search_util.solr_query(
                solr_search_terms,
                settings.SOLR_SD,
                self.solr_fields_en,
                self.solr_query_fields_en,
                self.solr_facet_fields_en,
                self.phrase_xtras_en,
                start_row=str(start_row),
                pagesize=str(items_per_page),
                facets=facets_dict,
                sort_order=solr_search_sort)

        context['results'] = search_results
        export_url = "/{0}/sd/export/?{1}".format(request.LANGUAGE_CODE,
                                                  request.GET.urlencode())
        context['export_url'] = export_url

        # Set pagination values for the page

        pagination = search_util.calc_pagination_range(context['results'],
                                                       items_per_page, page)
        context['pagination'] = pagination
        context['previous_page'] = (1 if page == 1 else page - 1)
        last_page = (pagination[len(pagination) -
                                1] if len(pagination) > 0 else 1)
        last_page = (1 if last_page < 1 else last_page)
        context['last_page'] = last_page
        next_page = page + 1
        next_page = (last_page if next_page > last_page else next_page)
        context['next_page'] = next_page
        context['currentpage'] = page

        if request.LANGUAGE_CODE == 'fr':
            context['org_facets_fr'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_fr_s'])
            context[
                'status_facets_fr'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']['status_fr_s'])
            context[
                'subjects_facets_fr'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']['subjects_fr_s'])
        else:
            context['org_facets_en'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_en_s'])
            context[
                'status_facets_en'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']['status_en_s'])
            context[
                'subjects_facets_en'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']['subjects_en_s'])

        return render(request, "sd_search.html", context)
Exemplo n.º 4
0
    def get(self, request):

        context = dict(LANGUAGE_CODE=request.LANGUAGE_CODE, )
        context["cdts_version"] = settings.CDTS_VERSION
        context["od_en_url"] = settings.OPEN_DATA_EN_URL_BASE
        context["od_fr_url"] = settings.OPEN_DATA_FR_URL_BASE
        context["si_ds_id"] = settings.SI_DATASET_ID
        context["si_ds_title_en"] = settings.SI_DATASET_TITLE_EN
        context["si_ds_title_fr"] = settings.SI_DATASET_TITLE_FR
        context["si_dv_path_en"] = settings.SI_DATAVIZ_PATH_EN
        context["si_dv_path_fr"] = settings.SI_DATAVIZ_PATH_FR
        context["adobe_analytics_url"] = settings.ADOBE_ANALYTICS_URL
        # Allow for, but do not require, a custom alert message
        if hasattr(settings, 'OPEN_DATA_PORTAL_ALERT_BASE'):
            context[
                'od_portal_alert_base'] = settings.OPEN_DATA_PORTAL_ALERT_BASE
        else:
            context[
                'od_portal_alert_base'] = "/data/static/_site_messaging/header_od_ckan."

        # Get any search terms
        solr_search_terms = search_util.get_search_terms(request)
        context['search_text'] = str(request.GET.get('search_text', ''))

        items_per_page = int(settings.SI_ITEMS_PER_PAGE)

        # Retrieve search results and transform facets results to python dict

        solr_search_orgs: str = request.GET.get('si-search-orgs', '')
        solr_search_years: str = request.GET.get('si-search-year', '')
        solr_search_xis: str = request.GET.get('si-search-ext-int', '')
        solr_search_stype: str = request.GET.get('si-search-service-type', '')
        solr_search_designations: str = request.GET.get(
            'si-search-designations', '')
        solr_search_targets: str = request.GET.get('si-search-target-groups',
                                                   '')
        solr_search_fees: str = request.GET.get('si-search-service-fee', '')
        solr_search_cra_no: str = request.GET.get('si-search-cra-number', '')
        solr_search_e_reg: str = request.GET.get('si-search-e-reg', '')
        solr_search_e_authenticate: str = request.GET.get(
            'si-search-e-authenticate', '')
        solr_search_e_decision: str = request.GET.get('si-search-e-decision',
                                                      '')
        solr_search_e_issuance: str = request.GET.get('si-search-e-issuance',
                                                      '')
        solr_search_e_feedback: str = request.GET.get('si-search-e-feedback',
                                                      '')

        context["organizations_selected"] = solr_search_orgs
        context["organizations_selected_list"] = solr_search_orgs.split('|')
        context["years_selected"] = solr_search_years
        context["years_selected_list"] = solr_search_years.split('|')
        context["xis_selected"] = solr_search_xis
        context["xis_selected_list"] = solr_search_xis.split('|')
        context["stypes_selected"] = solr_search_stype
        context["stypes_selected_list"] = solr_search_stype.split('|')
        context["designations_selected"] = solr_search_designations
        context["designations_selected_list"] = solr_search_designations.split(
            '|')
        context["targets_selected"] = solr_search_targets
        context["targets_selected_list"] = solr_search_targets.split('|')
        context["fees_selected"] = solr_search_fees
        context["fees_selected_list"] = solr_search_fees.split('|')
        context["cra_no_selected"] = solr_search_cra_no
        context["cra_no_selected_list"] = solr_search_cra_no.split('|')
        context["e_reg_selected"] = solr_search_e_reg
        context["e_reg_selected_list"] = solr_search_e_reg.split('|')
        context["e_authenticate_selected"] = solr_search_e_authenticate
        context[
            "e_authenticate_selected_list"] = solr_search_e_authenticate.split(
                '|')
        context["e_decision_selected"] = solr_search_e_decision
        context["e_decision_selected_list"] = solr_search_e_decision.split('|')
        context["e_issuance_selected"] = solr_search_e_issuance
        context["e_issuance_selected_list"] = solr_search_e_issuance.split('|')
        context["e_feedback_selected"] = solr_search_e_feedback
        context["e_feedback_selected_list"] = solr_search_e_feedback.split('|')

        start_row, page = search_util.calc_starting_row(
            request.GET.get('page', 1), items_per_page)

        solr_search_sort = request.GET.get('sort', 'score desc')
        if request.LANGUAGE_CODE == 'fr':
            if solr_search_sort not in [
                    'score desc', 'program_name_fr_s asc',
                    'service_name_fr_s asc'
            ]:
                solr_search_sort = 'score desc'
        else:
            if solr_search_sort not in [
                    'score desc', 'program_name_en_s asc',
                    'service_name_en_s asc'
            ]:
                solr_search_sort = 'score desc'
        context['sortby'] = solr_search_sort

        if request.LANGUAGE_CODE == 'fr':
            facets_dict = dict(
                owner_org_fr_s=context['organizations_selected'],
                fiscal_year_s=context['years_selected'],
                external_internal_fr_s=context['xis_selected'],
                service_type_fr_s=context['stypes_selected'],
                special_designations_fr_s=context['designations_selected'],
                client_target_groups_fr_s=context['targets_selected'],
                service_fee_fr_s=context["fees_selected"],
                cra_business_number_fr_s=context["cra_no_selected"],
                e_registration_fr_s=context["e_reg_selected"],
                e_authentication_fr_s=context["e_authenticate_selected"],
                e_decision_fr_s=context["e_decision_selected"],
                e_issuance_fr_s=context["e_issuance_selected"],
                e_feedback_fr_s=context["e_feedback_selected"],
            )
        else:
            facets_dict = dict(
                owner_org_en_s=context['organizations_selected'],
                fiscal_year_s=context['years_selected'],
                external_internal_en_s=context['xis_selected'],
                service_type_en_s=context['stypes_selected'],
                special_designations_en_s=context['designations_selected'],
                client_target_groups_en_s=context['targets_selected'],
                service_fee_en_s=context["fees_selected"],
                cra_business_number_en_s=context["cra_no_selected"],
                e_registration_en_s=context["e_reg_selected"],
                e_authentication_en_s=context["e_authenticate_selected"],
                e_decision_en_s=context["e_decision_selected"],
                e_issuance_en_s=context["e_issuance_selected"],
                e_feedback_en_s=context["e_feedback_selected"],
            )

        if request.LANGUAGE_CODE == 'fr':
            search_results = search_util.solr_query(
                solr_search_terms,
                settings.SOLR_SI,
                self.solr_fields_fr,
                self.solr_query_fields_fr,
                self.solr_facet_fields_fr,
                self.phrase_xtras_fr,
                start_row=str(start_row),
                pagesize=str(items_per_page),
                facets=facets_dict,
                sort_order=solr_search_sort)
        else:
            search_results = search_util.solr_query(
                solr_search_terms,
                settings.SOLR_SI,
                self.solr_fields_en,
                self.solr_query_fields_en,
                self.solr_facet_fields_en,
                self.phrase_xtras_en,
                start_row=str(start_row),
                pagesize=str(items_per_page),
                facets=facets_dict,
                sort_order=solr_search_sort)

        solr_search_orgs: str = request.GET.get('si-search-orgs', '')
        context["organizations_selected"] = solr_search_orgs

        context['results'] = search_results
        export_url = "/{0}/si/export/?{1}".format(request.LANGUAGE_CODE,
                                                  request.GET.urlencode())
        context['export_url'] = export_url

        pagination = search_util.calc_pagination_range(context['results'],
                                                       items_per_page, page)
        context['pagination'] = pagination
        context['previous_page'] = (1 if page == 1 else page - 1)
        last_page = (pagination[len(pagination) -
                                1] if len(pagination) > 0 else 1)
        last_page = (1 if last_page < 1 else last_page)
        context['last_page'] = last_page
        next_page = page + 1
        next_page = (last_page if next_page > last_page else next_page)
        context['next_page'] = next_page
        context['currentpage'] = page

        if request.LANGUAGE_CODE == 'fr':
            context['org_facets_fr'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_fr_s'])
            context['xis_facets_fr'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']
                ['external_internal_fr_s'])
            context[
                'stype_facets_fr'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']['service_type_fr_s'])
            context[
                'designation_facets_fr'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']
                    ['special_designations_fr_s'])
            context[
                'targets_facets_fr'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']
                    ['client_target_groups_fr_s'])
            context['fees_facets_fr'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['service_fee_fr_s'])
            context[
                'cra_no_facets_fr'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']
                    ['cra_business_number_fr_s'])
            context['e_reg_facets_fr'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['e_registration_fr_s'])
            context[
                'e_authenticate_facets_fr'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']
                    ['e_authentication_fr_s'])
            context[
                'e_decision_facets_fr'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']['e_decision_fr_s'])
            context[
                'e_issuance_facets_fr'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']['e_issuance_fr_s'])
            context[
                'e_feedback_facets_fr'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']['e_feedback_fr_s'])
            context['info_msg'] = settings.SI_NOTE_INFO_FR
        else:
            context['org_facets_en'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_en_s'])
            context['xis_facets_en'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']
                ['external_internal_en_s'])
            context[
                'stype_facets_en'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']['service_type_en_s'])
            context[
                'designation_facets_en'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']
                    ['special_designations_en_s'])
            context[
                'targets_facets_en'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']
                    ['client_target_groups_en_s'])
            context['fees_facets_en'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['service_fee_en_s'])
            context[
                'cra_no_facets_en'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']
                    ['cra_business_number_en_s'])
            context['e_reg_facets_en'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['e_registration_en_s'])
            context[
                'e_authenticate_facets_en'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']
                    ['e_authentication_en_s'])
            context[
                'e_decision_facets_en'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']['e_decision_en_s'])
            context[
                'e_issuance_facets_en'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']['e_issuance_en_s'])
            context[
                'e_feedback_facets_en'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']['e_feedback_en_s'])
            context['info_msg'] = settings.SI_NOTE_INFO_EN

        context['fiscal_year'] = search_util.convert_facet_list_to_dict(
            search_results.facets['facet_fields']['fiscal_year_s'])

        return render(request, "si_search.html", context)
Exemplo n.º 5
0
    def get(self, request):

        context = dict(LANGUAGE_CODE=request.LANGUAGE_CODE, )
        context["cdts_version"] = settings.CDTS_VERSION
        context["od_en_url"] = settings.OPEN_DATA_EN_URL_BASE
        context["od_fr_url"] = settings.OPEN_DATA_FR_URL_BASE
        context["bn_ds_id"] = settings.BRIEFING_NOTE_DATASET_ID
        context["bn_ds_title_en"] = settings.BRIEFING_NOTE_DATASET_TITLE_EN
        context["bn_ds_title_fr"] = settings.BRIEFING_NOTE_DATASET_TITLE_FR
        context["adobe_analytics_url"] = settings.ADOBE_ANALYTICS_URL

        items_per_page = int(settings.BN_ITEMS_PER_PAGE)

        # Allow for, but do not require, a custom alert message
        if hasattr(settings, 'OPEN_DATA_PORTAL_ALERT_BASE'):
            context[
                'od_portal_alert_base'] = settings.OPEN_DATA_PORTAL_ALERT_BASE
        else:
            context[
                'od_portal_alert_base'] = "/data/static/_site_messaging/header_od_ckan."

        # Get any search terms
        solr_search_terms = search_util.get_search_terms(request)
        context['search_text'] = str(request.GET.get('search_text', ''))

        # Retrieve search results and transform facets results to python dict

        solr_search_orgs: str = request.GET.get('bn-search-orgs', '')
        solr_search_year: str = request.GET.get('bn-search-year', '')
        solr_search_month: str = request.GET.get('bn-search-month', '')
        solr_search_ar: str = request.GET.get('bn-search-action', '')
        solr_search_addrs: str = request.GET.get('bn-search-addressee', '')

        context["organizations_selected"] = solr_search_orgs
        context["organizations_selected_list"] = solr_search_orgs.split('|')
        context["year_selected"] = solr_search_year
        context["year_selected_list"] = solr_search_year.split('|')
        context["month_selected"] = solr_search_month
        context["month_selected_list"] = solr_search_month.split('|')
        context["actions_selected"] = solr_search_ar
        context["actions_selected_list"] = solr_search_ar.split('|')
        context["addressee_selected"] = solr_search_addrs
        context["addressee_selected_list"] = solr_search_addrs.split('|')

        start_row, page = search_util.calc_starting_row(
            request.GET.get('page', 1), items_per_page)

        # Retrieve search sort order
        solr_search_sort = request.GET.get('sort', 'score desc')
        if solr_search_sort not in [
                'score desc', 'date_received_tdt desc', 'title_txt_en asc'
        ]:
            solr_search_sort = 'score desc'
        context['sortby'] = solr_search_sort

        if request.LANGUAGE_CODE == 'fr':
            facets_dict = dict(
                owner_org_fr_s=context['organizations_selected'],
                year_i=context['year_selected'],
                month_i=context['month_selected'],
                action_required_fr_s=context['actions_selected'],
                addressee_fr_s=context['addressee_selected'])
        else:
            facets_dict = dict(
                owner_org_en_s=context['organizations_selected'],
                year_i=context['year_selected'],
                month_i=context['month_selected'],
                action_required_en_s=context['actions_selected'],
                addressee_en_s=context['addressee_selected'])

        if request.LANGUAGE_CODE == 'fr':
            search_results = search_util.solr_query(
                solr_search_terms,
                settings.SOLR_BN,
                self.solr_fields_fr,
                self.solr_query_fields_fr,
                self.solr_facet_fields_fr,
                self.phrase_xtras_fr,
                start_row=str(start_row),
                pagesize=str(items_per_page),
                facets=facets_dict,
                sort_order=solr_search_sort)
        else:
            search_results = search_util.solr_query(
                solr_search_terms,
                settings.SOLR_BN,
                self.solr_fields_en,
                self.solr_query_fields_en,
                self.solr_facet_fields_en,
                self.phrase_xtras_en,
                start_row=str(start_row),
                pagesize=str(items_per_page),
                facets=facets_dict,
                sort_order=solr_search_sort)

        context['results'] = search_results
        export_url = "/{0}/bn/export/?{1}".format(request.LANGUAGE_CODE,
                                                  request.GET.urlencode())
        context['export_url'] = export_url

        # Set pagination values for the page

        pagination = search_util.calc_pagination_range(context['results'],
                                                       items_per_page, page)
        context['pagination'] = pagination
        context['previous_page'] = (1 if page == 1 else page - 1)
        last_page = (pagination[len(pagination) -
                                1] if len(pagination) > 0 else 1)
        last_page = (1 if last_page < 1 else last_page)
        context['last_page'] = last_page
        next_page = page + 1
        next_page = (last_page if next_page > last_page else next_page)
        context['next_page'] = next_page
        context['currentpage'] = page

        if request.LANGUAGE_CODE == 'fr':
            context['org_facets_fr'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_fr_s'])
            context[
                'action_required_fr_s'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']
                    ['action_required_fr_s'])
            context['addressee_fr_s'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['addressee_fr_s'])
            context['info_msg'] = settings.BRIEF_NOTE_INFO_FR

        else:
            context['org_facets_en'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_en_s'])
            context[
                'action_required_en_s'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']
                    ['action_required_en_s'])
            context['addressee_en_s'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['addressee_en_s'])
            context['info_msg'] = settings.BRIEF_NOTE_INFO_EN

        context['month_i'] = search_util.convert_facet_list_to_dict(
            search_results.facets['facet_fields']['month_i'])
        context['year_i'] = search_util.convert_facet_list_to_dict(
            search_results.facets['facet_fields']['year_i'])

        return render(request, "bn_search.html", context)
Exemplo n.º 6
0
    def get(self, request):
        context = dict(LANGUAGE_CODE=request.LANGUAGE_CODE, )
        context["cdts_version"] = settings.CDTS_VERSION
        context["od_en_url"] = settings.OPEN_DATA_EN_URL_BASE
        context["od_fr_url"] = settings.OPEN_DATA_FR_URL_BASE
        context["oc_en_url"] = settings.OPEN_CANADA_EN_URL_BASE
        context["oc_fr_url"] = settings.OPEN_CANADA_FR_URL_BASE
        context["nap_ds_id"] = settings.NAP_DATASET_ID
        context["nap_ds_title_en"] = settings.NAP_DATASET_TITLE_EN
        context["nap_ds_title_fr"] = settings.NAP_DATASET_TITLE_FR
        context["adobe_analytics_url"] = settings.ADOBE_ANALYTICS_URL
        # Allow for, but do not require, a custom alert message
        if hasattr(settings, 'OPEN_DATA_PORTAL_ALERT_BASE'):
            context['od_portal_alert_base'] = settings.OPEN_DATA_PORTAL_ALERT_BASE
        else:
            context['od_portal_alert_base'] = "/data/static/_site_messaging/header_od_ckan."
        # Get any search terms
        solr_search_terms = search_util.get_search_terms(request)
        context['search_text'] = str(request.GET.get('search_text', ''))
        if request.LANGUAGE_CODE == 'fr':
            context['info_msg'] = settings.NAP_INFO_FR
            context['about_msg'] = settings.NAP_ABOUT_FR
        else:
            context['info_msg'] = settings.NAP_INFO_EN
            context['about_msg'] = settings.NAP_ABOUT_EN
        items_per_page = int(settings.SI_ITEMS_PER_PAGE)

        # Retrieve search results and transform facets results to python dict

        solr_search_orgs: str = request.GET.get('ap-search-orgs', '')
        solr_search_periods: str = request.GET.get('ap-reporting-period', '')
        solr_search_commitments: str = request.GET.get('ap-commitment', '')
        solr_search_milestones: str = request.GET.get('ap-milestone', '')
        solr_search_status: str = request.GET.get('ap-status', '')
        solr_search_due_dates: str = request.GET.get('ap-due-date', '')

        context["organizations_selected"] = solr_search_orgs
        context["organizations_selected_list"] = solr_search_orgs.split('|')
        context["periods_selected"] = solr_search_periods
        context["periods_selected_list"] = solr_search_periods.split('|')
        context["commitments_selected"] = solr_search_commitments
        context["commitments_selected_list"] = solr_search_commitments.split('|')
        context["milestone_selected"] = solr_search_milestones
        context["milestone_selected_list"] = solr_search_milestones.split('|')
        context["statuses_selected"] = solr_search_status
        context["statuses_selected_list"] = solr_search_status.split('|')
        context["due_dates_selected"] = solr_search_due_dates
        context["due_dates_selected_list"] = solr_search_due_dates.split('|')

        start_row, page = search_util.calc_starting_row(request.GET.get('page', 1), items_per_page)

        solr_search_sort = request.GET.get('sort', 'score desc')
        if request.LANGUAGE_CODE == 'fr':
            if solr_search_sort not in ['score desc', 'reporting_period_s desc']:
                solr_search_sort = 'score desc'
        else:
            if solr_search_sort not in ['score desc', 'reporting_period_s desc']:
                solr_search_sort = 'score desc'
        context['sortby'] = solr_search_sort

        if request.LANGUAGE_CODE == 'fr':
            facets_dict = dict(owner_org_fr_s=context['organizations_selected'],
                               reporting_period_s=context['periods_selected'],
                               commitments_fr_s=context['commitments_selected'],
                               milestone_fr_s=context['milestone_selected'],
                               status_fr_s=context['statuses_selected'],
                               due_date_s=context['due_dates_selected'],
                               )
        else:
            facets_dict = dict(owner_org_en_s=context['organizations_selected'],
                               reporting_period_s=context['periods_selected'],
                               commitments_en_s=context['commitments_selected'],
                               milestone_en_s=context['milestone_selected'],
                               status_en_s=context['statuses_selected'],
                               due_date_s=context['due_dates_selected'],
                               )

        if request.LANGUAGE_CODE == 'fr':
            search_results = search_util.solr_query(solr_search_terms,
                                                    settings.SOLR_NAP,
                                                    self.solr_fields_fr,
                                                    self.solr_query_fields_fr,
                                                    self.solr_facet_fields_fr,
                                                    self.phrase_xtras_fr,
                                                    start_row=str(start_row), pagesize=str(items_per_page),
                                                    facets=facets_dict,
                                                    sort_order=solr_search_sort)
        else:
            search_results = search_util.solr_query(solr_search_terms,
                                                    settings.SOLR_NAP,
                                                    self.solr_fields_en,
                                                    self.solr_query_fields_en,
                                                    self.solr_facet_fields_en,
                                                    self.phrase_xtras_en,
                                                    start_row=str(start_row), pagesize=str(items_per_page),
                                                    facets=facets_dict,
                                                    sort_order=solr_search_sort)

        context['results'] = search_results
        export_url = "/{0}/nap/export/?{1}".format(request.LANGUAGE_CODE, request.GET.urlencode())
        context['export_url'] = export_url

        pagination = search_util.calc_pagination_range(context['results'], items_per_page, page)
        context['pagination'] = pagination
        context['previous_page'] = (1 if page == 1 else page - 1)
        last_page = (pagination[len(pagination) - 1] if len(pagination) > 0 else 1)
        last_page = (1 if last_page < 1 else last_page)
        context['last_page'] = last_page
        next_page = page + 1
        next_page = (last_page if next_page > last_page else next_page)
        context['next_page'] = next_page
        context['currentpage'] = page

        # Facet results
        context['reporting_periods_facets'] = search_util.convert_facet_list_to_dict(
            search_results.facets['facet_fields']['reporting_period_s'])
        context['due_date_facets_en'] = search_util.convert_facet_list_to_dict(
            search_results.facets['facet_fields']['due_date_s'])
        if request.LANGUAGE_CODE == 'fr':
            context['org_facets_fr'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_fr_s'])
            context['commitment_facets_fr'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['commitments_fr_s'])
            context['milestone_facets_fr'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['milestone_fr_s'])
            context['status_facets_fr'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['status_fr_s'])
        else:
            context['org_facets_en'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_en_s'])
            context['commitment_facets_en'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['commitments_en_s'])
            context['milestone_facets_en'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['milestone_en_s'])
            context['status_facets_en'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['status_en_s'])

        return render(request, "nap_search.html", context)
Exemplo n.º 7
0
    def get(self, request):

        context = dict(LANGUAGE_CODE=request.LANGUAGE_CODE, )
        context['query_string'] = request.META['QUERY_STRING']
        context['cdts_version'] = settings.CDTS_VERSION
        context['od_en_url'] = settings.OPEN_DATA_EN_URL_BASE
        context['od_fr_url'] = settings.OPEN_DATA_FR_URL_BASE
        context['ds_id'] = settings.QP_DATASET_ID
        context['ds_title_en'] = settings.QP_DATASET_TITLE_EN
        context['ds_title_fr'] = settings.QP_DATASET_TITLE_FR
        context['adobe_analytics_url'] = settings.ADOBE_ANALYTICS_URL
        # Allow for, but do not require, a custom alert message
        if hasattr(settings, 'OPEN_DATA_PORTAL_ALERT_BASE'):
            context[
                'od_portal_alert_base'] = settings.OPEN_DATA_PORTAL_ALERT_BASE
        else:
            context[
                'od_portal_alert_base'] = "/data/static/_site_messaging/header_od_ckan."

        items_per_page = int(settings.QP_ITEMS_PER_PAGE)
        start_row, page = search_util.calc_starting_row(
            request.GET.get('page', 1), items_per_page)

        if request.LANGUAGE_CODE == 'fr':
            context['info_msg'] = settings.QP_INFO_FR
        else:
            context['info_msg'] = settings.QP_INFO_EN

        # Get any search terms
        solr_search_terms = search_util.get_search_terms(request)
        context['search_text'] = str(request.GET.get('search_text', ''))

        # Retrieve search sort order
        if request.GET.get('sort') is None:
            # setup default sort
            solr_search_sort = 'date_received_dt desc'
        else:
            solr_search_sort = request.GET.get('sort', 'score desc')
            if request.LANGUAGE_CODE == 'fr':
                if solr_search_sort not in [
                        'score desc', 'date_received_dt desc', 'title_fr_s asc'
                ]:
                    solr_search_sort = 'score desc'
            else:
                if solr_search_sort not in [
                        'score desc', 'date_received_dt desc', 'title_en_s asc'
                ]:
                    solr_search_sort = 'score desc'
        context['sortby'] = solr_search_sort

        # Retrieve facets and transform facets results to python dict
        solr_search_year: str = request.GET.get('qp-search-year', '')
        solr_search_month: str = request.GET.get('qp-search-month', '')
        solr_search_minister: str = request.GET.get('qp-search-minister', '')
        solr_search_minister_status: str = request.GET.get(
            'qp-search-minister-status', '')
        solr_search_minister_position: str = request.GET.get(
            'qp-search-minister-positions', '')
        solr_search_orgs: str = request.GET.get('qp-search-orgs', '')

        context['year_selected'] = solr_search_year
        context['year_selected_list'] = solr_search_year.split('|')
        context['month_selected'] = solr_search_month
        context['month_selected_list'] = solr_search_month.split('|')
        context['minister_selected'] = solr_search_minister
        context['minister_selected_list'] = solr_search_minister.split('|')
        context['minister_position_selected'] = solr_search_minister_position
        context[
            'minister_position_selected_list'] = solr_search_minister_position.split(
                '|')
        context['minister_status_selected'] = solr_search_minister_status
        context[
            'minister_status_selected_list'] = solr_search_minister_status.split(
                '|')
        context["organizations_selected"] = solr_search_orgs
        context["organizations_selected_list"] = solr_search_orgs.split('|')

        if request.LANGUAGE_CODE == 'fr':
            facets_dict = dict(
                year_i=context['year_selected'],
                month_i=context['month_selected'],
                minister_fr_s=context['minister_selected'],
                minister_position_fr_s=context['minister_position_selected'],
                minister_status_fr_s=context['minister_status_selected'],
                owner_org_fr_s=context['organizations_selected'],
            )
        else:
            facets_dict = dict(
                year_i=context['year_selected'],
                month_i=context['month_selected'],
                minister_en_s=context['minister_selected'],
                minister_position_en_s=context['minister_position_selected'],
                minister_status_en_s=context['minister_status_selected'],
                owner_org_en_s=context['organizations_selected'],
            )

        # Generate search results
        if request.LANGUAGE_CODE == 'fr':
            search_results = search_util.solr_query(
                solr_search_terms,
                settings.SOLR_QP,
                self.solr_fields_fr,
                self.solr_query_fields_fr,
                self.solr_facet_fields_fr,
                self.phrase_xtras_fr,
                start_row=str(start_row),
                pagesize=str(items_per_page),
                facets=facets_dict,
                sort_order=solr_search_sort)

        else:
            search_results = search_util.solr_query(
                solr_search_terms,
                settings.SOLR_QP,
                self.solr_fields_en,
                self.solr_query_fields_en,
                self.solr_facet_fields_en,
                self.phrase_xtras_en,
                start_row=str(start_row),
                pagesize=str(items_per_page),
                facets=facets_dict,
                sort_order=solr_search_sort)

        context['results'] = search_results

        # Set pagination values for the page
        pagination = search_util.calc_pagination_range(context['results'],
                                                       items_per_page, page)
        context['pagination'] = pagination
        context['previous_page'] = (1 if page == 1 else page - 1)
        last_page = (pagination[len(pagination) -
                                1] if len(pagination) > 0 else 1)
        last_page = (1 if last_page < 1 else last_page)
        context['last_page'] = last_page
        next_page = page + 1
        next_page = (last_page if next_page > last_page else next_page)
        context['next_page'] = next_page
        context['currentpage'] = page

        # Generate facet list for the search result
        if request.LANGUAGE_CODE == 'fr':
            context['minister_fr_s'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['minister_fr_s'])
            context[
                'minister_position_facets_fr'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']
                    ['minister_position_fr_s'])
            context[
                'minister_status_facets_fr_s'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']
                    ['minister_status_fr_s'])
            context['org_facets_fr'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_fr_s'])
        else:
            context['minister_en_s'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['minister_en_s'])
            context[
                'minister_position_facets_en'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']
                    ['minister_position_en_s'])
            context[
                'minister_status_facets_en_s'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']
                    ['minister_status_en_s'])
            context['org_facets_en'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_en_s'])

        context['month_i'] = search_util.convert_facet_list_to_dict(
            search_results.facets['facet_fields']['month_i'])
        context['year_i'] = search_util.convert_facet_list_to_dict(
            search_results.facets['facet_fields']['year_i'])

        # export url
        export_url = "/{0}/qp/export/?{1}".format(request.LANGUAGE_CODE,
                                                  request.GET.urlencode())
        context['export_url'] = export_url
        return render(request, "qp_notes_search.html", context)
Exemplo n.º 8
0
    def get(self, request):

        context = dict(LANGUAGE_CODE=request.LANGUAGE_CODE, )
        context["cdts_version"] = settings.CDTS_VERSION
        context["od_en_url"] = settings.OPEN_DATA_EN_URL_BASE
        context["od_fr_url"] = settings.OPEN_DATA_FR_URL_BASE
        context["ati_ds_id"] = settings.ATI_DATASET_ID
        context["ati_ds_title_en"] = settings.ATI_DATASET_TITLE_EN
        context["ati_ds_title_fr"] = settings.ATI_DATASET_TITLE_FR
        context['ati_request_form_url_en'] = settings.ATI_REQUEST_URL_EN
        context['ati_request_form_url_fr'] = settings.ATI_REQUEST_URL_FR

        # Get any search terms
        solr_search_terms = search_util.get_search_terms(request)
        context['search_text'] = str(request.GET.get('search_text', ''))

        # Get "Include Nothing To Report" flag, if available
        # Retrieve search results and transform facets results to python dict

        solr_search_rtype: str = request.GET.get('ati-report-type', '')
        solr_search_orgs: str = request.GET.get('ati-search-orgs', '')
        solr_search_year: str = request.GET.get('ati-search-year', '')
        solr_search_month: str = request.GET.get('ati-search-month', '')

        context["organizations_selected"] = solr_search_orgs
        context["organizations_selected_list"] = solr_search_orgs.split('|')
        context["year_selected"] = solr_search_year
        context["year_selected_list"] = solr_search_year.split('|')
        context["month_selected"] = solr_search_month
        context["month_selected_list"] = solr_search_month.split('|')
        context["report_types_selected"] = solr_search_rtype
        context["report_types_selected_list"] = solr_search_rtype.split('|')

        # Calculate a starting row for the Solr search results. We only retrieve one page at a time

        start_row, page = search_util.calc_starting_row(
            request.GET.get('page', 1))

        # Retrieve search sort order

        solr_search_sort = request.GET.get('sort', 'score desc')
        if solr_search_sort not in ['score desc', 'year_i desc', 'year_i asc']:
            solr_search_sort = 'score desc'
        context['sortby'] = solr_search_sort

        if request.LANGUAGE_CODE == 'fr':
            facets_dict = dict(
                owner_org_fr_s=context['organizations_selected'],
                year_i=context['year_selected'],
                month_i=context['month_selected'],
                report_type_fr_s=context['report_types_selected'])
        else:
            facets_dict = dict(
                owner_org_en_s=context['organizations_selected'],
                year_i=context['year_selected'],
                month_i=context['month_selected'],
                report_type_en_s=context['report_types_selected'])

        search_results = self.solr_query(solr_search_terms,
                                         startrow=str(start_row),
                                         pagesize='10',
                                         facets=facets_dict,
                                         language=request.LANGUAGE_CODE,
                                         sort_order=solr_search_sort)

        context[
            'results'] = search_results  # Set up previous and next page numbers

        pagination = search_util.calc_pagination_range(context['results'], 10,
                                                       page)
        context['pagination'] = pagination
        context['previous_page'] = (1 if page == 1 else page - 1)
        last_page = (pagination[len(pagination) -
                                1] if len(pagination) > 0 else 1)
        last_page = (1 if last_page < 1 else last_page)
        context['last_page'] = last_page
        next_page = page + 1
        next_page = (last_page if next_page > last_page else next_page)
        context['next_page'] = next_page
        context['currentpage'] = page

        export_url = "/{0}/ati/export/?{1}".format(request.LANGUAGE_CODE,
                                                   request.GET.urlencode())
        context['export_url'] = export_url

        if request.LANGUAGE_CODE == 'fr':
            context['org_facets_fr'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_fr_s'])
            context['report_type_fr'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['report_type_fr_s'])
        else:
            context['org_facets_en'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_en_s'])
            context['report_type_en'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['report_type_en_s'])
        context['month_i'] = search_util.convert_facet_list_to_dict(
            search_results.facets['facet_fields']['month_i'])
        context['year_i'] = search_util.convert_facet_list_to_dict(
            search_results.facets['facet_fields']['year_i'])

        return render(request, "ati_search.html", context)