示例#1
0
    def get_org_sources(self, org_id, search_params=None):
        """
        Load org sources from the API and return OclSearch instance with results
        """
        # TODO([email protected]): Validate the input parameters

        # Perform the search
        searcher = OclSearch(search_type=OclConstants.RESOURCE_NAME_SOURCES,
                             search_scope=OclConstants.SEARCH_SCOPE_RESTRICTED,
                             params=search_params)
        api = OclApi(self.request, debug=True, facets=True)
        search_response = api.get('orgs',
                                  org_id,
                                  'sources',
                                  params=searcher.search_params)
        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the results
        searcher.process_search_results(search_type=searcher.search_type,
                                        search_response=search_response,
                                        search_params=self.request.GET)

        return searcher
示例#2
0
    def get_concept_history(self, owner_type, owner_id, source_id, concept_id,
                            search_params=None):
        """
        Get the concept version history.
        Note that source_version_id and concept_version_id are not applied here.
        """
        # TODO([email protected]): Validate input parameters

        # Perform the search
        searcher = OclSearch(search_type=OclConstants.RESOURCE_NAME_CONCEPT_VERSIONS,
                             search_scope=OclConstants.SEARCH_SCOPE_RESTRICTED,
                             params=search_params)
        api = OclApi(self.request, debug=True, facets=False)
        search_response = api.get(
            owner_type, owner_id, 'sources', source_id,
            'concepts', concept_id, 'versions')
        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the results
        searcher.process_search_results(
            search_type=searcher.search_type, search_response=search_response,
            search_params=search_params)

        return searcher
示例#3
0
文件: views.py 项目: AnshuAg/ocl_web
    def get_source_concepts(self, owner_type, owner_id, source_id,
                            source_version_id=None, search_params=None):
        """
        Load source concepts from the API and return OclSearch instance with results.
        """
        # TODO([email protected]): Validate the input parameters

        # Perform the search, applying source_version_id if not None
        searcher = OclSearch(search_type=OclConstants.RESOURCE_NAME_CONCEPTS,
                             search_scope=OclConstants.SEARCH_SCOPE_RESTRICTED,
                             params=search_params)
        api = OclApi(self.request, debug=True, facets=True)
        if source_version_id:
            search_response = api.get(
                owner_type, owner_id, 'sources', source_id, source_version_id, 'concepts',
                params=searcher.search_params)
        else:
            search_response = api.get(
                owner_type, owner_id, 'sources', source_id, 'concepts',
                params=searcher.search_params)
        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the results
        searcher.process_search_results(
            search_type=searcher.search_type, search_response=search_response,
            search_params=search_params)

        return searcher
示例#4
0
    def get_source_concepts(self, api_client, owner_type, owner_id, source_id,
                            source_version_id=None, search_params=None):
        """
        Load source concepts from the API and return OclSearch instance with results.
        """

        # Perform the search, applying source_version_id if not None
        searcher = OclSearch(search_type=OclConstants.RESOURCE_NAME_CONCEPTS,
                             search_scope=OclConstants.SEARCH_SCOPE_RESTRICTED,
                             params=search_params)

        if source_version_id:
            search_response = api_client.get(
                owner_type, owner_id, 'sources', source_id, source_version_id, 'concepts',
                params=searcher.search_params)
        else:
            search_response = api_client.get(
                owner_type, owner_id, 'sources', source_id, 'concepts',
                params=searcher.search_params)
        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the results
        searcher.process_search_results(
            search_type=searcher.search_type,
            search_response=search_response,
            search_params=search_params)

        return searcher
