Exemple #1
0
    def get(self, request: HttpRequest):

        # Check to see if a recent cached results exists and return that instead if it exists

        hashed_query = hashlib.sha1(
            request.GET.urlencode().encode('utf8')).hexdigest()
        cached_filename = os.path.join(self.cache_dir,
                                       "{}.csv".format(hashed_query))
        if os.path.exists(cached_filename):
            if time.time() - os.path.getmtime(cached_filename) > 600:
                os.remove(cached_filename)
            else:
                if settings.EXPORT_FILE_CACHE_URL == "":
                    return FileResponse(open(cached_filename, 'rb'),
                                        as_attachment=True)
                else:
                    return HttpResponseRedirect(
                        settings.EXPORT_FILE_CACHE_URL +
                        "{}.csv".format(hashed_query))

        solr_search_terms = search_util.get_search_terms(request)

        # 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', '')

        solr_search_facets = self.solr_facet_fields_en
        solr_query_fields = self.solr_query_fields_en
        if request.LANGUAGE_CODE == 'fr':
            facets_dict = dict(owner_org_fr_s=solr_search_orgs,
                               year_i=solr_search_year,
                               month_i=solr_search_month,
                               action_required_fr_s=solr_search_ar,
                               addressee_fr_s=solr_search_addrs)
            solr_search_facets = self.solr_facet_fields_fr
            solr_query_fields = self.solr_query_fields_fr
        else:
            facets_dict = dict(owner_org_en_s=solr_search_orgs,
                               year_i=solr_search_year,
                               month_i=solr_search_month,
                               action_required_en_s=solr_search_ar,
                               addressee_en_s=solr_search_addrs)

        search_results = search_util.solr_query_for_export(
            solr_search_terms, settings.SOLR_BN, self.solr_fields,
            solr_query_fields, solr_search_facets, "id asc", facets_dict,
            self.phrase_xtras)

        if search_util.cache_search_results_file(
                cached_filename=cached_filename, sr=search_results):
            if settings.EXPORT_FILE_CACHE_URL == "":
                return FileResponse(open(cached_filename, 'rb'),
                                    as_attachment=True)
            else:
                return HttpResponseRedirect(settings.EXPORT_FILE_CACHE_URL +
                                            "{}.csv".format(hashed_query))
Exemple #2
0
    def get(self, request: HttpRequest):

        # Check to see if a recent cached results exists and return that instead if it exists
        hashed_query = hashlib.sha1(request.GET.urlencode().encode('utf8')).hexdigest()
        cached_filename = os.path.join(self.cache_dir, "{}.csv".format(hashed_query))
        if os.path.exists(cached_filename):
            if time.time() - os.path.getmtime(cached_filename) > 600:
                os.remove(cached_filename)
            else:
                if settings.EXPORT_FILE_CACHE_URL == "":
                    return FileResponse(open(cached_filename, 'rb'), as_attachment=True)
                else:
                    return HttpResponseRedirect(settings.EXPORT_FILE_CACHE_URL + "{}.csv".format(hashed_query))

        solr_search_terms = search_util.get_search_terms(request)

        # 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', '')

        solr_search_facets = self.solr_facet_fields_en
        if request.LANGUAGE_CODE == 'fr':
            facets_dict = dict(owner_org_fr_s=solr_search_orgs,
                               reporting_period_s=solr_search_periods,
                               commitments_fr_s=solr_search_commitments,
                               milestone_fr_s=solr_search_milestones,
                               status_fr_s=solr_search_status,
                               due_date_s=solr_search_due_dates,
                               )
        else:
            facets_dict = dict(owner_org_en_s=solr_search_orgs,
                               reporting_period_s=solr_search_periods,
                               commitments_en_s=solr_search_commitments,
                               milestone_en_s=solr_search_milestones,
                               status_en_s=solr_search_status,
                               due_date_s=solr_search_due_dates,
                               )

        search_results = search_util.solr_query_for_export(solr_search_terms,
                                                           settings.SOLR_NAP,
                                                           self.solr_fields,
                                                           self.solr_query_fields_en,
                                                           solr_search_facets,
                                                           "id asc",
                                                           facets_dict,
                                                           self.phrase_xtras)

        if search_util.cache_search_results_file(cached_filename=cached_filename, sr=search_results):
            if settings.EXPORT_FILE_CACHE_URL == "":
                return FileResponse(open(cached_filename, 'rb'), as_attachment=True)
            else:
                return HttpResponseRedirect(settings.EXPORT_FILE_CACHE_URL + "{}.csv".format(hashed_query))
