Ejemplo n.º 1
0
    def get_context_data(self, *args, **kwargs):
        """
        Loads the mapping details.
        """
        # Setup the context and args
        context = super(MappingDetailsView,
                        self).get_context_data(*args, **kwargs)
        self.get_args()

        # Load the mapping details
        if self.mapping_version_id:
            mapping = self.get_mapping_details(
                self.owner_type,
                self.owner_id,
                self.source_id,
                self.mapping_id,
                mapping_version_id=self.mapping_version_id)
        else:
            mapping = self.get_mapping_details(self.owner_type, self.owner_id,
                                               self.source_id, self.mapping_id)

        # Set the context
        context['kwargs'] = self.kwargs
        context['url_params'] = self.request.GET
        context['selected_tab'] = 'Details'
        context['mapping'] = mapping

        if self.request.user.is_authenticated():
            api = OclApi(self.request, debug=True, facets=True)
            context['all_collections'] = api.get_all_collections_for_user(
                self.request.user.username)

        return context
Ejemplo n.º 2
0
    def get_context_data(self, *args, **kwargs):
        """
        Loads the concept details and its version history.
        """

        # Setup the context and args
        context = super(ConceptHistoryView, self).get_context_data(*args, **kwargs)
        self.get_args()

        api = OclApi(self.request, debug=True, facets=True)

        # Load the concept details
        concept = self.get_concept_details(
            self.owner_type, self.owner_id, self.source_id, self.concept_id,
            source_version_id=self.source_version_id, concept_version_id=self.concept_version_id)

        # Load the concept version history
        searcher = self.get_concept_history(
            self.owner_type, self.owner_id, self.source_id, self.concept_id)
        # search_results_paginator = Paginator(range(searcher.num_found), searcher.num_per_page)
        # search_results_current_page = search_results_paginator.page(searcher.current_page)

        if self.request.user.is_authenticated():
            context['all_collections'] = api.get_all_collections_for_user(self.request.user.username)

        # Set the context
        context['kwargs'] = self.kwargs
        context['url_params'] = self.request.GET
        context['selected_tab'] = 'History'
        context['concept'] = concept
        context['concept_versions'] = searcher.search_results
        # context['current_page'] = search_results_current_page
        # context['pagination_url'] = self.request.get_full_path()

        return context
Ejemplo n.º 3
0
    def get_context_data(self, *args, **kwargs):
        """
        Loads the concept details.
        """

        # Setup the context and args
        context = super(ConceptDetailsView, self).get_context_data(*args, **kwargs)
        self.get_args()

        api = OclApi(self.request, debug=True, facets=True)

        # Load the concept details
        concept = self.get_concept_details(
            self.owner_type, self.owner_id, self.source_id, self.concept_id,
            source_version_id=self.source_version_id, concept_version_id=self.concept_version_id)

        if self.request.user.is_authenticated():
            context['all_collections'] = api.get_all_collections_for_user(self.request.user.username)

        # Set the context
        context['kwargs'] = self.kwargs
        context['url_params'] = self.request.GET
        context['selected_tab'] = 'Details'
        context['concept'] = concept

        return context
Ejemplo n.º 4
0
    def get_context_data(self, *args, **kwargs):
        """
        Loads the mapping details.
        """

        # Setup the context and args
        context = super(MappingVersionsView, self).get_context_data(*args, **kwargs)
        self.get_args()

        # Load the mapping details
        if self.mapping_version_id:
            mapping = self.get_mapping_details(
                self.owner_type, self.owner_id, self.source_id, self.mapping_id,
                mapping_version_id=self.mapping_version_id)
        else:
            mapping = self.get_mapping_details(
                self.owner_type, self.owner_id, self.source_id, self.mapping_id)

        searcher = self.get_mapping_versions(
            self.owner_type, self.owner_id, self.source_id, self.mapping_id, search_params={'limit': '0'})

        # Set the context
        context['kwargs'] = self.kwargs
        context['url_params'] = self.request.GET
        context['selected_tab'] = 'History'
        context['mapping'] = mapping
        context['mapping_versions'] = searcher.search_results

        if self.request.user.is_authenticated():
            api = OclApi(self.request, debug=True, facets=True)
            context['all_collections'] = api.get_all_collections_for_user(self.request.user.username)

        return context