示例#5
0
    def get_collection_versions(self,
                                owner_type,
                                owner_id,
                                collection_id,
                                search_params=None):
        # Perform the search
        searcher = OclSearch(
            search_type=OclConstants.RESOURCE_NAME_COLLECTION_VERSIONS,
            search_scope=OclConstants.SEARCH_SCOPE_RESTRICTED,
            params=search_params)

        api = OclApi(self.request, debug=True, facets=False)
        search_response = api.get(owner_type,
                                  owner_id,
                                  'collections',
                                  collection_id,
                                  'versions',
                                  params=searcher.search_params)

        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the results
        searcher.process_search_results(search_type=searcher.search_type,
                                        search_response=search_response,
                                        search_params=search_params)

        return searcher
示例#6
0
    def get_collection_data(self, owner_type, owner_id, collection_id, field_name,
                            collection_version_id=None, search_params=None):

        searcher = OclSearch(search_type=field_name, params=search_params)
        api = OclApi(self.request, debug=True, facets=True)

        if collection_version_id:
            search_response = api.get(
                owner_type, owner_id, 'collections', collection_id,
                collection_version_id, field_name,
                params=searcher.search_params)
        else:
            search_response = api.get(
                owner_type, owner_id, 'collections', collection_id, field_name,
                params=searcher.search_params)
        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the results
        searcher.process_search_results(
            search_type=None, search_response=search_response,
            search_params=search_params)

        return searcher
示例#7
0
    def get_source_versions(self, owner_type, owner_id, source_id, search_params=None):
        """
        Load source versions from the API and return OclSearch instance with results.
        """
        # TODO([email protected]): Validate the input parameters

        # Perform the search
        searcher = OclSearch(search_type=OclConstants.RESOURCE_NAME_SOURCE_VERSIONS,
                             params=search_params)

        api = OclApi(self.request, debug=True, facets=False)
        search_response = api.get(owner_type, owner_id, 'sources', source_id, 'versions',
            params=searcher.search_params)

        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the results
        searcher.process_search_results(
            search_type=searcher.search_type, search_response=search_response,
            search_params=search_params)

        return searcher
示例#8
0
    def get_mapping_versions(self,
                             owner_type,
                             owner_id,
                             source_id,
                             mapping_id,
                             search_params=None):
        """
        Load mapping details from the API and return as dictionary.
        """
        # TODO([email protected]): Validate the input parameters

        searcher = OclSearch(
            search_type=OclConstants.RESOURCE_NAME_MAPPING_VERSIONS,
            search_scope=OclConstants.SEARCH_SCOPE_RESTRICTED,
            params=search_params)

        api = OclApi(self.request, debug=True, facets=False)
        search_response = api.get(owner_type,
                                  owner_id,
                                  'sources',
                                  source_id,
                                  'mappings',
                                  mapping_id,
                                  'versions',
                                  params=searcher.search_params)

        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()
        searcher.process_search_results(search_type=searcher.search_type,
                                        search_response=search_response,
                                        search_params=search_params)

        return searcher
示例#9
0
    def get_source_concepts(self, api_client, owner_type, owner_id, source_id,
                            source_version_id=None, search_params=None):
        """
        Load source concepts from the API and return OclSearch instance with results.
        """

        # Perform the search, applying source_version_id if not None
        searcher = OclSearch(search_type=OclConstants.RESOURCE_NAME_CONCEPTS,
                             search_scope=OclConstants.SEARCH_SCOPE_RESTRICTED,
                             params=search_params)

        if source_version_id:
            search_response = api_client.get(
                owner_type, owner_id, 'sources', source_id, source_version_id, 'concepts',
                params=searcher.search_params)
        else:
            search_response = api_client.get(
                owner_type, owner_id, 'sources', source_id, 'concepts',
                params=searcher.search_params)
        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the results
        searcher.process_search_results(
            search_type=searcher.search_type,
            search_response=search_response,
            search_params=search_params)

        return searcher