Exemple #3
0
    def get(self, request: HttpRequest):
        # Check to see if a recent cached results exists and return that instead if it exists
        hashed_query = hashlib.sha1(
            request.GET.urlencode().encode('utf8')).hexdigest()
        cached_filename = os.path.join(
            self.cache_dir, "{}_{}.csv".format(hashed_query,
                                               request.LANGUAGE_CODE))
        if os.path.exists(cached_filename):
            if time.time() - os.path.getmtime(cached_filename) > 600:
                os.remove(cached_filename)
            else:
                if settings.EXPORT_FILE_CACHE_URL == "":
                    return FileResponse(open(cached_filename, 'rb'),
                                        as_attachment=True)
                else:
                    return HttpResponseRedirect(
                        settings.EXPORT_FILE_CACHE_URL +
                        "{}_{}.csv".format(hashed_query, request.LANGUAGE_CODE)
                    )

        # Retrieve any selected search facets
        params = get_user_facet_parameters(request)

        solr_search_terms = search_util.get_search_terms(request)

        if request.LANGUAGE_CODE == 'fr':
            facets_dict = dict(owner_org_fr_s=params['solr_search_orgs'],
                               status_fr_s=params['solr_search_status'],
                               reason_fr_s=params['solr_search_reason'])
            solr_fields = self.solr_fields_fr
            solr_search_facets = self.solr_facet_fields_fr
            solr_query_fields = self.solr_query_fields_fr
        else:
            facets_dict = dict(owner_org_en_s=params['solr_search_orgs'],
                               status_en_s=params['solr_search_status'],
                               reason_en_s=params['solr_search_reason'])
            solr_fields = self.solr_fields_en
            solr_search_facets = self.solr_facet_fields_en
            solr_query_fields = self.solr_query_fields_en

        search_results = search_util.solr_query_for_export(
            solr_search_terms, settings.SOLR_SD, solr_fields,
            solr_query_fields, solr_search_facets, "id asc", facets_dict,
            self.phrase_xtras)

        if search_util.cache_search_results_file(
                cached_filename=cached_filename, sr=search_results):
            if settings.EXPORT_FILE_CACHE_URL == "":
                return FileResponse(open(cached_filename, 'rb'),
                                    as_attachment=True)
            else:
                return HttpResponseRedirect(
                    settings.EXPORT_FILE_CACHE_URL +
                    "{}_{}.csv".format(hashed_query, request.LANGUAGE_CODE))