Ejemplo n.º 5
0
    def get_context_data(self, *args, **kwargs):
        """
        Loads the concept details and its version history.
        """

        # Setup the context and args
        context = super(ConceptHistoryView, self).get_context_data(*args, **kwargs)
        self.get_args()

        api = OclApi(self.request, debug=True, facets=True)

        # Load the concept details
        concept = self.get_concept_details(
            self.owner_type, self.owner_id, self.source_id, self.concept_id,
            source_version_id=self.source_version_id, concept_version_id=self.concept_version_id)

        # Load the concept version history
        searcher = self.get_concept_history(
            self.owner_type, self.owner_id, self.source_id, self.concept_id)
        # search_results_paginator = Paginator(range(searcher.num_found), searcher.num_per_page)
        # search_results_current_page = search_results_paginator.page(searcher.current_page)

        if self.request.user.is_authenticated():
            context['all_collections'] = api.get_all_collections_for_user(self.request.user.username)

        # Set the context
        context['kwargs'] = self.kwargs
        context['url_params'] = self.request.GET
        context['selected_tab'] = 'History'
        context['concept'] = concept
        context['concept_versions'] = searcher.search_results
        # context['current_page'] = search_results_current_page
        # context['pagination_url'] = self.request.get_full_path()

        return context
Ejemplo n.º 6
0
    def get_context_data(self, *args, **kwargs):
        """
        Loads the concept details.
        """

        # Setup the context and args
        context = super(ConceptDetailsView, self).get_context_data(*args, **kwargs)
        self.get_args()

        api = OclApi(self.request, debug=True, facets=True)

        # Load the concept details
        concept = self.get_concept_details(
            self.owner_type, self.owner_id, self.source_id, self.concept_id,
            source_version_id=self.source_version_id, concept_version_id=self.concept_version_id,
            include_mappings=True, include_inverse_mappings=True)

        concept['has_direct_mappings'] = False
        concept['has_inverse_mappings'] = False
        if 'mappings' in concept and concept['mappings']:
            for mapping in concept['mappings']:
                if (self.proper_owner_type == mapping['to_source_owner_type'] and
                        self.owner_id == mapping['to_source_owner'] and
                        self.source_id == mapping['to_source_name'] and
                        self.concept_id == mapping['to_concept_code']):
                    mapping['is_inverse_mapping'] = True
                    concept['has_inverse_mappings'] = True
                    mapping['is_direct_mapping'] = False
                else:
                    mapping['is_direct_mapping'] = True
                    mapping['is_inverse_mapping'] = False
                    concept['has_direct_mappings'] = True
                if mapping['to_concept_url']:
                    mapping['is_internal_mapping'] = True
                    mapping['is_external_mapping'] = False
                else:
                    mapping['is_internal_mapping'] = False
                    mapping['is_external_mapping'] = True

        if self.request.user.is_authenticated():
            context['all_collections'] = api.get_all_collections_for_user(self.request.user.username)

        # Set the context
        context['kwargs'] = self.kwargs
        context['url_params'] = self.request.GET
        context['selected_tab'] = 'Details'
        context['concept'] = concept

        return context
Ejemplo n.º 7
0
    def get_context_data(self, *args, **kwargs):
        """
        Loads the mapping details.
        """

        # Setup the context and args
        context = super(MappingVersionsView,
                        self).get_context_data(*args, **kwargs)
        self.get_args()

        # Load the mapping details
        if self.mapping_version_id:
            mapping = self.get_mapping_details(
                self.owner_type,
                self.owner_id,
                self.source_id,
                self.mapping_id,
                mapping_version_id=self.mapping_version_id)
        else:
            mapping = self.get_mapping_details(self.owner_type, self.owner_id,
                                               self.source_id, self.mapping_id)

        searcher = self.get_mapping_versions(self.owner_type,
                                             self.owner_id,
                                             self.source_id,
                                             self.mapping_id,
                                             search_params={'limit': '0'})

        # Set the context
        context['kwargs'] = self.kwargs
        context['url_params'] = self.request.GET
        context['selected_tab'] = 'History'
        context['mapping'] = mapping
        context['mapping_versions'] = searcher.search_results

        if self.request.user.is_authenticated():
            api = OclApi(self.request, debug=True, facets=True)
            context['all_collections'] = api.get_all_collections_for_user(
                self.request.user.username)

        all_sources = _get_org_or_user_sources_list2(self.request,
                                                     str(self.request.user))
        context['all_sources'] = all_sources

        return context