示例#10
0
    def get_source_mappings(self, owner_type, owner_id, source_id,
                            source_version_id=None, search_params=None):
        """
        Load source mappings from the API and return OclSearch instance with results.
        """

        # Perform the search, applying source_version_id if not None
        searcher = OclSearch(search_type=OclConstants.RESOURCE_NAME_MAPPINGS,
                             search_scope=OclConstants.SEARCH_SCOPE_RESTRICTED,
                             params=search_params)
        api = OclApi(self.request, debug=True, facets=True)
        if source_version_id:
            search_response = api.get(
                owner_type, owner_id, 'sources', source_id, source_version_id, 'mappings',
                params=searcher.search_params)
        else:
            search_response = api.get(
                owner_type, owner_id, 'sources', source_id, 'mappings',
                params=searcher.search_params)
        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the results
        searcher.process_search_results(
            search_type=searcher.search_type,
            search_response=search_response,
            search_params=search_params)

        return searcher
示例#11
0
    def get_concept_history(self,
                            owner_type,
                            owner_id,
                            source_id,
                            concept_id,
                            search_params=None):
        """
        Get the concept version history.
        Note that source_version_id and concept_version_id are not applied here.
        """
        # TODO([email protected]): Validate input parameters

        # Perform the search
        searcher = OclSearch(
            search_type=OclConstants.RESOURCE_NAME_CONCEPT_VERSIONS,
            search_scope=OclConstants.SEARCH_SCOPE_RESTRICTED,
            params=search_params)
        api = OclApi(self.request, debug=True, facets=False)
        search_response = api.get(owner_type, owner_id, 'sources', source_id,
                                  'concepts', concept_id, 'versions')
        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the results
        searcher.process_search_results(search_type=searcher.search_type,
                                        search_response=search_response,
                                        search_params=search_params)

        return searcher
示例#12
0
    def get_source_extrefs(self,
                           owner_type,
                           owner_id,
                           source_id,
                           source_version_id=None,
                           search_params=None):
        """
        Load external mappings that reference this source from the API, return OclSearch instance.
        """
        # TODO([email protected]): Validate the input parameters

        # Get search_params into a mutable QueryDict format so that I can add values
        if isinstance(search_params, QueryDict):
            params = search_params.copy()
        elif isinstance(search_params, basestring):
            params = QueryDict(search_params, mutable=True)
        elif isinstance(search_params, dict) or not search_params:
            params = QueryDict('', mutable=True)
            params.update(search_params)
        else:
            raise TypeError('Expected QueryDict, dict, or str.' +
                            str(search_params) + ' passed.')

        # Add additional search params for the extref mappings search
        new_params = {}
        new_params[
            'toConceptOwnerType'] = 'Organization' if owner_type == 'orgs' else 'User'
        new_params['toConceptOwner'] = self.owner_id
        new_params['toConceptSource'] = self.source_id
        params.update(new_params)

        # Perform the search
        searcher = OclSearch(search_type=OclConstants.RESOURCE_NAME_MAPPINGS,
                             search_scope=OclConstants.SEARCH_SCOPE_GLOBAL,
                             params=params)
        api = OclApi(self.request, debug=True, facets=True)
        search_response = api.get('mappings', params=searcher.search_params)
        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the results
        searcher.process_search_results(search_type=searcher.search_type,
                                        search_response=search_response,
                                        search_params=search_params)

        # TODO: Post-processing on external references results goes here
        # Maybe remove toConceptOwnerType, toConceptOwner, toConceptSource facets

        return searcher
示例#13
0
    def get_org_collections(self, org_id, search_params=None):

        # Perform the search
        searcher = OclSearch(search_type=OclConstants.RESOURCE_NAME_COLLECTIONS, params=search_params)
        api = OclApi(self.request, debug=True, facets=True)
        search_response = api.get('orgs', org_id, 'collections', params=searcher.search_params)
        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the results
        searcher.process_search_results(
            search_type=searcher.search_type, search_response=search_response,
            search_params=self.request.GET)

        return searcher
