(self, sketch_id)
return self.to_json(cache)
Handles POST request to the resource.

        Returns:
            Graph in JSON (instance of flask.wrappers.Response)
Handles POST request to the resource.
Handles POST request to the resource .
def post(self, sketch_id):
        """Handles POST request to the resource.

        Returns:
            Graph in JSON (instance of flask.wrappers.Response)
        """
        sketch = Sketch.query.get_with_acl(sketch_id)
        if not sketch:
            abort(HTTP_STATUS_CODE_NOT_FOUND, 'No sketch found with this ID.')

        form = request.json
        plugin_name = form.get('plugin')
        graph_config = form.get('config')
        refresh = form.get('refresh')
        timeline_ids = form.get('timeline_ids', None)

        if timeline_ids and not isinstance(timeline_ids, (list, tuple)):
            abort(
                HTTP_STATUS_CODE_BAD_REQUEST,
                'Timeline IDs if supplied need to be a list.')

        if timeline_ids and not all(
                [isinstance(x, int) for x in timeline_ids]):
            abort(
                HTTP_STATUS_CODE_BAD_REQUEST,
                'Timeline IDs needs to be a list of integers.')

        sketch_indices = [
            timeline.searchindex.index_name
            for timeline in sketch.active_timelines
        ]

        cache = GraphCache.get_or_create(
            sketch=sketch, graph_plugin=plugin_name)

        if graph_config:
            cache_config = graph_config
        else:
            cache_config = cache.graph_config

        if isinstance(cache_config, str):
            cache_config = json.loads(cache_config)

        # Refresh cache if timelines have been added/removed from the sketch.
        if cache_config:
            cache_graph_filter = cache_config.get('filter', {})
            cache_filter_indices = cache_graph_filter.get('indices', [])
            if set(sketch_indices) ^ set(cache_filter_indices):
                refresh = True

        if cache.graph_elements and not refresh:
            return self.to_json(cache)

        graph_class = manager.GraphManager.get_graph(plugin_name)
        graph = graph_class(sketch=sketch, timeline_ids=timeline_ids)
        cytoscape_json = graph.generate().to_cytoscape()

        if cytoscape_json:
            cache.graph_elements = json.dumps(cytoscape_json)
            cache.graph_config = json.dumps(graph_config)
            cache.update_modification_time()
            db_session.add(cache)
            db_session.commit()

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

        return self.to_json(cache)
def post ( self , sketch_id ) : sketch = Sketch . query . get_with_acl ( sketch_id ) if not sketch : abort ( HTTP_STATUS_CODE_NOT_FOUND , 'No sketch found with this ID.' ) form = request . json plugin_name = form . get ( 'plugin' ) graph_config = form . get ( 'config' ) refresh = form . get ( 'refresh' ) timeline_ids = form . get ( 'timeline_ids' , None ) if timeline_ids and not isinstance ( timeline_ids , ( list , tuple ) ) : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'Timeline IDs if supplied need to be a list.' ) if timeline_ids and not all ( [ isinstance ( x , int ) for x in timeline_ids ] ) : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'Timeline IDs needs to be a list of integers.' ) sketch_indices = [ timeline . searchindex . index_name for timeline in sketch . active_timelines ] cache = GraphCache . get_or_create ( sketch = sketch , graph_plugin = plugin_name ) if graph_config : cache_config = graph_config else : cache_config = cache . graph_config if isinstance ( cache_config , str ) : cache_config = json . loads ( cache_config ) # Refresh cache if timelines have been added/removed from the sketch. if cache_config : cache_graph_filter = cache_config . get ( 'filter' , { } ) cache_filter_indices = cache_graph_filter . get ( 'indices' , [ ] ) if set ( sketch_indices ) ^ set ( cache_filter_indices ) : refresh = True if cache . graph_elements and not refresh : return self . to_json ( cache ) graph_class = manager . GraphManager . get_graph ( plugin_name ) graph = graph_class ( sketch = sketch , timeline_ids = timeline_ids ) cytoscape_json = graph . generate ( ) . to_cytoscape ( ) if cytoscape_json : cache . graph_elements = json . dumps ( cytoscape_json ) cache . graph_config = json . dumps ( graph_config ) cache . update_modification_time ( ) db_session . add ( cache ) db_session . commit ( ) # Update the last activity of a sketch. utils . update_sketch_last_activity ( sketch ) return self . to_json ( cache )