def delete_recipe(recipe_id): recipe_db = mongo.db.recipes.find_one_and_delete( {'_id': ObjectId(recipe_id)}) form = ConfirmDelete(data=recipe_db) if form.validate_on_submit(): recipes_db = mongo.db.recipes_db recipes_db.delete_one({'_id': ObjectId(recipe_id)}) return redirect( url_for('get_all_recipes', title='Updated List of Recipes')) return render_template('delete_recipe.html', title="delete recipe", recipe=recipe_db, form=form)
def delete_lock(lock_id): lock_db = mongo.db.Locks.find_one_or_404({'_id': ObjectId(lock_id)}) if request.method == 'GET': form = ConfirmDelete(data=lock_db) return render_template('delete_lock.html', form=form) form = ConfirmDelete(request.form) if form.validate_on_submit(): locks_db = mongo.db.Locks locks_db.delete_one({ '_id': ObjectId(lock_id), }) return redirect(url_for('index')) return render_template('delete_lock.html', lock=lock_db, form=form)
def delete_film(film_id): film_db = mongo.db.films.find_one_or_404({'_id': ObjectId(film_id)}) if request.method == 'GET': form = ConfirmDelete(data=film_db) return render_template('deletefilm.html', title="Delete film", form=form) form = ConfirmDelete(request.form) if form.validate_on_submit(): films_db = mongo.db.films films_db.delete_one({ '_id': ObjectId(film_id), }) return redirect(url_for('index')) return render_template('deletefilm.html', film=film_db, form=form)
def delete_recipe(recipe_id): """Allows logged in user to delete one of their recipes with added confirmation""" recipe_db = mongo.db.recipes.find_one_or_404({'_id': ObjectId(recipe_id)}) if request.method == 'GET': form = ConfirmDelete(data=recipe_db) return render_template('delete_recipe.html', title="Delete Recipe", form=form) form = ConfirmDelete(request.form) if form.validate_on_submit(): recipes_db = mongo.db.recipes recipes_db.delete_one({ '_id': ObjectId(recipe_id), }) return redirect(url_for('index', title='Recipe Updated')) return render_template('delete_recipe.html', title="delete recipe", recipe=recipe_db, form=form)
def delete_movie(movie_id): """Allows logged in user to delete one of their recipes with added confirmation""" movie_db = mongo.db.movies.find_one_or_404({'_id': ObjectId(movie_id)}) if request.method == 'GET': form = ConfirmDelete(data=movie_db) return render_template('delete_movie.html', title="Magnificient 7", form=form) form = ConfirmDelete(request.form) if form.validate_on_submit(): movies_db = mongo.db.movies movies_db.delete_one({ '_id': ObjectId(movie_id), }) return redirect(url_for('index', title='Movie-App Updated')) return render_template('delete_movie.html', title="delete movie", movie=movie_db, form=form)
def delete_film(film_id): # get the film object film_db = mongo.db.films.find_one_or_404({'_id': ObjectId(film_id)}) if request.method == 'GET': form = ConfirmDelete(data=film_db) # send film to delete template return render_template('deletefilm.html', title="Delete film", form=form) # get the form form = ConfirmDelete(request.form) # check form validates corrrectly if form.validate_on_submit(): films_db = mongo.db.films films_db.delete_one({ '_id': ObjectId(film_id), }) # film successfully deleted redirect to index return redirect(url_for('index')) # send film to delete template return render_template('deletefilm.html', film=film_db, form=form)
def delete_recipe(recipe_id): '''Delete a recipe with added confirmation''' recipe_db = mongo.db.Recipes.find_one_or_404({'_id': ObjectId(recipe_id)}) if request.method == 'GET': form = ConfirmDelete(data=recipe_db) return render_template('delete_recipe.html', title='Delete Recipe', context=recipe_db, form=form) form = ConfirmDelete(request.form) if request.method == 'POST': recipe_db = mongo.db.Recipes recipe_db.delete_one({ '_id': ObjectId(recipe_id), }) return redirect(url_for('index', condition='Welsh Recipes Updated')) return render_template('delete_recipe.html', title='delete recipe', recipe=recipe_db, form=form)