Ejemplo n.º 8
0
    def get_context_data(self, *args, **kwargs):
        """ Loads the mappings that are in the source. """

        # Setup the context and args
        context = super(SourceMappingsView, self).get_context_data(*args, **kwargs)
        self.get_args()
        api = OclApi(self.request, debug=True, facets=True)

        # Load the source details
        source = self.get_source_details(
            self.owner_type, self.owner_id, self.source_id,
            source_version_id=self.source_version_id)

        # Load the mappings in this source, applying search parameters
        original_search_string = self.request.GET.get('q', '')
        # TODO: SearchStringFormatter.add_wildcard(self.request)
        searcher = self.get_source_mappings(
            self.owner_type, self.owner_id, self.source_id,
            source_version_id=self.source_version_id,
            search_params=self.request.GET)
        search_results_paginator = Paginator(range(searcher.num_found), searcher.num_per_page)
        search_results_current_page = search_results_paginator.page(searcher.current_page)

        # Load the source versions
        source_version_searcher = self.get_source_versions(
            self.owner_type, self.owner_id, self.source_id,
            search_params={'limit': '0'})

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

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

        # Set the context
        context['kwargs'] = self.kwargs
        context['source'] = source
        context['source_version'] = self.source_version_id
        context['source_versions'] = source_version_searcher.search_results
        context['selected_tab'] = 'Mappings'
        context['results'] = searcher.search_results
        context['current_page'] = search_results_current_page
        context['pagination_url'] = self.request.get_full_path()
        context['search_sort_option_defs'] = searcher.get_sort_option_definitions()
        context['search_sort'] = searcher.get_sort()
        context['search_query'] = original_search_string
        context['search_filters'] = searcher.search_filter_list

        if self.request.user.is_authenticated():
            context['all_collections'] = api.get_all_collections_for_user(self.request.user.username)

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

        return context
Ejemplo n.º 9
0
    def get_context_data(self, *args, **kwargs):
        """ Loads the concepts that are in the collection. """

        # Setup the context and args
        context = super(CollectionConceptsView,
                        self).get_context_data(*args, **kwargs)
        self.get_args()
        api = OclApi(self.request, debug=True)
        results = api.get(self.owner_type, self.owner_id, 'collections',
                          self.collection_id)
        collection = results.json()
        params = self.request.GET.copy()
        params['verbose'] = 'true'
        params['limit'] = '10'

        # to fetch all , set limit to 0
        versions = self.get_collection_versions(self.owner_type,
                                                self.owner_id,
                                                self.collection_id,
                                                search_params={'limit': '0'})

        # Load the concepts in this collection, applying search parameters
        original_search_string = self.request.GET.get('q', '')
        # TODO: SearchStringFormatter.add_wildcard(self.request)
        params = self.request.GET.copy()
        params['verbose'] = 'true'
        params['limit'] = '10'
        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=params)

        search_results_paginator = Paginator(range(searcher.num_found),
                                             searcher.num_per_page)
        search_results_current_page = search_results_paginator.page(
            searcher.current_page)

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

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

        # Set the context
        context['kwargs'] = self.kwargs
        context['selected_tab'] = 'Concepts'
        context['collection'] = collection
        context['collection_version'] = self.collection_version_id
        context['collection_versions'] = versions.search_results
        context['selected_tab'] = 'Concepts'
        context['results'] = searcher.search_results
        context['current_page'] = search_results_current_page
        context['pagination_url'] = self.request.get_full_path()
        context['search_sort_option_defs'] = searcher.get_sort_options()
        context['search_sort'] = searcher.get_sort()
        context['search_query'] = self.search_string if hasattr(
            self, 'search_string') else ''
        context['search_filters'] = searcher.search_filter_list
        context['search_sort_options'] = searcher.get_sort_options()
        context['search_sort'] = searcher.get_sort()
        context['search_facets_json'] = searcher.search_facets
        context['search_filters_debug'] = str(searcher.search_filter_list)
        context['collection_versions'] = versions.search_results

        if self.request.user.is_authenticated():
            context['all_collections'] = api.get_all_collections_for_user(
                self.request.user.username)

        return context
