Exemplo n.º 1
0
    def get(self, request, *args, **kwargs):
        """Get concept
        """

        self.get_args()
        data = {}
        print self.request.is_ajax()
        api = OclApi(self.request, debug=True)
        source = api.get(self.owner_type, self.owner_id, 'sources',
                         self.source_id).json()
        data['source'] = source

        if self.concept_id is not None:
            # edit
            concept = api.get(self.owner_type, self.owner_id, 'sources',
                              self.source_id, 'concepts',
                              self.concept_id).json()
            data['concept'] = concept

            if request.is_ajax():
                return self.render_json_response(concept)

        if self.concept_id is None:
            return TemplateResponse(request, 'concepts/concept_create.html',
                                    data)
        else:
            return TemplateResponse(request, 'concepts/concept_edit.html',
                                    data)
Exemplo n.º 2
0
def _get_org_or_user_sources_list(**kwargs):
    sources = []
    oclApi = OclApi(kwargs['initial']['request'], debug=True)
    username = str(kwargs['initial']['request'].user)

    print("_get_org_or_user_sources_list:  kwargs: ", kwargs)

    response_user_sources = oclApi.get('users',
                                       username,
                                       'sources',
                                       params={'limit': 20})
    sources.extend([] if response_user_sources.status_code == 404 else
                   [source for source in response_user_sources.json()])
    response_user_orgs = oclApi.get('users',
                                    username,
                                    'orgs',
                                    params={'limit': 20})
    for user_org in response_user_orgs.json():
        response_user_orgs_sources = oclApi.get('orgs',
                                                user_org['id'],
                                                'sources',
                                                params={'limit': 20})
        sources.extend(
            [] if response_user_orgs_sources.status_code ==
            404 else [source for source in response_user_orgs_sources.json()])

    return sources
Exemplo n.º 3
0
    def test_user_update(self):
        """ Test user partial data update.
            Need to login first with hard coded password.
         """
        ocl = OclApi(admin=True, debug=True)

        user = User.objects.create_user(username=self.username)
        user.password = self.password
        user.save()

        result = ocl.get_user_auth(user.username, user.password)
        print 'get auth:', result.status_code
        if len(result.text) > 0:
            print result.json()

        request = FakeRequest()
        ocl.save_auth_token(request, result.json())

        ocl = OclApi(request, debug=True)
        print ocl.get('users', user.username).json()

        data = {'company': 'company one'}
        result = ocl.post('user', **data)
        print result.status_code
        if len(result.text) > 0:
            print result.json()
Exemplo n.º 4
0
    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
Exemplo n.º 5
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
Exemplo n.º 6
0
    def get_initial(self):
        """ Load initial form data """
        context = super(SourceVersionsNewView, self).get_initial()
        self.get_args()

        # Load the most recent source version
        api = OclApi(self.request, debug=True)
        source_version = None
        if self.from_org:
            source_version = api.get('orgs', self.org_id, 'sources', self.source_id,
                                     'versions', params={'limit':1}).json()
        else:
            source_version = api.get('users', self.user_id, 'sources', self.source_id,
                                     'versions', params={'limit':1}).json()

        data = {
            'request': self.request,
            'from_user': self.from_user,
            'from_org': self.from_org,
            'user_id': self.user_id,
            'org_id': self.org_id,
            'owner_type': self.owner_type,
            'owner_id': self.owner_id,
            'source_id': self.source_id,
            'previous_version': source_version[0]['id'],
            'released': False
        }
        return data
Exemplo n.º 7
0
    def get(self, request, *args, **kwargs):
        """
            Return a list of descriptions as json.
        """
        self.get_all_args()
        api = OclApi(self.request, debug=True)

        if self.optional:
            result = api.get(self.owner_type,
                             self.owner_id,
                             'sources',
                             self.source_id,
                             'concepts',
                             self.concept_id,
                             self.item_name,
                             params=self.optional)
        else:
            result = api.get(self.owner_type, self.owner_id, 'sources',
                             self.source_id, 'concepts', self.concept_id,
                             self.item_name)

        if not result.ok:
            print result
            return self.render_bad_request_response(result)

        return self.render_json_response(result.json())