示例#14
0
文件: views.py 项目: AnshuAg/ocl_web
    def get_source_extrefs(self, owner_type, owner_id, source_id,
                           source_version_id=None, search_params=None):
        """
        Load external mappings that reference this source from the API, return OclSearch instance.
        """
        # TODO([email protected]): Validate the input parameters

        # Get search_params into a mutable QueryDict format so that I can add values
        if isinstance(search_params, QueryDict):
            params = search_params.copy()
        elif isinstance(search_params, basestring):
            params = QueryDict(search_params, mutable=True)
        elif isinstance(search_params, dict) or not search_params:
            params = QueryDict('', mutable=True)
            params.update(search_params)
        else:
            raise TypeError('Expected QueryDict, dict, or str.' + str(search_params) + ' passed.')

        # Add additional search params for the extref mappings search
        new_params = {}
        new_params['toConceptOwnerType'] = 'Organization' if owner_type == 'orgs' else 'User'
        new_params['toConceptOwner'] = self.owner_id
        new_params['toConceptSource'] = self.source_id
        params.update(new_params)

        # Perform the search
        searcher = OclSearch(search_type=OclConstants.RESOURCE_NAME_MAPPINGS,
                             search_scope=OclConstants.SEARCH_SCOPE_GLOBAL,
                             params=params)
        api = OclApi(self.request, debug=True, facets=True)
        search_response = api.get('mappings', params=searcher.search_params)
        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the results
        searcher.process_search_results(
            search_type=searcher.search_type, search_response=search_response,
            search_params=search_params)

        # TODO: Post-processing on external references results goes here
        # Maybe remove toConceptOwnerType, toConceptOwner, toConceptSource facets

        return searcher
示例#15
0
    def get_collection_versions(self, owner_type, owner_id, collection_id, search_params=None):
        # Perform the search
        searcher = OclSearch(search_type=OclConstants.RESOURCE_NAME_COLLECTION_VERSIONS,
                             search_scope=OclConstants.SEARCH_SCOPE_RESTRICTED,
                             params=search_params)

        api = OclApi(self.request, debug=True, facets=False)
        search_response = api.get(owner_type, owner_id, 'collections', collection_id, 'versions',
                                  params=searcher.search_params)

        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the results
        searcher.process_search_results(
            search_type=searcher.search_type, search_response=search_response,
            search_params=search_params)

        return searcher
示例#16
0
文件: views.py 项目: AnshuAg/ocl_web
    def get_org_sources(self, org_id, search_params=None):
        """
        Load org sources from the API and return OclSearch instance with results
        """
        # TODO([email protected]): Validate the input parameters

        # Perform the search
        searcher = OclSearch(search_type=OclConstants.RESOURCE_NAME_SOURCES,
                             search_scope=OclConstants.SEARCH_SCOPE_RESTRICTED,
                             params=search_params)
        api = OclApi(self.request, debug=True, facets=True)
        search_response = api.get('orgs', org_id, 'sources', params=searcher.search_params)
        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the results
        searcher.process_search_results(
            search_type=searcher.search_type, search_response=search_response,
            search_params=self.request.GET)

        return searcher
示例#17
0
    def get_mapping_versions(self, owner_type, owner_id, source_id, mapping_id, search_params=None):
        """
        Load mapping details from the API and return as dictionary.
        """
        # TODO([email protected]): Validate the input parameters

        searcher = OclSearch(search_type=OclConstants.RESOURCE_NAME_MAPPING_VERSIONS,
                             search_scope=OclConstants.SEARCH_SCOPE_RESTRICTED,
                             params=search_params)

        api = OclApi(self.request, debug=True, facets=False)
        search_response = api.get(
            owner_type, owner_id, 'sources', source_id, 'mappings', mapping_id, 'versions',
            params=searcher.search_params)

        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()
        searcher.process_search_results(
            search_type=searcher.search_type, search_response=search_response,
            search_params=search_params)

        return searcher
