def delete(self, id): task = DB.find_one("Tasks", {"_id": id}) if task: DB.remove("Tasks", {"_id": id}) return jsonify("Task removed") return jsonify("No task matching given id")
def delete_poll(poll): user = DB.find_one(collection="Profile", query={"email": current_user.email}) if user is None: flash('Please create your profile first!') return redirect(url_for('edit_profile')) toDelete = DB.find_one(collection='Poll', query={'_id': ObjectId(poll)}) if toDelete is None: flash('Please contact admin, DB error!') return redirect(url_for('polls')) for voter in toDelete['voters']: toRemove = DB.find_one(collection="Profile", query={"_id": voter}) if toRemove is None: flash('Please contact admin, DB error!') return redirect(url_for('polls')) DB.update_one(collection="Profile", filter={'_id': voter}, data={"$pull": { "polls": ObjectId(poll) }}) DB.update_one(collection="Profile", filter={'_id': user['_id']}, data={"$pull": { "polls": ObjectId(poll) }}) DB.remove(collection="Poll", condition={"_id": ObjectId(poll)}) flash('Deleted Poll!') return redirect(url_for('polls'))
def delete_event(id): user = DB.find_one(collection="Profile", query={"email": current_user.email}) if user is None: flash('Please create your profile first!') return redirect(url_for('edit_profile')) #delete the event from the id #first go through all the users that is associated with that id x = DB.find_one(collection="Events", query={"_id": ObjectId(id)}) profileList = x['invitees'] # Delete the event from all users in profile for profile in profileList: DB.update_one(collection="Profile", filter={"email": profile['email']}, data={"$pull": { "events": ObjectId(id) }}) #delete the actual event from the database DB.remove(collection="Events", condition={"_id": ObjectId(id)}) return redirect(url_for("view_events"))