def handle_post_reagent(s_id, r_id, client_state, username, body): ''' Function expects integers sequence id and reagent id. Function also expects a client state, a string username, and a string for the body sent with the POST request. Function calls save client and return then returns the output of the function called. ''' # Extract sequence and reagent IDs sequence_id = int(s_id) reagent_id = int(r_id) # Make sure we can edit this sequence sequence_metadata = db.get_sequence_metadata(sequence_id) if sequence_metadata["sequencetype"] != "Saved": raise Exception("Cannot edit sequence") # Save the reagent reagent = json.loads(body) db.update_reagent( reagent_id, reagent["name"], reagent["description"]) # Flag the sequence validation as dirty db.update_sequence_dirty_flag(sequence_id, True) # Return the new state return save_client_state_and_return(client_state, db, username)
def reagent_post_index(s_id, r_id): ''' Function shall handle all POST .../reagent/<reagent_id> web requests. Function expects integers sequence id and reagent id to be passed in as parameters. Function returns the output of save client state and return. The function obtains the data of the body sent with the POST request and updates the reagent on the database before calling save client state and return. ''' # Get objects auth = request.authorization username = str(auth.username) server_state = get_server_state(username) client_state = getCurrentClientState(username) # Get POST object body = request.data current_app.logger.debug("Body sent: " + str(body)) # Make sure we can edit this sequence sequence_metadata = db.get_sequence_metadata(int(s_id)) if sequence_metadata["sequencetype"] != "Saved": raise Exception("Cannot edit sequence") # Save the reagent reagent = json.loads(body) db.update_reagent( int(r_id), reagent["name"], reagent["description"]) # Flag the sequence validation as dirty db.update_sequence_dirty_flag(int(s_id), True) # Return the new state return save_client_state_and_return( client_state, username)