示例#18
0
文件: views.py 项目: AnshuAg/ocl_web
    def get_context_data(self, *args, **kwargs):
        """ Set context for OCL global search """

        context = super(GlobalSearchView, self).get_context_data(*args, **kwargs)

        # Perform the primary search via the API

        original_search_string = self.request.GET.get('q', '')
        SearchStringFormatter.add_wildcard(self.request)

        searcher = OclSearch(params=self.request.GET)

        api = OclApi(
            self.request, debug=True,
            facets=OclConstants.resource_has_facets(searcher.search_type))

        search_response = api.get(searcher.search_type, params=searcher.search_params)
        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the primary search results
        searcher.process_search_results(
            search_type=searcher.search_type,
            search_response=search_response,
            search_params=self.request.GET)

        # Setup paginator for primary search
        search_paginator = Paginator(range(searcher.num_found), searcher.num_per_page)
        search_current_page = search_paginator.page(searcher.current_page)

        # Set context for primary search
        context['results'] = searcher.search_results
        context['page'] = search_current_page
        context['pagination_url'] = self.request.get_full_path()
        context['search_type'] = searcher.search_type
        context['search_type_name'] = OclConstants.resource_display_name(searcher.search_type)
        context['search_sort_option_defs'] = searcher.get_sort_option_definitions()
        context['search_sort'] = searcher.get_sort()
        context['search_filters'] = searcher.search_filter_list
        context['search_query'] = original_search_string
        context['hide_nav_search'] = True

        # Build URL params for navigating to other resources
        other_resource_search_params = {}
        for param in OclSearch.TRANSFERRABLE_SEARCH_PARAMS:
            if param in self.request.GET:
                if param == 'q':
                    other_resource_search_params[param] = original_search_string
                else:
                    other_resource_search_params[param] = self.request.GET.get(param)

        # This code encodes the search parameters into a single URL-encoded string
        #    so that it can easily be appended onto URL links on the search page
        context['other_resource_search_params'] = ''
        if other_resource_search_params:
            context['other_resource_search_params'] = (
                '&' + urlencode(other_resource_search_params))

        # Perform the counter searches for the other resources
        resource_count = {}
        for resource_type in OclConstants.RESOURCE_TYPE_INFO:
            if resource_type == searcher.search_type:
                # Primary search has already been performed, so just set value from above
                resource_count[searcher.search_type] = searcher.num_found
            else:
                # Get resource count applying transferrable search criteria
                count_response = api.head(resource_type, params=other_resource_search_params)
                if 'num_found' in count_response.headers:
                    resource_count[resource_type] = int(count_response.headers['num_found'])
                else:
                    resource_count[resource_type] = 0
        context['resource_count'] = resource_count

        # Set debug variables
        context['url_params'] = self.request.GET
        context['search_params'] = searcher.search_params
        context['search_response_headers'] = search_response.headers
        context['search_facets_json'] = searcher.search_facets
        context['search_filters_debug'] = str(searcher.search_filter_list)

        return context
