示例#1
0
    def concept_view(self):
        '''
        This view displays the concept details

        :param request: A :class:`pyramid.request.Request`
        '''
        conceptschemes = [
            {'id': x.get_metadata()['id'],
             'conceptscheme': x.concept_scheme}
            for x in self.skos_registry.get_providers() if not any([not_shown in x.get_metadata()['subject']
                                                                    for not_shown in ['external', 'hidden']])
        ]

        scheme_id = self.request.matchdict['scheme_id']
        c_id = self.request.matchdict['c_id']
        provider = self.request.skos_registry.get_provider(scheme_id)

        if not provider:
            raise ConceptSchemeNotFoundException(scheme_id)
        try:
            c = self.skos_manager.get_thing(c_id, provider.conceptscheme_id)
            if isinstance(c, Concept):
                concept_type = "Concept"
            elif isinstance(c, Collection):
                concept_type = "Collection"
            else:
                return Response('Thing without type: ' + str(c_id), status_int=500)
            url = self.request.route_url('concept', scheme_id=scheme_id, c_id=c_id)
            update_last_visited_concepts(self.request, {'label': c.label(self.request.locale_name).label, 'url': url})
            return {'concept': c, 'conceptType': concept_type, 'scheme_id': scheme_id, 'conceptschemes': conceptschemes}
        except NoResultFound:
            raise ConceptNotFoundException(c_id)
示例#2
0
    def concept_view(self):
        """
        This view displays the concept details
        """
        conceptschemes = [
            {'id': x.get_metadata()['id'],
             'conceptscheme': x.concept_scheme}
            for x in self.skos_registry.get_providers() if not any([not_shown in x.get_metadata()['subject']
                                                                    for not_shown in ['external', 'hidden']])
        ]

        scheme_id = self.request.matchdict['scheme_id']
        c_id = self.request.matchdict['c_id']
        provider = self.request.skos_registry.get_provider(scheme_id)

        if not provider:
            raise ConceptSchemeNotFoundException(scheme_id)
        try:
            c = self.skos_manager.get_thing(c_id, provider.conceptscheme_id)
            if isinstance(c, Concept):
                concept_type = "Concept"
            elif isinstance(c, Collection):
                concept_type = "Collection"
            else:
                return Response('Thing without type: ' + str(c_id), status_int=500)
            url = self.request.route_url('concept', scheme_id=scheme_id, c_id=c_id)
            update_last_visited_concepts(self.request, {'label': c.label(self.request.locale_name).label, 'url': url})
            return {'concept': c, 'conceptType': concept_type, 'scheme_id': scheme_id,
                    'conceptschemes': conceptschemes, 'provider': provider}
        except NoResultFound:
            raise ConceptNotFoundException(c_id)
示例#3
0
 def test_update_last_visited_concepts_max(self):
     for id in range(50):
         c = Concept()
         c.id = id
         c.labels = [Label('test', language_id='en-us')]
         update_last_visited_concepts(self.request, {'label': c.label(), 'url': 'http://test.test/{0}'.format(id)})
     self.assertEqual(4, len(self.request.session['last_visited']))
     last = self.request.session['last_visited'].pop()
     self.assertEqual('http://test.test/49', last['url'])
示例#4
0
 def test_update_last_visited_concepts(self):
     c = Concept()
     c.id= 2
     c.labels = [Label('test', language_id='en-us')]
     update_last_visited_concepts(self.request, {'label': c.label(), 'url': 'http://test.test/{0}'.format(55)})
     c = Concept()
     c.id= 33
     c.labels = [Label('test', language_id='nl-be')]
     update_last_visited_concepts(self.request, {'label': c.label(), 'url': 'http://test.test/{0}'.format(2)})
     self.assertEqual(2, len(self.request.session['last_visited']))
示例#5
0
 def test_update_last_visited_concepts_max(self):
     for id in range(50):
         c = Concept()
         c.id = id
         c.labels = [Label('test', language_id='en-us')]
         update_last_visited_concepts(
             self.request, {
                 'label': c.label(),
                 'url': 'http://test.test/{0}'.format(id)
             })
     self.assertEqual(4, len(self.request.session['last_visited']))
     last = self.request.session['last_visited'].pop()
     self.assertEqual('http://test.test/49', last['url'])
示例#6
0
 def test_update_last_visited_concepts(self):
     c = Concept()
     c.id = 2
     c.labels = [Label('test', language_id='en-us')]
     update_last_visited_concepts(self.request, {
         'label': c.label(),
         'url': 'http://test.test/{0}'.format(55)
     })
     c = Concept()
     c.id = 33
     c.labels = [Label('test', language_id='nl-be')]
     update_last_visited_concepts(self.request, {
         'label': c.label(),
         'url': 'http://test.test/{0}'.format(2)
     })
     self.assertEqual(2, len(self.request.session['last_visited']))