Esempio n. 1
0
def edit(client, graph):
    graphID = graph.get('id', None)
    del graph['id']

    if graphID in ['create', 'clone']:
        graphObj = Graph.create(client=client)
    else:
        graphObj = Graph.get(id=graphID, client=client)

    if graphID == 'clone':
        graph['name'] = graph['name'] + ' clone'

    graphObj.update(type=graph.get('type', None),
                    name=graph.get('name', None),
                    incrementSelector=graph.get('incrementSelector', None),
                    rangeSelector=graph.get('rangeSelector', None),
                    limits=graph.get('limits', None),
                    data=graph.get('data', None),
                    grid=graph.get('grid', None),
                    crossHair=graph.get('crossHair', None),
                    legend=graph.get('legend', None),
                    tooltips=graph.get('tooltips', None),
                    query=graph.get('query', None),
                    exportData=graph.get('exportData', None))
    return {'status': 'edited', 'id': "graph_" + str(graphObj.id)}
Esempio n. 2
0
def resource(client):
    response = {}
    response['object'] = 'resource'
    response['type'] = 'graph'
    response['data'] = [Graph.getTemplate()]
    response['data'] += [graph.dict()
                         for graph in Graph.list(client=client)][::-1]
    return response
Esempio n. 3
0
    def create_graph(self, user_id, is_public=False):

        graph = Graph(user_id=user_id,
                      name='An Other Graph',
                      is_public=is_public,
                      spreadsheet_id='123456')
        graph.put()
        return graph
Esempio n. 4
0
 def test_logged_user_should_be_able_to_create_a_graph(self, mocked_user):
     mocked_user.return_value = self.user
     self.client.get(reverse("login"))
     self.assertFalse(Graph.query(Graph.user_id == self.user.user_id()).get())
     post_data = {'is_public': False, 'name': 'Test', 'spreadsheet_id': '123'}
     response = self.client.post(reverse("graph_create"), post_data)
     self.assertEqual(response.status_code, 302)
     new_graph = Graph.query(Graph.user_id == self.user.user_id()).get()
     self.assertTrue(new_graph)
Esempio n. 5
0
    def create_graph(self, user_id, is_public=False):

        graph = Graph(
            user_id=user_id,
            name='An Other Graph',
            is_public=is_public,
            spreadsheet_id='123456'
        )
        graph.put()
        return graph
 def test_logged_user_should_be_able_to_create_a_graph(self, mocked_user):
     mocked_user.return_value = self.user
     self.client.get(reverse("login"))
     self.assertFalse(
         Graph.query(Graph.user_id == self.user.user_id()).get())
     post_data = {
         'is_public': False,
         'name': 'Test',
         'spreadsheet_id': '123'
     }
     response = self.client.post(reverse("graph_create"), post_data)
     self.assertEqual(response.status_code, 302)
     new_graph = Graph.query(Graph.user_id == self.user.user_id()).get()
     self.assertTrue(new_graph)
Esempio n. 7
0
    def get_context_data(self, **kwargs):
        """Optional |graph_id| as a matched parameter."""
        context = super(NetworkX, self).get_context_data(**kwargs)
        graph = None
        graph_id = int(kwargs['graph_id']) if 'graph_id' in kwargs else None

        graphs_query = FetchGraphs()
        graphs = [graph for graph in graphs_query.iter()]
        if graph_id:
            graph = Graph.get_by_id(graph_id)
            if graph not in graphs:
                raise Http404

        context.update({
            'form': GraphForm,
            'graphs': graphs,
            'graphs_count': len(graphs) if graphs else 0,
            'section': 'homepage',
            'hostname': settings.HOSTNAME,
            'json_data': _JSONify(graphs_query)
        })

        if graph_id:
            context.update({'graph_id': graph_id, 'graph': graph})

        return context
Esempio n. 8
0
def FetchGraphs():
    user = users.get_current_user()
    try:
        graphs_query = Graph.query(Graph.user_id == user.user_id())
    except AttributeError:
        []
    return graphs_query