示例#19
0
    def get_context_data(self, *args, **kwargs):
        """ Set context for OCL global search """

        context = super(GlobalSearchView, self).get_context_data(*args, **kwargs)

        # Perform the primary search via the API

        original_search_string = self.request.GET.get('q', '')
        SearchStringFormatter.add_wildcard(self.request)

        searcher = OclSearch(params=self.request.GET)

        api = OclApi(
            self.request, debug=True,
            facets=OclConstants.resource_has_facets(searcher.search_type))

        search_response = api.get(searcher.search_type, params=searcher.search_params)
        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the primary search results
        searcher.process_search_results(
            search_type=searcher.search_type,
            search_response=search_response,
            search_params=self.request.GET)

        # Setup paginator for primary search
        search_paginator = Paginator(range(searcher.num_found), searcher.num_per_page)
        search_current_page = search_paginator.page(searcher.current_page)

        # Set context for primary search
        context['results'] = searcher.search_results
        context['page'] = search_current_page
        context['pagination_url'] = self.request.get_full_path()
        context['search_type'] = searcher.search_type
        context['search_type_name'] = OclConstants.resource_display_name(searcher.search_type)
        context['search_sort_option_defs'] = searcher.get_sort_option_definitions()
        context['search_sort'] = searcher.get_sort()
        context['search_filters'] = searcher.search_filter_list
        context['search_query'] = original_search_string
        context['hide_nav_search'] = True

        # Build URL params for navigating to other resources
        other_resource_search_params = {}
        for param in OclSearch.TRANSFERRABLE_SEARCH_PARAMS:
            if param in self.request.GET:
                if param == 'q':
                    other_resource_search_params[param] = original_search_string
                else:
                    other_resource_search_params[param] = self.request.GET.get(param)

        # This code encodes the search parameters into a single URL-encoded string
        #    so that it can easily be appended onto URL links on the search page
        context['other_resource_search_params'] = ''
        if other_resource_search_params:
            context['other_resource_search_params'] = (
                '&' + urlencode(other_resource_search_params))

        # Perform the counter searches for the other resources
        resource_count = {}
        for resource_type in OclConstants.RESOURCE_TYPE_INFO:
            if resource_type == searcher.search_type:
                # Primary search has already been performed, so just set value from above
                resource_count[searcher.search_type] = searcher.num_found
            elif OclConstants.RESOURCE_TYPE_INFO[resource_type]['show_on_global_search']:
                # Get resource count applying transferrable search criteria
                count_response = api.head(resource_type, params=other_resource_search_params)
                if 'num_found' in count_response.headers:
                    resource_count[resource_type] = int(count_response.headers['num_found'])
                else:
                    resource_count[resource_type] = 0
        context['resource_count'] = resource_count

        # Set debug variables
        context['url_params'] = self.request.GET
        context['search_params'] = searcher.search_params
        context['search_response_headers'] = search_response.headers
        context['search_facets_json'] = searcher.search_facets
        context['search_filters_debug'] = str(searcher.search_filter_list)

        return context
示例#20
0
    def get_context_data(self, *args, **kwargs):
        """ Set context for OCL global search_type """

        context = super(GlobalSearchView,
                        self).get_context_data(*args, **kwargs)

        # Perform the primary search via the API

        search_string = self.request.GET.get('q', '')
        SearchStringFormatter.add_wildcard(self.request)

        searcher = OclSearch(params=self.request.GET)

        api = OclApi(self.request,
                     debug=True,
                     facets=OclConstants.resource_has_facets(
                         searcher.search_type))

        search_response = api.get(searcher.search_type,
                                  params=searcher.search_params)
        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the primary search results
        searcher.process_search_results(search_type=searcher.search_type,
                                        search_response=search_response,
                                        search_params=self.request.GET)

        # Setup paginator for primary search
        search_paginator = Paginator(range(searcher.num_found),
                                     searcher.num_per_page)
        search_current_page = search_paginator.page(searcher.current_page)

        # Set context for primary search
        context['results'] = searcher.search_results
        context['page'] = search_current_page
        context['pagination_url'] = self.request.get_full_path()
        context['search_type'] = searcher.search_type
        context['search_type_name'] = OclConstants.resource_display_name(
            searcher.search_type)
        context['search_sort_options'] = searcher.get_sort_options()
        context['search_sort'] = searcher.get_sort()
        context['search_filters'] = searcher.search_filter_list
        context['search_query'] = search_string

        # Build URL params for navigating to other resources
        other_resource_search_params = {}
        for param in OclSearch.TRANSFERRABLE_SEARCH_PARAMS:
            if param in self.request.GET:
                other_resource_search_params[param] = self.request.GET.get(
                    param)

        context['other_resource_search_params'] = ''

        # Following code breaks for unicode characters -- couldn't figure out why this code is here -- Sny/Anshu
        if other_resource_search_params:
            context['other_resource_search_params'] = (
                '&' + urlencode(other_resource_search_params))
        #
        # Perform the counter searches for the other resources
        resource_count = {}
        for resource_type in OclConstants.RESOURCE_TYPE_INFO:
            if resource_type == searcher.search_type:
                # Primary search has already been performed, so just set value from above
                resource_count[searcher.search_type] = searcher.num_found
            else:
                # Get resource count applying transferrable search criteria
                count_response = api.head(resource_type,
                                          params=other_resource_search_params)
                if 'num_found' in count_response.headers:
                    resource_count[resource_type] = int(
                        count_response.headers['num_found'])
                else:
                    resource_count[resource_type] = 0
        context['resource_count'] = resource_count

        # Set debug variables
        context['url_params'] = self.request.GET
        context['search_params'] = searcher.search_params
        context['search_response_headers'] = search_response.headers
        context['search_facets_json'] = searcher.search_facets
        context['search_filters_debug'] = str(searcher.search_filter_list)

        # Set to remove closing form tag in nav.html -- retire in the future
        context['extend_nav_form'] = True

        return context