Exemple #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["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)
Exemple #5
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)
Exemple #6
0
    def get(self, request: HttpRequest):

        # Check to see if a recent cached results exists and return that instead if it exists

        hashed_query = hashlib.sha1(
            request.GET.urlencode().encode('utf8')).hexdigest()
        cached_filename = os.path.join(self.cache_dir,
                                       "{}.csv".format(hashed_query))
        if os.path.exists(cached_filename):
            if time.time() - os.path.getmtime(cached_filename) > 600:
                os.remove(cached_filename)
            else:
                if settings.EXPORT_FILE_CACHE_URL == "":
                    return FileResponse(open(cached_filename, 'rb'),
                                        as_attachment=True)
                else:
                    return HttpResponseRedirect(
                        settings.EXPORT_FILE_CACHE_URL +
                        "{}.csv".format(hashed_query))

        # Get any search terms

        solr_search_terms = search_util.get_search_terms(request)

        # 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',
                                                      '')

        solr_search_facets = self.solr_facet_fields_en
        if request.LANGUAGE_CODE == 'fr':
            facets_dict = dict(
                owner_org_fr_s=solr_search_orgs,
                fiscal_year_s=solr_search_years,
                external_internal_fr_s=solr_search_xis,
                service_type_fr_s=solr_search_stype,
                special_designations_fr_s=solr_search_designations,
                client_target_groups_fr_s=solr_search_targets,
                service_fee_fr_s=solr_search_fees,
                cra_business_number_fr_s=solr_search_cra_no,
                e_registration_fr_s=solr_search_e_reg,
                e_authentication_fr_s=solr_search_e_authenticate,
                e_decision_fr_s=solr_search_e_decision,
                e_issuance_fr_s=solr_search_e_issuance,
                e_feedback_fr_s=solr_search_e_feedback,
            )
        else:
            facets_dict = dict(
                owner_org_en_s=solr_search_orgs,
                fiscal_year_s=solr_search_years,
                external_internal_en_s=solr_search_xis,
                service_type_en_s=solr_search_stype,
                special_designations_en_s=solr_search_designations,
                client_target_groups_en_s=solr_search_targets,
                service_fee_en_s=solr_search_fees,
                cra_business_number_en_s=solr_search_cra_no,
                e_registration_en_s=solr_search_e_reg,
                e_authentication_en_s=solr_search_e_authenticate,
                e_decision_en_s=solr_search_e_decision,
                e_issuance_en_s=solr_search_e_issuance,
                e_feedback_en_s=solr_search_e_feedback,
            )

        search_results = search_util.solr_query_for_export(
            solr_search_terms, settings.SOLR_SI, self.solr_fields,
            self.solr_query_fields_en, solr_search_facets, "id asc",
            facets_dict, self.phrase_xtras)

        if search_util.cache_search_results_file(
                cached_filename=cached_filename, sr=search_results):
            if settings.EXPORT_FILE_CACHE_URL == "":
                return FileResponse(open(cached_filename, 'rb'),
                                    as_attachment=True)
            else:
                return HttpResponseRedirect(settings.EXPORT_FILE_CACHE_URL +
                                            "{}.csv".format(hashed_query))