Exemplo n.º 8
0
    def get(self, request, *args, **kwargs):
        """Get concept
        """

        self.get_args()
        data = {}
        print self.request.is_ajax()
        api = OclApi(self.request, debug=True)
        source = api.get(self.owner_type, self.owner_id, 'sources', self.source_id).json()
        data['source'] = source

        if self.concept_id is not None:
            # edit
            concept = api.get(
                self.owner_type, self.owner_id, 'sources', self.source_id,
                'concepts', self.concept_id).json()
            data['concept'] = concept

            if request.is_ajax():
                return self.render_json_response(concept)

        if self.concept_id is None:
            return TemplateResponse(request, 'concepts/concept_create.html', data)
        else:
            return TemplateResponse(request, 'concepts/concept_edit.html', data)
Exemplo n.º 9
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
Exemplo n.º 10
0
    def test_user_update(self):
        """ Test user partial data update.
            Need to login first with hard coded password.
         """
        ocl = OclApi(admin=True, debug=True)

        user = User.objects.create_user(username=self.username)
        user.password = self.password
        user.save()

        result = ocl.get_user_auth(user.username, user.password)
        print 'get auth:', result.status_code
        if len(result.text) > 0:
            print result.json()

        request = FakeRequest()
        ocl.save_auth_token(request, result.json())


        ocl = OclApi(request, debug=True)
        print ocl.get('users', user.username).json()

        data = {'company': 'company one'}
        result = ocl.post('user', **data)
        print result.status_code
        if len(result.text) > 0:
            print result.json()
Exemplo n.º 11
0
    def get_initial(self):
        super(CollectionVersionsNewView, self).get_initial()
        self.get_args()

        api = OclApi(self.request, debug=True)
        # collection_version = None
        if self.from_org:
            collection_version = api.get('orgs', self.org_id, 'collections', self.collection_id,
                                         'versions', params={'limit': 1}).json()
        else:
            collection_version = api.get('users', self.user_id, 'collections', self.collection_id,
                                         'versions', params={'limit': 1}).json()

        data = {
            'request': self.request,
            'from_user': self.from_user,
            'from_org': self.from_org,
            'user_id': self.user_id,
            'org_id': self.org_id,
            'owner_type': self.owner_type,
            'owner_id': self.owner_id,
            'collection_id': self.collection_id,
            'previous_version': collection_version[0]['id'],
            'released': False
        }
        return data
Exemplo n.º 12
0
    def get_form_class(self):
        """
        A sneaky way to hook into the generic form processing view, to grep args
        from the URL, retrieve some application data and store them in the view.
        """
        self.get_args()
        self.source_id = self.kwargs.get('source')
        self.concept_id = self.kwargs.get('concept')

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

        if self.from_org:
            self.source = api.get(self.owner_type, self.org_id, 'sources',
                                  self.source_id).json()
            self.concept = api.get(self.owner_type, self.org_id, 'sources',
                                   self.source_id, 'concepts',
                                   self.concept_id).json()
        else:
            self.source = api.get(self.owner_type, self.user_id, 'sources',
                                  self.source_id).json()
            self.concept = api.get(self.owner_type, self.user_id, 'sources',
                                   self.source_id, 'concepts',
                                   self.concept_id).json()

        return ConceptEditForm
Exemplo n.º 13
0
    def get_form_class(self):
        """
        A sneaky way to hook into the generic form processing view, to grep args
        from the URL, retrieve some application data and store them in the view.
        """
        self.get_args()
        self.source_id = self.kwargs.get('source')
        self.concept_id = self.kwargs.get('concept')

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

        if self.from_org:
            self.source = api.get(
                self.owner_type, self.org_id, 'sources', self.source_id).json()
            self.concept = api.get(
                self.owner_type, self.org_id, 'sources', self.source_id,
                'concepts', self.concept_id).json()
        else:
            self.source = api.get(
                self.owner_type, self.user_id, 'sources', self.source_id).json()
            self.concept = api.get(
                self.owner_type, self.user_id, 'sources', self.source_id,
                'concepts', self.concept_id).json()

        return ConceptEditForm
Exemplo n.º 14
0
    def get_context_data(self, *args, **kwargs):
        """Set the context for OCL user
        """

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

        # Setup API calls
        username = (kwargs["object"].username)
        api = OclApi(self.request, debug=True)

        # Set the limit of records for standard display
        # TODO([email protected]): Create page for each user resource list to handle > than limit
        limit = 20

        ocl_user = api.get('users', username).json()
        ocl_user_orgs = api.get('users', username, 'orgs', params={'limit':limit}).json()
        ocl_user_sources = api.get('users', username, 'sources', params={'limit':limit}).json()
        #ocl_user_collections = api.get('users', username, 'collections',
        #                               params={'limit':limit}).json()

        # Set the context
        context['ocl_user'] = ocl_user
        context['orgs'] = ocl_user_orgs
        context['sources'] = ocl_user_sources
        #context['collections'] = ocl_user_collections

        if self.request.user.username == username:
            context['api_token'] = api.api_key
        return context