示例#21
0
    def get_context_data(self, *args, **kwargs):
        """ Set context for OCL global search_type """

        context = super(GlobalSearchView, self).get_context_data(*args, **kwargs)

        # Perform the primary search via the API
        searcher = OclSearch(params=self.request.GET)
        api = OclApi(self.request, debug=True,
                     facets=OclConstants.resource_has_facets(searcher.search_type))
        search_response = api.get(searcher.search_type, params=searcher.search_params)
        if search_response.status_code == 404:
            raise Http404
        elif search_response.status_code != 200:
            search_response.raise_for_status()

        # Process the primary search results
        searcher.process_search_results(
            search_type=searcher.search_type, search_response=search_response,
            search_params=self.request.GET)

        # Setup paginator for primary search
        search_paginator = Paginator(range(searcher.num_found), searcher.num_per_page)
        search_current_page = search_paginator.page(searcher.current_page)

        # Set context for primary search
        context['results'] = searcher.search_results
        context['page'] = search_current_page
        context['pagination_url'] = self.request.get_full_path()
        context['search_type'] = searcher.search_type
        context['search_type_name'] = OclConstants.resource_display_name(searcher.search_type)
        context['search_sort_options'] = searcher.get_sort_options()
        context['search_sort'] = searcher.get_sort()
        context['search_filters'] = searcher.search_filter_list

        # Build URL params for navigating to other resources
        other_resource_search_params = {}
        for param in OclSearch.TRANSFERRABLE_SEARCH_PARAMS:
            if param in self.request.GET:
                other_resource_search_params[param] = self.request.GET.get(param)
        context['other_resource_search_params'] = ''
        if other_resource_search_params:
            context['other_resource_search_params'] = (
                '&' + urllib.urlencode(other_resource_search_params))

        # Perform the counter searches for the other resources
        resource_count = {}
        for resource_type in OclConstants.RESOURCE_TYPE_INFO:
            if resource_type == searcher.search_type:
                # Primary search has already been performed, so just set value from above
                resource_count[searcher.search_type] = searcher.num_found
            else:
                # Get resource count applying transferrable search criteria
                count_response = api.head(resource_type, params=other_resource_search_params)
                if 'num_found' in count_response.headers:
                    resource_count[resource_type] = int(count_response.headers['num_found'])
                else:
                    resource_count[resource_type] = 0
        context['resource_count'] = resource_count

        # Set debug variables
        context['url_params'] = self.request.GET
        context['search_params'] = searcher.search_params
        context['search_response_headers'] = search_response.headers
        context['search_facets_json'] = searcher.search_facets
        context['search_filters_debug'] = str(searcher.search_filter_list)

        # Set to remove closing form tag in nav.html -- retire in the future
        context['extend_nav_form'] = True

        return context