Ejemplo n.º 10
0
    def get_context_data(self, *args, **kwargs):
        """ Loads the mappings that are in the source. """

        # Setup the context and args
        context = super(SourceMappingsView, self).get_context_data(*args, **kwargs)
        self.get_args()
        api = OclApi(self.request, debug=True, facets=True)

        # Load the source details
        source = self.get_source_details(
            self.owner_type, self.owner_id, self.source_id,
            source_version_id=self.source_version_id)

        # Load the mappings in this source, applying search parameters
        original_search_string = self.request.GET.get('q', '')
        # TODO: SearchStringFormatter.add_wildcard(self.request)
        searcher = self.get_source_mappings(
            self.owner_type, self.owner_id, self.source_id,
            source_version_id=self.source_version_id,
            search_params=self.request.GET)
        search_results_paginator = Paginator(range(searcher.num_found), searcher.num_per_page)
        search_results_current_page = search_results_paginator.page(searcher.current_page)

        # Load the source versions
        source_version_searcher = self.get_source_versions(
            self.owner_type, self.owner_id, self.source_id,
            search_params={'limit': '0'})

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

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

        # Set the context
        context['kwargs'] = self.kwargs
        context['source'] = source
        context['source_version'] = self.source_version_id
        context['source_versions'] = source_version_searcher.search_results
        context['selected_tab'] = 'Mappings'
        context['results'] = searcher.search_results
        context['current_page'] = search_results_current_page
        context['pagination_url'] = self.request.get_full_path()
        context['search_sort_option_defs'] = searcher.get_sort_option_definitions()
        context['search_sort'] = searcher.get_sort()
        context['search_query'] = original_search_string
        context['search_filters'] = searcher.search_filter_list

        if self.request.user.is_authenticated():
            context['all_collections'] = api.get_all_collections_for_user(self.request.user.username)

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

        return context
