(self, sketch_id, graph_id)
return jsonify(response)
Handles GET request to the resource.

        Returns:
            List of graphs in JSON (instance of flask.wrappers.Response)
Handles GET request to the resource.
Handles GET request to the resource .
def get(self, sketch_id, graph_id):
        """Handles GET request to the resource.

        Returns:
            List of graphs in JSON (instance of flask.wrappers.Response)
        """
        args = self.parser.parse_args()
        output_format = args.get('format', None)

        sketch = Sketch.query.get_with_acl(sketch_id)
        if not sketch:
            abort(HTTP_STATUS_CODE_NOT_FOUND, 'No sketch found with this ID.')

        graph = Graph.query.get(graph_id)
        if not graph:
            abort(HTTP_STATUS_CODE_NOT_FOUND, 'No graph found with this ID.')

        if not sketch.id == graph.sketch.id:
            abort(
                HTTP_STATUS_CODE_BAD_REQUEST,
                'Graph does not belong to this sketch.')

        # If requested use a format suitable for the CytoscapeJS frontend.
        if output_format == 'cytoscape':
            response = self.to_json(graph).json
            response['objects'][0]['graph_elements'] = graph.graph_elements
            return jsonify(response)

        # Reformat elements to work with networkx python library.
        # TODO: Change frontend to save directed and multigraph attributes.
        graph_elements = json.loads(graph.graph_elements)
        formatted_graph = {
            'data': [],
            'directed': True,
            'multigraph': True,
            'elements': {
                'nodes': [],
                'edges': []
            }
        }
        for element in graph_elements:
            group = element['group']
            element_data = {'data': element['data']}
            formatted_graph['elements'][group].append(element_data)

        response = self.to_json(graph).json
        response['objects'][0]['graph_elements'] = formatted_graph
        response['objects'][0]['graph_config'] = graph.graph_config

        # Update the last activity of a sketch.
        utils.update_sketch_last_activity(sketch)

        return jsonify(response)
def get ( self , sketch_id , graph_id ) : args = self . parser . parse_args ( ) output_format = args . get ( 'format' , None ) sketch = Sketch . query . get_with_acl ( sketch_id ) if not sketch : abort ( HTTP_STATUS_CODE_NOT_FOUND , 'No sketch found with this ID.' ) graph = Graph . query . get ( graph_id ) if not graph : abort ( HTTP_STATUS_CODE_NOT_FOUND , 'No graph found with this ID.' ) if not sketch . id == graph . sketch . id : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'Graph does not belong to this sketch.' ) # If requested use a format suitable for the CytoscapeJS frontend. if output_format == 'cytoscape' : response = self . to_json ( graph ) . json response [ 'objects' ] [ 0 ] [ 'graph_elements' ] = graph . graph_elements return jsonify ( response ) # Reformat elements to work with networkx python library. # TODO: Change frontend to save directed and multigraph attributes. graph_elements = json . loads ( graph . graph_elements ) formatted_graph = { 'data' : [ ] , 'directed' : True , 'multigraph' : True , 'elements' : { 'nodes' : [ ] , 'edges' : [ ] } } for element in graph_elements : group = element [ 'group' ] element_data = { 'data' : element [ 'data' ] } formatted_graph [ 'elements' ] [ group ] . append ( element_data ) response = self . to_json ( graph ) . json response [ 'objects' ] [ 0 ] [ 'graph_elements' ] = formatted_graph response [ 'objects' ] [ 0 ] [ 'graph_config' ] = graph . graph_config # Update the last activity of a sketch. utils . update_sketch_last_activity ( sketch ) return jsonify ( response )