示例#1
0
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")
示例#2
0
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])    
示例#3
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])
示例#4
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)
示例#5
0
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))
示例#6
0
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))
示例#7
0
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")
示例#8
0
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)
示例#9
0
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)