Exemplo n.º 15
0
    def get_initial(self):
        """ Load initial form data """
        context = super(SourceVersionsNewView, self).get_initial()
        self.get_args()

        # Load the most recent source version
        api = OclApi(self.request, debug=True)
        source_version = None
        if self.from_org:
            source_version = api.get('orgs', self.org_id, 'sources', self.source_id,
                                     'versions', params={'limit':1}).json()
        else:
            source_version = api.get('users', self.user_id, 'sources', self.source_id,
                                     'versions', params={'limit':1}).json()

        data = {
            'request': self.request,
            'from_user': self.from_user,
            'from_org': self.from_org,
            'user_id': self.user_id,
            'org_id': self.org_id,
            'owner_type': self.owner_type,
            'owner_id': self.owner_id,
            'source_id': self.source_id,
            'previous_version': source_version[0]['id'],
            'released': False
        }
        return data
Exemplo n.º 16
0
    def get_concept_details(self,
                            owner_type,
                            owner_id,
                            source_id,
                            concept_id,
                            source_version_id=None,
                            concept_version_id=None,
                            include_mappings=False,
                            include_inverse_mappings=False):
        """ Get the concept details. """
        # TODO([email protected]): Validate input parameters

        # Setup request parameters
        params = {}
        if include_mappings:
            params['includeMappings'] = 'true'
            params['verbose'] = 'true'
        if include_inverse_mappings:
            params['includeInverseMappings'] = 'true'
            params['verbose'] = 'true'

        # Perform the search
        api = OclApi(self.request, debug=True)
        if source_version_id and concept_version_id:
            raise ValueError(
                'Must specify only a source version or a concept version. Both were specified.'
            )
        elif source_version_id:
            search_response = api.get(owner_type,
                                      owner_id,
                                      'sources',
                                      source_id,
                                      source_version_id,
                                      'concepts',
                                      concept_id,
                                      params=params)
        elif concept_version_id:
            search_response = api.get(owner_type,
                                      owner_id,
                                      'sources',
                                      source_id,
                                      'concepts',
                                      concept_id,
                                      concept_version_id,
                                      params=params)
        else:
            search_response = api.get(owner_type,
                                      owner_id,
                                      'sources',
                                      source_id,
                                      'concepts',
                                      concept_id,
                                      params=params)
        if search_response.status_code == 404:
            raise Http404(search_response.text)
        elif search_response.status_code != 200:
            search_response.raise_for_status()
        return search_response.json()
Exemplo n.º 17
0
 def get_form_class(self):
     """ Trick to load initial data """
     self.get_args()
     api = OclApi(self.request, debug=True)
     self.source_id = self.kwargs.get('source')
     if self.from_org:
         self.source = api.get('orgs', self.org_id, 'sources', self.source_id).json()
     else:
         self.source = api.get('users', self.user_id, 'sources', self.source_id).json()
     return CollectionEditForm
Exemplo n.º 18
0
    def get_context_data(self, *args, **kwargs):
        """Set the context for OCL user
        """

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

        # Setup API calls
        username = (kwargs["object"].username)
        api = OclApi(self.request, debug=True)

        # Set the limit of records for standard display
        # TODO([email protected]): Create page for each user resource list to handle > than limit
        limit = 20

        ocl_user = api.get('users', username).json()
        ocl_user_orgs = api.get('users',
                                username,
                                'orgs',
                                params={
                                    'limit': limit
                                }).json()
        ocl_user_sources = api.get('users',
                                   username,
                                   'sources',
                                   params={
                                       'limit': limit
                                   }).json()
        ocl_user_collections = api.get('users',
                                       username,
                                       'collections',
                                       params={
                                           'limit': limit
                                       }).json()

        # Set the selected tab
        default_tab = 'repositories'
        if 'tab' in self.request.GET:
            selected_tab = self.request.GET.get('tab').lower()
            if selected_tab not in ('repositories', 'organizations'):
                selected_tab = default_tab
        else:
            selected_tab = default_tab

        # Set the context
        context['ocl_user'] = ocl_user
        context['orgs'] = ocl_user_orgs
        context['sources'] = ocl_user_sources
        context['collections'] = ocl_user_collections
        context['selected_tab'] = selected_tab

        if self.request.user.username == username:
            context['api_token'] = api.api_key
        return context