Exemple #7
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)
Exemple #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["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)
Exemple #9
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)
Exemple #10
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)
Exemple #11
0
    def get(self, request):

        # If a list of ids is provided, then the facets and search text are ignored.

        search_text = ''
        solr_search_terms = ''
        solr_search_portal = ''
        solr_search_col = ''
        solr_search_jur = ''
        solr_search_orgs = ''
        solr_search_keyw = ''
        solr_search_subj = ''
        solr_search_fmts = ''
        solr_search_rsct = ''
        solr_search_updc = ''

        solr_search_ids = request.GET.get('ids', '')

        mlt_search_id = request.GET.get("mlt_id", '')

        if solr_search_ids == '' and mlt_search_id == '':
            # Handle search text
            search_text = str(request.GET.get('search_text', ''))

            # Get any search terms
            solr_search_terms = search_util.get_search_terms(request)

            # Retrieve any search facets and add to context

            solr_search_portal = request.GET.get('od-search-portal', '')
            solr_search_col = request.GET.get('od-search-col', '')
            solr_search_jur = request.GET.get('od-search-jur', '')
            solr_search_orgs = request.GET.get('od-search-orgs', '')
            solr_search_keyw = request.GET.get('od-search-keywords', '')
            solr_search_subj = request.GET.get('od-search-subjects', '')
            solr_search_fmts = request.GET.get('od-search-format', '')
            solr_search_rsct = request.GET.get('od-search-rsct', '')
            solr_search_updc = request.GET.get('od-search-update', '')

        context = dict(
            search_text=search_text,
            portal_selected_list=str(solr_search_portal).split('|'),
            portal_selected=solr_search_portal,
            col_selected_list=str(solr_search_col).split('|'),
            col_selected=solr_search_col,
            jur_selected_list=str(solr_search_jur).split('|'),
            jur_selected=solr_search_jur,
            organizations_selected_list=str(solr_search_orgs).split('|'),
            organizations_selected=solr_search_orgs,
            keyw_selected_list=str(solr_search_keyw).split('|'),
            keyw_selected=solr_search_keyw,
            subject_selected_list=str(solr_search_subj).split('|'),
            subject_selected=solr_search_subj,
            format_selected_list=str(solr_search_fmts).split('|'),
            format_selected=solr_search_fmts,
            rsct_selected_list=str(solr_search_rsct).split('|'),
            rsct_selected=solr_search_rsct,
            update_selected_list=str(solr_search_updc).split('|'),
            update_selected=solr_search_updc,
        )

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

        try:
            page = int(request.GET.get('page', 1))
        except ValueError:
            page = 1
        if page < 1:
            page = 1
        elif page > 10000:  # @magic_number: arbitrary upper range
            page = 10000
        start_row = 10 * (page - 1)

        alerts = []
        if hasattr(settings,
                   "CUSTOM_OD_ALERT_EN") and request.LANGUAGE_CODE == 'en':
            alerts.append(settings.CUSTOM_OD_ALERT_EN)
        elif hasattr(settings,
                     "CUSTOM_OD_ALERT_FR") and request.LANGUAGE_CODE == 'fr':
            alerts.append(settings.CUSTOM_OD_ALERT_FR)
        if 'Open Maps' in context['col_selected_list']:
            alerts.append(_(settings.OPEN_MAPS_INFO_EN))
        elif 'Cartes Ouvertes' in context['col_selected_list']:
            alerts.append(_(settings.OPEN_MAPS_INFO_FR))
        if 'Open Information' in context['portal_selected_list']:
            alerts.append(_(settings.OPEN_INFORMATION_INFO_EN))
        elif 'Information ouverte' in context['portal_selected_list']:
            alerts.append(_(settings.OPEN_INFORMATION_INFO_FR))
        if 'User' in context['jur_selected_list']:
            alerts.append(_(settings.OPEN_DATA_EXTERNAL_INFO_EN))
        elif 'Utilisateur' in context['jur_selected_list']:
            alerts.append(_(settings.OPEN_DATA_EXTERNAL_INFO_FR))
        context['alerts'] = alerts

        # Set Sort order

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

        # Search Solr and return results and facets

        if request.LANGUAGE_CODE == 'fr':
            facets_dict = dict(
                portal_type_fr_s=context['portal_selected'],
                collection_type_fr_s=context['col_selected'],
                jurisdiction_fr_s=context['jur_selected'],
                owner_org_title_fr_s=context['organizations_selected'],
                keywords_fr_s=context['keyw_selected'],
                subject_fr_s=context['subject_selected'],
                resource_format_s=context['format_selected'],
                resource_type_fr_s=context['rsct_selected'],
                update_cycle_fr_s=context['update_selected'])
        else:
            facets_dict = dict(
                portal_type_en_s=context['portal_selected'],
                collection_type_en_s=context['col_selected'],
                jurisdiction_en_s=context['jur_selected'],
                owner_org_title_en_s=context['organizations_selected'],
                keywords_en_s=context['keyw_selected'],
                subject_en_s=context['subject_selected'],
                resource_format_s=context['format_selected'],
                resource_type_en_s=context['rsct_selected'],
                update_cycle_en_s=context['update_selected'])

        # Retrieve search results and transform facets results to python dict
        if mlt_search_id == '':
            if request.LANGUAGE_CODE == 'fr':
                search_results = search_util.solr_query(
                    solr_search_terms,
                    settings.SOLR_URL,
                    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(settings.OPEN_DATA_ITEMS_PER_PAGE),
                    facets=facets_dict,
                    sort_order=solr_search_sort,
                    uuid_list=solr_search_ids,
                    facet_limit=self.solr_facet_limits_fr)
            else:
                search_results = search_util.solr_query(
                    solr_search_terms,
                    settings.SOLR_URL,
                    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(settings.OPEN_DATA_ITEMS_PER_PAGE),
                    facets=facets_dict,
                    sort_order=solr_search_sort,
                    uuid_list=solr_search_ids,
                    facet_limit=self.solr_facet_limits_en)
            context['mlt_message'] = ''
        else:
            if request.LANGUAGE_CODE == 'fr':
                search_results = search_util.solr_mlt(
                    mlt_search_id,
                    settings.SOLR_URL,
                    self.solr_fields_fr,
                    self.solr_facet_fields_fr,
                    self.mlt_fields_fr,
                    start_row='0',
                    pagesize='10')
                context[
                    'mlt_message'] = " similaries à <strong>{0}</strong>".format(
                        search_results.docs[0]['title_fr_s'])
            else:
                search_results = search_util.solr_mlt(
                    mlt_search_id,
                    settings.SOLR_URL,
                    self.solr_fields_en,
                    self.solr_facet_fields_en,
                    self.mlt_fields_en,
                    start_row='0',
                    pagesize='10')
                context[
                    'mlt_message'] = " similar to <strong>{0}</strong>".format(
                        search_results.docs[0]['title_en_s'])
            search_results.docs = search_results.raw_response['moreLikeThis'][
                mlt_search_id]['docs']

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

        if request.LANGUAGE_CODE == 'fr':
            context['portal_facets'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['portal_type_fr_s'])
            context[
                'collection_facets'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']
                    ['collection_type_fr_s'])
            context[
                'jurisdiction_facets'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']['jurisdiction_fr_s'])
            context['org_facets_en'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_title_fr_s'])
            context['org_facets_fr'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_title_fr_s'])
            context['keyword_facets'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['keywords_fr_s'])
            context['subject_facets'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['subject_fr_s'])
            context['format_facets'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['resource_format_s'])
            context['type_facets'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['resource_type_fr_s'])
            context[
                'frequency_facets'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']['update_cycle_fr_s'])
        else:
            context['portal_facets'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['portal_type_en_s'])
            context[
                'collection_facets'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']
                    ['collection_type_en_s'])
            context[
                'jurisdiction_facets'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']['jurisdiction_en_s'])
            context['org_facets_en'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_title_en_s'])
            context['org_facets_fr'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['owner_org_title_en_s'])
            context['keyword_facets'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['keywords_en_s'])
            context['subject_facets'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['subject_en_s'])
            context['format_facets'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['resource_format_s'])
            context['type_facets'] = search_util.convert_facet_list_to_dict(
                search_results.facets['facet_fields']['resource_type_en_s'])
            context[
                'frequency_facets'] = search_util.convert_facet_list_to_dict(
                    search_results.facets['facet_fields']['update_cycle_en_s'])

        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

        # Base url to link back to Open Data for ht efull record

        context["od_en_url"] = settings.OPEN_DATA_EN_URL_BASE
        context["od_fr_url"] = settings.OPEN_DATA_FR_URL_BASE
        context["od_ds_id"] = settings.OPEN_DATA_DATASET_ID
        context["od_ds_title_en"] = settings.OPEN_DATA_DATASET_TITLE_EN
        context["od_ds_title_fr"] = settings.OPEN_DATA_DATASET_TITLE_FR
        context["cdts_version"] = settings.CDTS_VERSION
        context['od_en_fgp_root'] = settings.OPEN_DATA_EN_FGP_BASE
        context['od_fr_fgp_root'] = settings.OPEN_DATA_FR_FGP_BASE
        # 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."

            # Adobe Analytics URL
        context["adobe_analytics_url"] = settings.ADOBE_ANALYTICS_URL

        return render(request, "od_search.html", context)
Exemple #12
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)