Exemplo n.º 1
0
    def test_get_leafs_and_edges(self):
        topic = self.create_topic()
        models = topic.get_models_module()
        Person = models.Person
        Company = models.Company
        # be sure we dont have anybody
        [p.delete() for p in Person.objects.all()]

        c1 = Company.objects.create(name='random', status='random')

        p1 = Person.objects.create(first_name='test', name='test')
        p1.employed_by.add(c1)
        p1.save()
        p2 = Person.objects.create(first_name='test', name='test')
        p2.employed_by.add(c1)
        p2.save()

        leafs = get_leafs_and_edges(topic=topic, depth=3)

        p3 = Person.objects.create(first_name='test',
                                   name='test',
                                   employed_by=c1)

        new_leafs = get_leafs_and_edges(topic=topic, depth=3)
        cached_leafs = topic_cache.get(topic,
                                       'leafs_and_nodes_%s_%s' % (3, '0'))
        self.assertEqual(new_leafs, cached_leafs)
        self.assertGreater(len(new_leafs[1]), len(leafs[1]))
Exemplo n.º 2
0
    def test_get_leafs_and_edges(self):
        topic = self.create_topic()
        models = topic.get_models_module()
        Person = models.Person
        Company = models.Company
        # be sure we dont have anybody
        [ p.delete() for p in Person.objects.all() ]

        c1 = Company.objects.create(name='random', status='random')

        p1 = Person.objects.create(first_name='test', name='test')
        p1.employed_by.add(c1)
        p1.save()
        p2 = Person.objects.create(first_name='test', name='test')
        p2.employed_by.add(c1)
        p2.save()

        leafs = get_leafs_and_edges(topic=topic, depth=3)

        p3 = Person.objects.create(first_name='test', name='test', employed_by=c1)

        new_leafs = get_leafs_and_edges(topic=topic, depth=3)
        cached_leafs = topic_cache.get(topic, 'leafs_and_nodes_%s_%s' % (3, '0'))
        self.assertEqual(new_leafs, cached_leafs)
        self.assertGreater(len(new_leafs[1]), len(leafs[1]))
Exemplo n.º 3
0
 def get_graph(self, request, **kwargs):
     self.method_check(request, allowed=["get"])
     self.throttle_check(request)
     depth = int(request.GET["depth"]) if "depth" in request.GET.keys() else 1
     topic = Topic.objects.get(ontology_as_mod=get_model_topic(self.get_model()))
     leafs, edges = get_leafs_and_edges(topic=topic, depth=depth, root_node=kwargs["pk"])
     self.log_throttled_access(request)
     return self.create_response(request, {"leafs": leafs, "edges": edges})
Exemplo n.º 4
0
 def summary_graph(self, bundle, request, **kwargs):
     self.method_check(request, allowed=['get'])
     self.throttle_check(request)
     depth     = int(request.GET['depth']) if 'depth' in request.GET.keys() else 1
     leafs, edges  = utils.get_leafs_and_edges(
         topic     = self.topic,
         depth     = depth,
         root_node = "0")
     self.log_throttled_access(request)
     return self.create_response(request, {'leafs': leafs, 'edges' : edges})
Exemplo n.º 5
0
 def summary_graph(self, bundle, request, **kwargs):
     self.method_check(request, allowed=['get'])
     self.throttle_check(request)
     depth = int(
         request.GET['depth']) if 'depth' in request.GET.keys() else 1
     leafs, edges = utils.get_leafs_and_edges(topic=self.topic,
                                              depth=depth,
                                              root_node="0")
     self.log_throttled_access(request)
     return self.create_response(request, {'leafs': leafs, 'edges': edges})
Exemplo n.º 6
0
 def get_graph(self, request, **kwargs):
     self.method_check(request, allowed=['get'])
     self.throttle_check(request)
     depth = int(request.GET['depth']) if 'depth' in request.GET.keys() else 2
     topic = Topic.objects.get(ontology_as_mod=get_model_topic(self.get_model()))
     leafs, edges = get_leafs_and_edges(
         topic     = topic,
         depth     = depth,
         root_node = kwargs['pk'])
     self.log_throttled_access(request)
     return self.create_response(request, {'leafs': leafs, 'edges' : edges})