Ejemplo n.º 11
0
    def get_context_data(self, *args, **kwargs):
        """ Loads the concept details. """

        # Setup the context and args
        context = super(ConceptMappingsView, self).get_context_data(*args, **kwargs)
        self.get_args()

        api = OclApi(self.request, debug=True, facets=True)

        # Load the concept details
        concept = self.get_concept_details(
            self.owner_type, self.owner_id, self.source_id, self.concept_id,
            source_version_id=self.source_version_id, concept_version_id=self.concept_version_id,
            include_mappings=True, include_inverse_mappings=True)

        # Process mappings relative to current concept
        # TODO([email protected]): Move processing code to concept/mapping class objects
        mappings = {
            'Direct Internal Mapping': [],
            'Direct External Mapping': [],
            'Inverse Mapping': [],
            'Linked Answer': [],
            'Linked Question': [],
            'Set Member': [],
            'Set Parent': [],
            'Other': [],
        }
        if 'mappings' in concept and concept['mappings']:
            for mapping in concept['mappings']:
                mapping['is_direct_mapping'] = False
                mapping['is_inverse_mapping'] = False
                mapping['is_internal_mapping'] = False
                mapping['is_external_mapping'] = False
                mapping['mapping_category'] = None
                mapping['to_url'] = None
                mapping['from_url'] = None
                mapping['mapping_url'] = None

                # TODO: Set the mapping_url
                mapping_url_args = {}
                if mapping['owner_type'] == 'Organization':
                    mapping_url_args['org'] = mapping['owner']
                else:
                    mapping_url_args['user'] = mapping['owner']
                mapping_url_args['source'] = mapping['source']
                mapping_url_args['mapping'] = mapping['id']
                mapping['mapping_url'] = reverse('mapping-home', kwargs=mapping_url_args)

                # this concept == from_concept
                if (self.proper_owner_type == mapping['from_source_owner_type'] and
                            self.owner_id == mapping['from_source_owner'] and
                            self.source_id == mapping['from_source_name'] and
                            self.concept_id == mapping['from_concept_code']):

                    # Setup the arguments to reverse to_concept URL - URL reversed in next block
                    to_concept_url_args = {}
                    if mapping['to_source_owner_type'] == 'Organization':
                        to_concept_url_args['org'] = mapping['to_source_owner']
                    else:
                        to_concept_url_args['user'] = mapping['to_source_owner']
                    to_concept_url_args['source'] = mapping['to_source_name']

                    # Set mapping attributes relative to the current concept
                    mapping['is_direct_mapping'] = True
                    if mapping['to_concept_url']:
                        mapping['is_internal_mapping'] = True
                        to_concept_url_args['concept'] = mapping['to_concept_code']
                        mapping['to_url'] = reverse('concept-home', kwargs=to_concept_url_args)
                    else:
                        mapping['is_external_mapping'] = True
                        mapping['to_url'] = reverse('source-home', kwargs=to_concept_url_args)

                    # Determine the mapping category relative to current concept
                    if mapping['map_type'] == 'Q-AND-A':
                        mapping['mapping_category'] = 'Linked Answer'
                        mappings['Linked Answer'].append(mapping)
                    elif mapping['map_type'] == 'CONCEPT-SET':
                        mapping['mapping_category'] = 'Set Member'
                        mappings['Set Member'].append(mapping)
                    elif mapping['to_concept_url']:
                        mapping['mapping_category'] = 'Direct Internal Mapping'
                        mappings['Direct Internal Mapping'].append(mapping)
                    else:
                        mapping['mapping_category'] = 'Direct External Mapping'
                        mappings['Direct External Mapping'].append(mapping)

                # this concept == to_concept (internal mapping)
                elif (self.proper_owner_type == mapping['to_source_owner_type'] and
                              self.owner_id == mapping['to_source_owner'] and
                              self.source_id == mapping['to_source_name'] and
                              self.concept_id == mapping['to_concept_code']):

                    # Setup the arguments to reverse from_concept URL - which must be in OCL
                    from_concept_url_args = {}
                    if mapping['from_source_owner_type'] == 'Organization':
                        from_concept_url_args['org'] = mapping['from_source_owner']
                    else:
                        from_concept_url_args['user'] = mapping['from_source_owner']
                    from_concept_url_args['source'] = mapping['from_source_name']
                    from_concept_url_args['concept'] = mapping['from_concept_code']
                    mapping['from_url'] = reverse('concept-home', kwargs=from_concept_url_args)

                    # Set mapping attributes relative to the current concept
                    mapping['is_inverse_mapping'] = True
                    mapping['is_internal_mapping'] = True

                    # Determine the mapping category
                    if mapping['map_type'] == 'Q-AND-A':
                        mapping['mapping_category'] = 'Linked Question'
                        mappings['Linked Question'].append(mapping)
                    elif mapping['map_type'] == 'CONCEPT-SET':
                        mapping['mapping_category'] = 'Set Parent'
                        mappings['Set Parent'].append(mapping)
                    else:
                        mapping['mapping_category'] = 'Inverse Mapping'
                        mappings['Inverse Mapping'].append(mapping)

                # this concept != from_concept or to_concept! something's wrong
                else:
                    mapping['mapping_category'] = 'Other'
                    mappings['Other'].append(mapping)

        if self.request.user.is_authenticated():
            context['all_collections'] = api.get_all_collections_for_user(self.request.user.username)

        # Set the context
        context['kwargs'] = self.kwargs
        context['url_params'] = self.request.GET
        context['selected_tab'] = 'Mappings'
        context['concept'] = concept
        context['mappings'] = mappings
        context['form'] = ConceptNewMappingForm()
        context['map_types'] = _get_map_type_list()

        return context
