Exemplo n.º 1
0
    def get(self, request, *args, **kwargs):
        self.search_string = request.GET.get('q', '')
        SearchStringFormatter.add_wildcard(request)

        if request.is_ajax():
            self.get_args()
            api = OclApi(self.request, debug=True, facets=True)
            # Load the concepts in this source, applying search parameters
            searcher = self.get_source_concepts(
                api, self.owner_type, self.owner_id, self.source_id,
                source_version_id=self.source_version_id,
                search_params=self.request.GET
            )

            response = {
                'items': searcher.search_results,
                'per_page': searcher.num_per_page,
                'total': searcher.num_found,
            }

            return HttpResponse(
                json.dumps(response),
                content_type="application/json"
            )
        return super(SourceConceptsView, self).get(self, *args, **kwargs)
Exemplo n.º 2
0
    def get(self, request, *args, **kwargs):
        self.search_string = request.GET.get('q', '')
        SearchStringFormatter.add_wildcard(request)

        if request.is_ajax():
            self.get_args()
            api = OclApi(self.request, debug=True, facets=True)
            # Load the concepts in this source, applying search parameters
            searcher = self.get_source_concepts(
                api, self.owner_type, self.owner_id, self.source_id,
                source_version_id=self.source_version_id,
                search_params=self.request.GET
            )

            response = {
                'items': searcher.search_results,
                'per_page': searcher.num_per_page,
                'total': searcher.num_found,
            }

            return HttpResponse(
                json.dumps(response),
                content_type="application/json"
            )
        return super(SourceConceptsView, self).get(self, *args, **kwargs)
Exemplo n.º 3
0
    def get(self, request, *args, **kwargs):
        self.search_string = request.GET.get('q', '')
        SearchStringFormatter.add_wildcard(request)

        if request.is_ajax():
            self.get_args()
            # Load the concepts in this collection, applying search parameters
            searcher = self.get_collection_data(
                self.owner_type, self.owner_id, self.collection_id,
                OclConstants.RESOURCE_NAME_CONCEPTS,
                collection_version_id=self.collection_version_id,
                search_params=self.request.GET
            )

            response = {
                'items': searcher.search_results,
                'per_page': searcher.num_per_page,
                'total': searcher.num_found,
            }

            return HttpResponse(
                json.dumps(response),
                content_type="application/json"
            )
        return super(CollectionConceptsView, self).get(self, *args, **kwargs)
Exemplo n.º 4
0
    def get(self, request, *args, **kwargs):
        self.search_string = request.GET.get('q', '')
        SearchStringFormatter.add_wildcard(request)

        if request.is_ajax():
            api = OclApi(self.request, debug=True)
            result = api.get('orgs', kwargs.get("org"), "sources", params={'limit':'0'})
            return HttpResponse(json.dumps(result.json()), content_type="application/json")
        return super(OrganizationSourcesView, self).get(self, *args, **kwargs)
Exemplo n.º 5
0
    def test_add_wildcard_without_query_string(self):
        query_dict = QueryDict('', mutable=True)
        query_dict.update(**{'exact_match': False})
        query_dict._mutable = False
        request = FakeRequest(query_dict)

        SearchStringFormatter.add_wildcard(request)

        self.assertTrue('q' not in request.GET)
Exemplo n.º 6
0
    def test_add_wildcard_with_empty_query_string(self):
        query_dict = QueryDict('', mutable=True)
        query_dict.update(**{'q': '', 'exact_match': False})
        query_dict._mutable = False
        request = FakeRequest(query_dict)

        SearchStringFormatter.add_wildcard(request)

        self.assertEquals(request.GET['q'], '')
Exemplo n.º 7
0
    def test_add_wildcard_without_exact_match(self):
        query_dict = QueryDict('', mutable=True)
        query_dict.update(**{'q': 'some search phrase', 'exact_match': False})
        query_dict._mutable = False
        request = FakeRequest(query_dict)

        SearchStringFormatter.add_wildcard(request)

        self.assertEquals(request.GET['q'], 'some* search* phrase*')
Exemplo n.º 8
0
    def get(self, request, *args, **kwargs):
        self.search_string = request.GET.get('q', '')
        SearchStringFormatter.add_wildcard(request)

        if request.is_ajax():
            api = OclApi(self.request, debug=True)
            result = api.get('orgs',
                             kwargs.get("org"),
                             "sources",
                             params={'limit': '0'})
            return HttpResponse(json.dumps(result.json()),
                                content_type="application/json")
        return super(OrganizationSourcesView, self).get(self, *args, **kwargs)
Exemplo n.º 9
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
Exemplo n.º 10
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
Exemplo n.º 11
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
            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