Esempio n. 9
0
  def get_context_data(self, **kwargs):
    """Optional |graph_id| as a matched parameter."""
    context = super(NetworkX, self).get_context_data(**kwargs)
    graph = None
    graph_id = int(kwargs['graph_id']) if 'graph_id' in kwargs else None

    graphs_query = FetchGraphs()
    graphs = [graph for graph in graphs_query.iter()]
    if graph_id:
      graph = Graph.get_by_id(graph_id)
      if graph not in graphs:
        raise Http404

    context.update({
        'form': GraphForm,
        'graphs': graphs,
        'graphs_count': len(graphs) if graphs else 0,
        'section': 'homepage',
        'hostname': settings.HOSTNAME,
        'json_data': _JSONify(graphs_query)
    })

    if graph_id:
      context.update({
          'graph_id': graph_id,
          'graph': graph})

    return context
Esempio n. 10
0
def FetchGraphs():
  user = users.get_current_user()
  try:
    graphs_query = Graph.query(Graph.user_id == user.user_id())
  except AttributeError:
    []
  return graphs_query
Esempio n. 11
0
 def test_logged_user_should_not_be_able_to_create_a_graph_with_wrong_data(self, mocked_user):
     mocked_user.return_value = self.user
     self.client.get(reverse("login"))
     post_data = {}
     response = self.client.post(self.url, post_data)
     self.assertEqual(response.status_code, 200)
     new_graph = Graph.query(Graph.user_id == self.user.user_id()).get()
     self.assertFalse(new_graph)
Esempio n. 12
0
def remove(client, sourceName):
    source = SourceMeta.getOrCreate(client=client, name=sourceName)
    for graph in Graph.list(client=client, source=source):
        graph.removeSource()
    source.remove()
    response = {}
    response['object'] = 'confirmation'
    response['status'] = 'success'
    return response
Esempio n. 13
0
 def test_logged_user_should_not_be_able_to_create_a_graph_with_wrong_data(
         self, mocked_user):
     mocked_user.return_value = self.user
     self.client.get(reverse("login"))
     post_data = {}
     response = self.client.post(self.url, post_data)
     self.assertEqual(response.status_code, 200)
     new_graph = Graph.query(Graph.user_id == self.user.user_id()).get()
     self.assertFalse(new_graph)
Esempio n. 14
0
 def test_logged_user_should_not_be_able_to_update_a_graph_with_wrong_data(self, mocked_user):
     mocked_user.return_value = self.user
     self.client.get(reverse("login"))
     is_public_value = self.graph.is_public
     post_data = {'is_public': not is_public_value}
     response = self.client.post(self.url, post_data)
     self.assertEqual(response.status_code, 200)
     graph_not_modified = Graph.query(Graph.user_id == self.user.user_id()).get()
     self.assertEqual(graph_not_modified.is_public, is_public_value)
Esempio n. 15
0
    def restore_object( self, attrs, instance=None ):
        graph_id = attrs.get( 'graph_id' ) if attrs.get( 'graph_id' )\
                else helper_util.gen_id()
        
        d = attrs.get( 'last_updated' )
        d = d.replace( tzinfo=ptz( 'UTC' ) )
        try:
            instance = Graph.objects.get( graph_id = graph_id )
            if instance.last_updated > d:
                return instance
        except Graph.DoesNotExist:
            instance = Graph( graph_id = graph_id )

        instance.in_progress = attrs.get( 'in_progress' )
        instance.matrix_size = attrs.get( 'matrix_size' )
        instance.graph = attrs.get( 'graph' )
        instance.last_updated = attrs.get( 'last_updated' )

        return instance
Esempio n. 16
0
def graph(request):
    if request.method == 'GET':
        print "in get"
        return HttpResponse("datahdjfhdfhg")
    if request.method == 'POST':
        post_data = json.loads(request.body)
        nodes = post_data.get("nodes")
        edges = post_data.get("edges")
        graph_name = post_data.get("graphName")
        graph = Graph(name=graph_name)
        graph.save()
        for link in edges:
            graph_link = GraphLinks(graph_id=graph.id, link_id=link.get("id"))
            graph_link.save()
        response = HttpResponse(json.dumps({"key": "value", "key2": "value"}))
        response["Access-Control-Allow-Origin"] = "*"
        response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
        response["Access-Control-Max-Age"] = "1000"
        response["Access-Control-Allow-Headers"] = "*"
        return response