Ejemplo n.º 12
0
    def get_context_data(self, *args, **kwargs):
        """ Loads the concept details. """

        # Setup the context and args
        context = super(ConceptMappingsView, self).get_context_data(*args, **kwargs)
        self.get_args()

        api = OclApi(self.request, debug=True, facets=True)

        # Load the concept details
        concept = self.get_concept_details(
            self.owner_type, self.owner_id, self.source_id, self.concept_id,
            source_version_id=self.source_version_id, concept_version_id=self.concept_version_id,
            include_mappings=True, include_inverse_mappings=True)

        # Process mappings relative to current concept
        # TODO([email protected]): Move processing code to concept/mapping class objects
        mappings = {
            'Direct Internal Mapping': [],
            'Direct External Mapping': [],
            'Inverse Mapping': [],
            'Linked Answer': [],
            'Linked Question': [],
            'Set Member': [],
            'Set Parent': [],
            'Other': [],
        }
        if 'mappings' in concept and concept['mappings']:
            for mapping in concept['mappings']:
                mapping['is_direct_mapping'] = False
                mapping['is_inverse_mapping'] = False
                mapping['is_internal_mapping'] = False
                mapping['is_external_mapping'] = False
                mapping['mapping_category'] = None
                mapping['to_url'] = None
                mapping['from_url'] = None
                mapping['mapping_url'] = None

                # TODO: Set the mapping_url
                mapping_url_args = {}
                if mapping['owner_type'] == 'Organization':
                    mapping_url_args['org'] = mapping['owner']
                else:
                    mapping_url_args['user'] = mapping['owner']
                mapping_url_args['source'] = mapping['source']
                mapping_url_args['mapping'] = mapping['id']
                mapping['mapping_url'] = reverse('mapping-home', kwargs=mapping_url_args)

                # this concept == from_concept
                if (self.proper_owner_type == mapping['from_source_owner_type'] and
                            self.owner_id == mapping['from_source_owner'] and
                            self.source_id == mapping['from_source_name'] and
                            self.concept_id == mapping['from_concept_code']):

                    # Setup the arguments to reverse to_concept URL - URL reversed in next block
                    to_concept_url_args = {}
                    if mapping['to_source_owner_type'] == 'Organization':
                        to_concept_url_args['org'] = mapping['to_source_owner']
                    else:
                        to_concept_url_args['user'] = mapping['to_source_owner']
                    to_concept_url_args['source'] = mapping['to_source_name']

                    # Set mapping attributes relative to the current concept
                    mapping['is_direct_mapping'] = True
                    if mapping['to_concept_url']:
                        mapping['is_internal_mapping'] = True
                        to_concept_url_args['concept'] = mapping['to_concept_code']
                        mapping['to_url'] = reverse('concept-home', kwargs=to_concept_url_args)
                    else:
                        mapping['is_external_mapping'] = True
                        mapping['to_url'] = reverse('source-home', kwargs=to_concept_url_args)

                    # Determine the mapping category relative to current concept
                    if mapping['map_type'] == 'Q-AND-A':
                        mapping['mapping_category'] = 'Linked Answer'
                        mappings['Linked Answer'].append(mapping)
                    elif mapping['map_type'] == 'CONCEPT-SET':
                        mapping['mapping_category'] = 'Set Member'
                        mappings['Set Member'].append(mapping)
                    elif mapping['to_concept_url']:
                        mapping['mapping_category'] = 'Direct Internal Mapping'
                        mappings['Direct Internal Mapping'].append(mapping)
                    else:
                        mapping['mapping_category'] = 'Direct External Mapping'
                        mappings['Direct External Mapping'].append(mapping)

                # this concept == to_concept (internal mapping)
                elif (self.proper_owner_type == mapping['to_source_owner_type'] and
                              self.owner_id == mapping['to_source_owner'] and
                              self.source_id == mapping['to_source_name'] and
                              self.concept_id == mapping['to_concept_code']):

                    # Setup the arguments to reverse from_concept URL - which must be in OCL
                    from_concept_url_args = {}
                    if mapping['from_source_owner_type'] == 'Organization':
                        from_concept_url_args['org'] = mapping['from_source_owner']
                    else:
                        from_concept_url_args['user'] = mapping['from_source_owner']
                    from_concept_url_args['source'] = mapping['from_source_name']
                    from_concept_url_args['concept'] = mapping['from_concept_code']
                    mapping['from_url'] = reverse('concept-home', kwargs=from_concept_url_args)

                    # Set mapping attributes relative to the current concept
                    mapping['is_inverse_mapping'] = True
                    mapping['is_internal_mapping'] = True

                    # Determine the mapping category
                    if mapping['map_type'] == 'Q-AND-A':
                        mapping['mapping_category'] = 'Linked Question'
                        mappings['Linked Question'].append(mapping)
                    elif mapping['map_type'] == 'CONCEPT-SET':
                        mapping['mapping_category'] = 'Set Parent'
                        mappings['Set Parent'].append(mapping)
                    else:
                        mapping['mapping_category'] = 'Inverse Mapping'
                        mappings['Inverse Mapping'].append(mapping)

                # this concept != from_concept or to_concept! something's wrong
                else:
                    mapping['mapping_category'] = 'Other'
                    mappings['Other'].append(mapping)

        if self.request.user.is_authenticated():
            context['all_collections'] = api.get_all_collections_for_user(self.request.user.username)

        # Set the context
        context['kwargs'] = self.kwargs
        context['url_params'] = self.request.GET
        context['selected_tab'] = 'Mappings'
        context['concept'] = concept
        context['mappings'] = mappings
        context['form'] = ConceptNewMappingForm()
        context['map_types'] = _get_map_type_list()

        return context
