def put_mold(wikia_name, mold_name): if request.content_type != 'application/json': response.status = 400 response.body = "Only Content-Type: application/json is permitted for this resource" return response if request.json is None: response.status = 400 response.body = "invalid json in request" return response db_connection = get_connection(CONFIG) wikia = Wikia() try: wikia.load_by_name(db_connection, wikia_name) except WikiaNotFoundException: response.status = 404 response.body = "Wikia not found" return response mold = Mold() try: mold.init_from_data(db_connection, wikia, mold_name, request.json) except MoldIncompleteException: response.status = 400 response.body = "Incomplete mold data given for PUT" return response mold.save(db_connection) response.status = 201 response.headers['Location'] = request.url return response
def delete_mold(wikia_name, mold_name): db_connection = get_connection(CONFIG) wikia = Wikia() try: wikia.load_by_name(db_connection, wikia_name) except WikiaNotFoundException: response.status = 200 return response mold = Mold() try: mold.load_by_name(db_connection, wikia, mold_name) except MoldNotFoundException: response.status = 200 return response mold.delete(db_connection) response.status = 204 return response
def get_mold(wikia_name, mold_name): db_connection = get_connection(CONFIG) wikia = Wikia() try: wikia.load_by_name(db_connection, wikia_name) except WikiaNotFoundException: response.status = 404 response.body = "Wikia not found" return response mold = Mold() try: mold.load_by_name(db_connection, wikia, mold_name) except MoldNotFoundException: response.status = 404 response.body = "Mold not found" return response view = MoldView(mold) return view.render_json()