Exemplo n.º 19
0
    def get_context_data(self, *args, **kwargs):
        """ Set context data for retiring the concept """
        context = super(ConceptRetireView, self).get_context_data(*args, **kwargs)

        self.get_args()

        api = OclApi(self.request, debug=True)
        source = api.get(self.owner_type, self.owner_id, 'sources', self.source_id).json()
        concept = api.get(
            self.owner_type, self.owner_id, 'sources', self.source_id,
            'concepts', self.concept_id).json()
        context['source'] = source
        context['concept'] = concept
        context['kwargs'] = self.kwargs
        return context
Exemplo n.º 20
0
    def get_context_data(self, *args, **kwargs):
        """ Set context data for retiring the concept """
        context = super(ConceptRetireView, self).get_context_data(*args, **kwargs)

        self.get_args()

        api = OclApi(self.request, debug=True)
        source = api.get(self.owner_type, self.owner_id, 'sources', self.source_id).json()
        concept = api.get(
            self.owner_type, self.owner_id, 'sources', self.source_id,
            'concepts', self.concept_id).json()
        context['source'] = source
        context['concept'] = concept
        context['kwargs'] = self.kwargs
        return context
Exemplo n.º 21
0
    def get_context_data(self, *args, **kwargs):
        """ Set context data for retiring the mapping """
        context = super(MappingRetireView, self).get_context_data(*args, **kwargs)

        self.get_args()

        api = OclApi(self.request, debug=True)
        source = api.get(self.owner_type, self.owner_id, 'sources', self.source_id).json()
        mapping = api.get(
            self.owner_type, self.owner_id, 'sources', self.source_id,
            'mappings', self.mapping_id).json()
        context['source'] = source
        context['mapping'] = mapping
        context['kwargs'] = self.kwargs
        return context
Exemplo n.º 22
0
    def get_context_data(self, *args, **kwargs):
        """ Loads the context data for creating a new concept. """

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

        # Load the source that the new concept 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 names types
        # TODO: Load list of description types
        # TODO: Load list of locales
        # TODO: Load list of datatypes
        # TODO: Load list of concept classes

        # Set the context
        context['kwargs'] = self.kwargs
        context['source'] = source
        context['locales'] = json.dumps(_get_locale_list())
        context['name_types'] = json.dumps(_get_name_type_list())
        context['description_types'] = json.dumps(_get_description_type_list())

        return context
Exemplo n.º 23
0
 def get_org(self):
     """
     Load the organization
     """
     self.org_id = self.kwargs.get('org')
     api = OclApi(self.request, debug=True)
     self.org = api.get('orgs', self.org_id).json()
Exemplo n.º 24
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
Exemplo n.º 25
0
 def get(self, request, *args, **kwargs):
     username = kwargs.get("user")
     if not (request.user.is_staff or request.user.username == username):
         return HttpResponse(status=401)
     api = OclApi(self.request, debug=True)
     result = api.get('users', username, "collections", params={'limit': '0'})
     return HttpResponse(json.dumps(result.json()), content_type="application/json")
Exemplo n.º 26
0
    def test_concept_names(self):
        """ Test concept names operations
            Need to login first with hard coded password.
         """
        ocl = OclApi(admin=True, debug=True)

        user = User.objects.create_user(username=self.username)
        user.password = self.password
        user.save()

        result = ocl.get_user_auth(user.username, user.password)
        print 'get auth:', result.status_code
        if len(result.text) > 0:
            print result.json()

        request = FakeRequest()
        ocl.save_auth_token(request, result.json())


        ocl = OclApi(request, debug=True)
        org_id = 'TESTORG1'
        source_id = 'S1'
        concept_id = 'C2'

        result = ocl.get('orgs', org_id, 'sources', source_id, 'concepts', concept_id, 'names')
        print result.status_code
        print result
        if len(result.text) > 0:
            print result.json()
Exemplo n.º 27
0
 def get_form_class(self):
     """ Trick to load initial data """
     self.get_args()
     api = OclApi(self.request, debug=True)
     self.collection = api.get(self.owner_type, self.owner_id, 'collections',
                               self.collection_id).json()
     return CollectionEditForm