Ejemplo n.º 13
0
    def get_context_data(self, *args, **kwargs):
        """ Loads the concepts that are in the collection. """

        # Setup the context and args
        context = super(CollectionConceptsView, self).get_context_data(*args, **kwargs)
        self.get_args()
        api = OclApi(self.request, debug=True)
        results = api.get(self.owner_type, self.owner_id, 'collections', self.collection_id)
        collection = results.json()
        params = self.request.GET.copy()
        params['verbose'] = 'true'
        params['limit'] = '10'

        # to fetch all , set limit to 0
        versions = self.get_collection_versions(
            self.owner_type, self.owner_id, self.collection_id,
            search_params={'limit': '0'})

        # Load the concepts in this collection, applying search parameters
        original_search_string = self.request.GET.get('q', '')
        # TODO: SearchStringFormatter.add_wildcard(self.request)
        params = self.request.GET.copy()
        params['verbose'] = 'true'
        params['limit'] = '10'
        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=params)

        search_results_paginator = Paginator(range(searcher.num_found), searcher.num_per_page)
        search_results_current_page = search_results_paginator.page(searcher.current_page)

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

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

        # Set the context
        context['kwargs'] = self.kwargs
        context['selected_tab'] = 'Concepts'
        context['collection'] = collection
        context['collection_version'] = self.collection_version_id
        context['collection_versions'] = versions.search_results
        context['selected_tab'] = 'Concepts'
        context['results'] = searcher.search_results
        context['current_page'] = search_results_current_page
        context['pagination_url'] = self.request.get_full_path()
        context['search_sort_option_defs'] = searcher.get_sort_options()
        context['search_sort'] = searcher.get_sort()
        context['search_query'] = self.search_string if hasattr(self, 'search_string') else ''
        context['search_filters'] = searcher.search_filter_list
        context['search_sort_options'] = searcher.get_sort_options()
        context['search_sort'] = searcher.get_sort()
        context['search_facets_json'] = searcher.search_facets
        context['search_filters_debug'] = str(searcher.search_filter_list)
        context['collection_versions'] = versions.search_results

        if self.request.user.is_authenticated():
            context['all_collections'] = api.get_all_collections_for_user(self.request.user.username)

        return context
Ejemplo n.º 14
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_type_icon'] = OclConstants.resource_display_icon(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

        if self.request.user.is_authenticated() and searcher.search_type in ['concepts', 'mappings']:
            context['all_collections'] = api.get_all_collections_for_user(self.request.user.username)

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

        # Encode 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