Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def update_employees(request, id ):
- if request.session['username'] != "cm_abrar":
- return redirect(customer_view.login)
- else:
- if request.method == "POST" and 'Click' in request.POST:
- print("ID is : ")
- print(id)
- name = request.POST['name']
- designation = request.POST['designation']
- salary = request.POST['salary']
- password = request.POST['password']
- username = request.POST['username']
- #
- branch = request.POST['branch']
- branch_no = branch[len(branch) - 1]
- #
- hashed_password = hashlib.md5(password.encode('utf-8')).hexdigest()
- if not name:
- sql = "SELECT NAME FROM EMPLOYEES WHERE EMPLOYEE_ID = %s"
- cursor = connection.cursor()
- result = cursor.execute(sql, [id])
- cursor.close()
- name = result[0][0]
- if not designation :
- sql = "SELECT DESIGNATION FROM EMPLOYEES WHERE EMPLOYEE_ID = %s"
- cursor = connection.cursor()
- result = cursor.execute(sql, [id])
- cursor.close()
- designation = result[0][0]
- if not salary:
- sql = "SELECT SALARY FROM EMPLOYEES WHERE EMPLOYEE_ID = %s"
- cursor = connection.cursor()
- result = cursor.execute(sql, [id])
- cursor.close()
- salary = result[0][0]
- if not password:
- sql = "SELECT PASSWORD FROM EMPLOYEES WHERE EMPLOYEE_ID = %s"
- cursor = connection.cursor()
- result = cursor.execute(sql, [id])
- cursor.close()
- hashed_password = result[0][0]
- if not username:
- sql = "SELECT USERNAME FROM EMPLOYEES WHERE EMPLOYEE_ID = %s"
- cursor = connection.cursor()
- result = cursor.execute(sql, [id])
- cursor.close()
- username = result[0][0]
- cursor = connection.cursor()
- sql = "UPDATE EMPLOYEES SET NAME = %s, DESIGNATION = %s, SALARY = %s, USERNAME = %s, PASSWORD = %s" \
- "WHERE EMPLOYEE_ID = %s"
- cursor.execute(sql, [name, designation, salary, username, hashed_password, id])
- connection.commit()
- cursor.close()
- redirect(show_employees)
- else:
- sql = "SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID = %s"
- cursor = connection.cursor()
- result = cursor.execute(sql, [id])
- name = result[0][1]
- designation = result[0][2]
- salary = result[0][3]
- username = result[0][6]
- cursor.close()
- # sql = "select BRANCH_ID FROM BRANCH B, BRANCH_EMPLOYEE BE WHERE BE.EMPLOYEE_ID = %s"
- # result = cursor.execute(sql,[id])
- # branch
- return(request, 'something.html', {name: 'name', designation: 'designation', salary: 'salary', username: 'username'})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement