(self, sketch_id)
return self.to_json(graph, status_code=HTTP_STATUS_CODE_CREATED)
Handles POST request to the resource.
Handles POST request to the resource.
Handles POST request to the resource .
def post(self, sketch_id):
        """Handles POST request to the resource."""
        sketch = Sketch.query.get_with_acl(sketch_id)
        if not sketch:
            abort(HTTP_STATUS_CODE_NOT_FOUND, 'No sketch found with this ID.')

        if not sketch.has_permission(current_user, 'write'):
            abort(HTTP_STATUS_CODE_FORBIDDEN,
                  'User does not have write access on sketch.')

        form = request.json

        name = form.get('name')
        description = form.get('description')
        elements = form.get('elements')
        graph_config = form.get('graph_config')

        if graph_config:
            if isinstance(graph_config, dict):
                graph_json = json.dumps(graph_config)
            elif isinstance(graph_config, str):
                graph_json = graph_config
            else:
                graph_json = ''
                logger.warning(
                    'Graph config not of the correct value, not saving.')
        else:
            graph_json = ''

        graph = Graph(
            user=current_user, sketch=sketch, name=str(name),
            graph_config=graph_json,
            description=description,
            graph_elements=json.dumps(elements))

        db_session.add(graph)
        db_session.commit()

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

        return self.to_json(graph, status_code=HTTP_STATUS_CODE_CREATED)
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.' ) if not sketch . has_permission ( current_user , 'write' ) : abort ( HTTP_STATUS_CODE_FORBIDDEN , 'User does not have write access on sketch.' ) form = request . json name = form . get ( 'name' ) description = form . get ( 'description' ) elements = form . get ( 'elements' ) graph_config = form . get ( 'graph_config' ) if graph_config : if isinstance ( graph_config , dict ) : graph_json = json . dumps ( graph_config ) elif isinstance ( graph_config , str ) : graph_json = graph_config else : graph_json = '' logger . warning ( 'Graph config not of the correct value, not saving.' ) else : graph_json = '' graph = Graph ( user = current_user , sketch = sketch , name = str ( name ) , graph_config = graph_json , description = description , graph_elements = json . dumps ( elements ) ) db_session . add ( graph ) db_session . commit ( ) # Update the last activity of a sketch. utils . update_sketch_last_activity ( sketch ) return self . to_json ( graph , status_code = HTTP_STATUS_CODE_CREATED )