Esempio n. 17
0
 def test_logged_user_should_not_be_able_to_update_a_graph_with_wrong_data(
         self, mocked_user):
     mocked_user.return_value = self.user
     self.client.get(reverse("login"))
     is_public_value = self.graph.is_public
     post_data = {'is_public': not is_public_value}
     response = self.client.post(self.url, post_data)
     self.assertEqual(response.status_code, 200)
     graph_not_modified = Graph.query(
         Graph.user_id == self.user.user_id()).get()
     self.assertEqual(graph_not_modified.is_public, is_public_value)
Esempio n. 18
0
def new_graph(request):
    """Function for creating new graph

    This function allows to creating a new record
    in the database.
    """
    graph = Graph(name="new graph")
    graph.save()
    path_to_graph = "graph/graphs/graph" + str(graph.id) + ".json"
    to_json = {}
    with open(path_to_graph, 'w') as f:
        f.write(json.dumps(to_json))
        f.close()
    graph.path_to_graph = path_to_graph
    graph.save()
    return HttpResponse(graph.id)
Esempio n. 19
0
def build(client, items, isAuthenticated):
    response = {}
    response['object'] = 'resource'
    response['type'] = 'graph'
    response['data'] = []
    for item in items:
        id = item.get('id', None)
        graph = Graph.get(id=id, client=client)
        if graph is None:
            raise GraphNotFoundException(context={"id": id})
        tokens = item.get('tokens', [])
        conditions = item.get('conditions', [])
        utcOffset = item.get("utcOffset", "+00")
        response['data'].append(
            graph.build(utcOffset=utcOffset,
                        tokens=tokens,
                        conditions=conditions,
                        isAuthenticated=isAuthenticated))

    # [graph.build(tokensIDs-tokensIDs,conditions=conditions) for graph in Graph.list(client=client)][::-1]
    return response
Esempio n. 20
0
def query(client, items, isAuthenticated):
    response = {}
    response['object'] = 'resource'
    response['type'] = 'query'
    response['data'] = []
    for item in items:
        id = item.get('id', None)
        start = item.get('start', None)
        end = item.get('end', None)
        increment = item.get('increment', None)
        if None in [id, increment, start, end]: continue
        tokens = item.get('tokens', [])
        conditions = item.get('conditions', [])
        utcOffset = item.get('utcOffset', '+00')

        if end != 'now':
            start = dateutil.parser.parse(start)
            end = dateutil.parser.parse(end)
        else:
            start = int(start)

        graph = Graph.get(id=id, client=client)
        if graph is None:
            raise GraphNotFoundException(context={"id": id})

        result = {}
        result['id'] = id
        result['datasets'] = graph.runQuery(utcOffset=utcOffset,
                                            tokens=tokens,
                                            conditions=conditions,
                                            start=start,
                                            end=end,
                                            isAuthenticated=isAuthenticated,
                                            increment=increment)
        response['data'].append(result)
    return response
Esempio n. 21
0
def create_graph():
    new_graph = Graph(AdjList={}, pub_date=timezone.now())
    new_graph.save()
    return new_graph.id
Esempio n. 22
0
def remove(client, id):
    graph = Graph.get(client=client, id=id)
    graph.delete()
    return {'status': 'deleted'}
Esempio n. 23
0
    def restore_object( self, attrs, instance=None ):
        graph_id = attrs.get( 'graph_id' ) if attrs.get( 'graph_id' )\
                else helper_util.gen_id()
        if Graph.objects.filter( graph_id = graph_id ).count() < 1:
            instance = Graph.objects.get( graph_id = graph_id )
            if instance.last_updated > attrs.get( 'last_updated' ):
                return instance
        else:
            instance = Graph( graph_id = graph_id )

        instance.in_progress = attrs.get( 'in_progress' )
        instance.matrix_size = attrs.get( 'matrix_size' )
        instance.graph = attrs.get( 'graph' )
        instance.last_updated = attrs.get( 'last_updated' )
        instance.coin_id = attrs.get( 'coin_id' )
        instance.coin_status = attrs.get( 'coin_status' )
        instance.error_code = attrs.get( 'error_code' )
        instance.is_solution = attrs.get( 'is_solution' )
        instance.passed_isomorph_check = attrs.get( 'passed_isomorph_check' )
        instance.is_to_validation = attrs.get( 'is_to_validation' )
        instance.is_synced = attrs.get( 'is_synced' )

        return instance