Exemplo n.º 28
0
 def get_form_class(self):
     """ Trick to load initial form data """
     self.get_args()
     api = OclApi(self.request, debug=True)
     self.source_version = api.get(self.owner_type, self.owner_id, 'sources', self.source_id,
                                   self.source_version_id).json()
     return SourceVersionsEditForm
Exemplo n.º 29
0
    def test_concept_names(self):
        """ Test concept names operations
            Need to login first with hard coded password.
         """
        ocl = OclApi(admin=True, debug=True)

        user = User.objects.create_user(username=self.username)
        user.password = self.password
        user.save()

        result = ocl.get_user_auth(user.username, user.password)
        print 'get auth:', result.status_code
        if len(result.text) > 0:
            print result.json()

        request = FakeRequest()
        ocl.save_auth_token(request, result.json())

        ocl = OclApi(request, debug=True)
        org_id = 'TESTORG1'
        source_id = 'S1'
        concept_id = 'C2'

        result = ocl.get('orgs', org_id, 'sources', source_id, 'concepts',
                         concept_id, 'names')
        print result.status_code
        print result
        if len(result.text) > 0:
            print result.json()
Exemplo n.º 30
0
    def get_context_data(self, *args, **kwargs):
        context = super(CollectionVersionsView, 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()

        # Load the collection versions
        params = self.request.GET.copy()
        params['verbose'] = 'true'
        params['limit'] = '10'
        searcher = self.get_collection_versions(
            self.owner_type, self.owner_id, self.collection_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)

        for collection_version in searcher.search_results:
            if '_ocl_processing' in collection_version and collection_version['_ocl_processing']:
                collection_version['is_processing'] = 'True'

        # Set the context
        context['kwargs'] = self.kwargs
        context['url_params'] = self.request.GET
        context['current_page'] = search_results_current_page
        context['pagination_url'] = self.request.get_full_path()
        context['selected_tab'] = 'Versions'
        context['collection'] = collection
        context['collection_versions'] = searcher.search_results

        return context
Exemplo n.º 31
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
Exemplo n.º 32
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
Exemplo n.º 33
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
Exemplo n.º 34
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
Exemplo n.º 35
0
 def get_form_class(self):
     """ Trick to load initial data """
     self.get_args()
     api = OclApi(self.request, debug=True)
     self.collection = api.get(self.owner_type, self.owner_id,
                               'collections', self.collection_id).json()
     return CollectionEditForm
Exemplo n.º 36
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
Exemplo n.º 37
0
 def get_form_class(self):
     """ Trick to load initial form data """
     self.get_args()
     api = OclApi(self.request, debug=True)
     self.source_version = api.get(self.owner_type, self.owner_id, 'sources', self.source_id,
                                   self.source_version_id).json()
     return SourceVersionsEditForm
Exemplo n.º 38
0
 def get_org(self):
     """
     Load the organization
     """
     self.org_id = self.kwargs.get('org')
     api = OclApi(self.request, debug=True)
     self.org = api.get('orgs', self.org_id).json()
Exemplo n.º 39
0
 def get(self, request, *args, **kwargs):
     self.get_args()
     if request.is_ajax():
         api = OclApi(self.request, debug=True)
         result = api.get(self.owner_type, self.owner_id, 'sources', kwargs.get('source'),
                          'versions', params={'limit': '0'})
         return HttpResponse(json.dumps(result.json()), content_type="application/json")
     return super(SourceVersionsView, self).get(self, *args, **kwargs)
Exemplo n.º 40
0
 def get(self, request, *args, **kwargs):
     self.get_args()
     if request.is_ajax():
         api = OclApi(self.request, debug=True)
         result = api.get(self.owner_type, self.owner_id, 'collections',
                          kwargs.get('collection'), 'versions', params={'limit': '0'})
         return HttpResponse(json.dumps(result.json()), content_type="application/json")
     return super(CollectionVersionsView, self).get(self, *args, **kwargs)
Exemplo n.º 41
0
 def get(self, request, *args, **kwargs):
     api = OclApi(self.request, debug=True)
     result = api.get('users',
                      kwargs.get("user"),
                      "collections",
                      params={'limit': '0'})
     return HttpResponse(json.dumps(result.json()),
                         content_type="application/json")
Exemplo n.º 42
0
    def get_context_data(self, *args, **kwargs):

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

        api = OclApi(self.request, debug=True)
        # collection = None
        if self.from_org:
            collection = api.get('orgs', self.org_id, 'collections', self.collection_id).json()
        else:
            collection = api.get('users', self.user_id, 'collections', self.collection_id).json()

        # Set the context
        context['kwargs'] = self.kwargs
        context['collection'] = collection

        return context
Exemplo n.º 43
0
    def get_context_data(self, *args, **kwargs):
        context = super(CollectionReferencesView, 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)
        data = api.get(self.owner_type, self.owner_id, 'collections', self.collection_id,'references').json()
        collection = results.json()

        # Set the context
        context['kwargs'] = self.kwargs
        context['url_params'] = self.request.GET
        context['selected_tab'] = 'References'
        context['collection'] = collection
        context['references'] = data.get('references')

        return context
Exemplo n.º 44
0
    def render(self, context):
        # Init state storage
        try:
            obj = self.obj_var.resolve(context)
        except template.VariableDoesNotExist:
            return ''

        user = context['user']
        has_access = False
        if not user.is_authenticated():
            # User must be authenticated if checking for access
            has_access = False

        elif obj.get('type') == 'Organization':  # pylint: disable=E1101
            # If org, authenticated user can access only if they are a member of the org
            api = OclApi(context['request'], debug=True)
            results = api.get('orgs', obj.get('id'), 'members', user.username)  # pylint: disable=E1101
            if results.status_code == 204:
                has_access = True
            print 'ACCESS Check on org:', results.status_code

        elif obj.get('type') == 'User':  # pylint: disable=E1101
            # If user, authenticated user can access only if they are that user
            if user.username == obj.get('username'):  # pylint: disable=E1101
                has_access = True

        elif obj.get('owner_type') == 'Organization':  # pylint: disable=E1101
            # If resource is owned by an org, then user must be a member of the org
            api = OclApi(context['request'], debug=True)
            results = api.get('orgs', obj.get('owner'), 'members',
                              user.username)  # pylint: disable=E1101
            if results.status_code == 204:
                has_access = True
            print 'ACCESS Check on ' + obj.get(
                'type') + ':', results.status_code  # pylint: disable=E1101

        elif obj.get('owner_type') == 'User':  # pylint: disable=E1101
            # If resource is owned by a user, then authenticated user must own the resource
            if obj.get('owner') == user.username:  # pylint: disable=E1101
                has_access = True

        if has_access:
            return self.nodelist_true.render(context)
        else:
            return self.nodelist_false.render(context)
Exemplo n.º 45
0
    def get_form_class(self):
        """
        A sneaky way to hook into the generic form processing view, to grep args
        from the URL, retrieve some application data and store them in the view.
        """
        self.get_args()
        self.source_id = self.kwargs.get('source')
        self.mapping_id = self.kwargs.get('mapping')

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

        self.source = api.get(
            self.owner_type, self.org_id, 'sources', self.source_id).json()
        self.mapping = api.get(
            self.owner_type, self.org_id, 'sources', self.source_id,
            'mappings', self.mapping_id).json()

        return MappingEditForm
Exemplo n.º 46
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.º 47
0
    def render(self, context):
        # Init state storage
        try:
            obj = self.obj_var.resolve(context)
        except template.VariableDoesNotExist:
            return ''

        user = context['user']
        has_access = False
        if not user.is_authenticated():
            # User must be authenticated if checking for access
            has_access = False

        elif obj.get('type') == 'Organization':     # pylint: disable=E1101
            # If org, authenticated user can access only if they are a member of the org
            api = OclApi(context['request'], debug=True)
            results = api.get('orgs', obj.get('id'), 'members', user.username)  # pylint: disable=E1101
            if results.status_code == 204:
                has_access = True
            print 'ACCESS Check on org:', results.status_code

        elif obj.get('type') == 'User':     # pylint: disable=E1101
            # If user, authenticated user can access only if they are that user
            if user.username == obj.get('username'):    # pylint: disable=E1101
                has_access = True

        elif obj.get('owner_type') == 'Organization':       # pylint: disable=E1101
            # If resource is owned by an org, then user must be a member of the org
            api = OclApi(context['request'], debug=True)
            results = api.get('orgs', obj.get('owner'), 'members', user.username)       # pylint: disable=E1101
            if results.status_code == 204:
                has_access = True
            print 'ACCESS Check on ' + obj.get('type') + ':', results.status_code       # pylint: disable=E1101

        elif obj.get('owner_type') == 'User':       # pylint: disable=E1101
            # If resource is owned by a user, then authenticated user must own the resource
            if obj.get('owner') == user.username:       # pylint: disable=E1101
                has_access = True

        if has_access:
            return self.nodelist_true.render(context)
        else:
            return self.nodelist_false.render(context)
Exemplo n.º 48
0
    def get_concept_details(self, owner_type, owner_id, source_id, concept_id,
                            source_version_id=None, concept_version_id=None,
                            include_mappings=False, include_inverse_mappings=False):
        """ Get the concept details. """
        # TODO([email protected]): Validate input parameters

        # Setup request parameters
        params = {}
        if include_mappings:
            params['includeMappings'] = 'true'
            params['verbose'] = 'true'
        if include_inverse_mappings:
            params['includeInverseMappings'] = 'true'
            params['verbose'] = 'true'

        # Perform the search
        api = OclApi(self.request, debug=True)
        if source_version_id and concept_version_id:
            raise ValueError(
                'Must specify only a source version or a concept version. Both were specified.')
        elif source_version_id:
            search_response = api.get(
                owner_type, owner_id,
                'sources', source_id, source_version_id,
                'concepts', concept_id,
                params=params)
        elif concept_version_id:
            search_response = api.get(
                owner_type, owner_id,
                'sources', source_id,
                'concepts', concept_id, concept_version_id,
                params=params)
        else:
            search_response = api.get(
                owner_type, owner_id,
                'sources', source_id,
                'concepts', concept_id,
                params=params)
        if search_response.status_code == 404:
            raise Http404(search_response.text)
        elif search_response.status_code != 200:
            search_response.raise_for_status()
        return search_response.json()
Exemplo n.º 49
0
    def get_context_data(self, *args, **kwargs):
        context = super(CollectionCreateView, self).get_context_data(*args, **kwargs)

        self.get_args()

        api = OclApi(self.request, debug=True)
        org = ocl_user = None

        if self.from_org:
            org = api.get('orgs', self.org_id).json()
        else:
            ocl_user = api.get('users', self.user_id).json()
        # Set the context
        context['org'] = org
        context['ocl_user'] = ocl_user
        context['from_user'] = self.from_user
        context['from_org'] = self.from_org

        return context
Exemplo n.º 50
0
 def clean_concept_id(self):
     """ concept ID must be unique """
     concept_id = self.cleaned_data['concept_id']
     source = self.initial['source']
     request = self.initial['request']
     api = OclApi(request, debug=True)
     result = api.get('orgs', source['owner'], 'sources', source['id'], 'concepts', concept_id)
     if result.status_code == 200:
         raise forms.ValidationError(_('This Concept ID is already used.'))
     return concept_id
Exemplo n.º 51
0
 def get_mapping_details(self, owner_type, owner_id, source_id,
                         mapping_id, mapping_version_id=None):
     """
     Load mapping details from the API and return as dictionary.
     """
     # TODO([email protected]): Validate the input parameters
     api = OclApi(self.request, debug=True)
     if mapping_version_id:
         search_response = api.get(
             owner_type, owner_id, 'sources', source_id, 'mappings',
             mapping_id, mapping_version_id)
     else:
         search_response = api.get(
             owner_type, owner_id, 'sources', source_id, 'mappings', mapping_id)
     if search_response.status_code == 404:
         raise Http404
     elif search_response.status_code != 200:
         search_response.raise_for_status()
     return search_response.json()
Exemplo n.º 52
0
    def get_context_data(self, *args, **kwargs):
        """
        Load context data needed for the view
        """
        context = super(SourceVersionsNewView, self).get_context_data(*args, **kwargs)
        self.get_args()

        # Load the source
        api = OclApi(self.request, debug=True)
        source = None
        if self.from_org:
            source = api.get('orgs', self.org_id, 'sources', self.source_id).json()
        else:
            source = api.get('users', self.user_id, 'sources', self.source_id).json()

        # Set the context
        context['kwargs'] = self.kwargs
        context['source'] = source

        return context
Exemplo n.º 53
0
    def clean_concept_id(self, request, concept_id):
        """ concept ID must be unique
        """

        api = OclApi(request, debug=True)
        result = api.get(
            self.owner_type, self.owner_id, 'sources', self.source_id,
            'concepts', concept_id)
        if result.status_code == 200:
            return _('This Concept ID is already used.')
        else:
            return None