def delete_user(id): mysql = connectToMySQL('manage_users') query = "DELETE FROM users WHERE id = %(user_id)s" data = { "user_id": id } user = mysql.query_db(query, data) return redirect("/users")
def edit_user(id): query = "SELECT * FROM users WHERE id = %(user_id)s" data = { 'user_id': id } mysql = connectToMySQL('manage_users') user = mysql.query_db(query, data) return render_template("edit_user.html", user = user[0])
def view_user(id): mysql = connectToMySQL('manage_users') query = "SELECT * FROM users WHERE id = %(user_id)s" data = { "user_id": id } user = mysql.query_db(query, data) return render_template("user_profile.html", user = user[0])
def display_newly_added_user(id): mysql = connectToMySQL('users_assignment') query = "SELECT * FROM users WHERE id = :specific_id LIMIT 1;" data = { "specific_id": id } user = mysql.query_db(query,data) print(user) return render_template("users_id.html", id = id, user = user)
def insert_user(): mysql = connectToMySQL("manage_users") query = "INSERT INTO users (first_name, last_name, email, created_at) VALUES (%(fn)s, %(ln)s, %(em)s, NOW());" data = { "fn": request.form["fname"], "ln": request.form["lname"], "em": request.form["email"] } id = mysql.query_db(query, data) return redirect("/users/{}".format(id))
def update_user(id): mysql = connectToMySQL('manage_users') query = "UPDATE users SET first_name=%(fn)s, last_name=%(ln)s, email=%(em)s, updated_at = NOW() WHERE id = %(user_id)s" data = { 'fn': request.form['fname'], 'ln': request.form['lname'], 'em': request.form['email'], 'user_id': id } mysql.query_db(query, data) return redirect('/users/{}'.format(id))
def add_new_user_to_db(): mysql = connectToMySQL('users_assignment') print("\nAdded" + request.form["fname"] + "to database") print(request.form) query = "INSERT INTO users (first_name, last_name, email, created_at, updated_at) VALUES (%(fn)s, %(ln)s, %(email)s, NOW(), NOW());" data = { "fn": request.form["fname"], "ln": request.form["lname"], "email": request.form["email"] } mysql.query_db(query, data) # name = session(request.form["fname"]) return redirect("/users/id")
def display_users(): mysql = connectToMySQL("manage_users") users = mysql.query_db("SELECT users.id, concat(users.first_name, ' ', users.last_name) AS full_name, users.email, users.created_at FROM users") print(users) return render_template("users.html", all_users = users)
def display_all_users(): print("\nDisplaying new user") mysql = connectToMySQL('users_assignment') users = mysql.query_db('SELECT * FROM users;') print(users) return render_template("users.html", all_users = users)