Ejemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     super(MappingNewForm, self).__init__(*args, **kwargs)
     # create widgets here to delay calls to api until initialization of the form
     self.fields['map_type'].widget = ComboBoxWidget(data_list=[
         (t) for t in _get_map_type_list()
     ],
                                                     name="map_type_list")
Ejemplo n.º 2
0
    def get_context_data(self, *args, **kwargs):
        """ Loads the mapping details. """

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

        # Set the context
        context['kwargs'] = self.kwargs
        context['source'] = self.source
        context['mapping'] = self.mapping
        context['map_types'] = _get_map_type_list()

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

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

        # Load the source that the new mapping will belong to
        api = OclApi(self.request, debug=True)
        source = api.get(self.owner_type, self.owner_id, 'sources', self.source_id).json()

        # TODO: Load list of map types

        # Set the context
        context['kwargs'] = self.kwargs
        context['source'] = source
        context['map_types'] = _get_map_type_list()

        return context
Ejemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     super(MappingNewForm, self).__init__(*args, **kwargs)
     # create widgets here to delay calls to api until initialization of the form
     self.fields['map_type'].widget = ComboBoxWidget(data_list=[(t) for t in _get_map_type_list()], name="map_type_list")
Ejemplo n.º 5
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.º 6
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