def edit_details(): if (get_username() == ""): flash ("Please Login!") return redirect(url_for('auth.login')) username = get_username() emp = db.employee.find_one({"_id" : username}) first_name = emp['first_name'] last_name = emp['last_name'] email_id = emp['email_id'] no_awards = emp['no_awards'] no_publications = emp['no_publications'] no_researchs = emp['no_researchs'] no_projects = emp['no_projects'] biography = emp['biography'] form = EditDetailsForm(first_name = first_name, last_name = last_name, email_id = email_id, biography = biography, no_awards = no_awards, no_publications = no_publications, no_researchs = no_researchs, no_projects = no_projects) if form.validate_on_submit(): myquery = { "_id": username } newvalues = { "$set": { "first_name" : form.first_name.data, "last_name" : form.last_name.data, "email_id" : form.email_id.data, "biography" : form.biography.data, "no_awards" : form.no_awards.data, "no_publications" : form.no_publications.data, "no_researchs" : form.no_researchs.data, "no_projects" : form.no_projects.data} } db.employee.update_one(myquery, newvalues) cursor.execute("UPDATE employee SET first_name = %s, last_name = %s, email_id = %s WHERE employee_id = (%s)", (form.first_name.data, form.last_name.data, form.email_id.data, username)) conn.commit() return redirect(url_for('user.profile')) return render_template('user/profile/edit_basic_details.html', form=form, title="Edit Details" , username = username, isadmin = get_isadmin(), role = get_role())
def edit_ccf(position): if get_isadmin() == False: return redirect(url_for('home.error403')) add_ccf = False form = EditCCFForm() cursor.execute("SELECT * FROM ccf WHERE position = %s", (position, )) data = cursor.fetchone() if form.validate_on_submit(): cursor.execute( "INSERT INTO ccf_history(employee_id, position, time, start_date, end_date) VALUES(%s, %s, %s, %s, %s)", (data[0], data[1], (datetime.now()).strftime("%H:%M:%S"), data[2], date.today())) cursor.execute("UPDATE employee SET role = %s WHERE employee_id = %s", ('FACULTY', data[0])) cursor.execute("UPDATE employee SET role = %s WHERE employee_id = %s", (position, form.employee_id.data)) cursor.execute( "UPDATE ccf SET employee_id = %s, appointed_date = %s WHERE position = %s", (form.employee_id.data, date.today(), position)) conn.commit() flash('You have successfully updated the position!') return redirect(url_for('admin.list_ccf')) return render_template('admin/roles/ccfs.html', action="Edit", add_ccf=add_ccf, form=form, title="Edit CCF", username=get_username(), isadmin=get_isadmin())
def delete_route(role, start_route): if get_isadmin() == False: return redirect(url_for('home.error403')) cursor.execute("DELETE FROM route WHERE role = %s AND start_route = %s", (role, start_route)) conn.commit() flash('You have successfully deleted the route!') return redirect(url_for('admin.list_routes')) return render_template(title="Delete Position")
def list_routes(): if get_isadmin() == False: return redirect(url_for('home.error403')) cursor.execute("SELECT * FROM route ORDER BY role") routes = cursor.fetchall() return render_template('admin/route/route.html', routes=routes, title="Routes", username=get_username(), isadmin=get_isadmin())
def validate_position(self, field): cursor.execute("SELECT position FROM pos WHERE position = %s", (field.data, )) if cursor.fetchone() == None: raise ValidationError('Position does not exist!') cursor.execute("SELECT position FROM ccf WHERE position = %s", (field.data, )) if cursor.fetchone(): raise ValidationError('Position already appointed!')
def list_positions(): if get_isadmin() == False: return redirect(url_for('home.error403')) cursor.execute("SELECT * FROM pos ORDER BY position ASC;") positions = cursor.fetchall() return render_template('admin/positions/positions.html', positions=positions, title="Positions", username=get_username(), isadmin=get_isadmin())
def list_ccf(): if get_isadmin() == False: return redirect(url_for('home.error403')) cursor.execute("SELECT * FROM ccf ORDER BY position ASC") poss = cursor.fetchall() return render_template('admin/roles/ccf.html', poss=poss, title='CCF', username=get_username(), isadmin=get_isadmin())
def list_hod(): if get_isadmin() == False: return redirect(url_for('home.error403')) cursor.execute("SELECT * FROM hod ORDER BY department_id ASC") hods = cursor.fetchall() return render_template('admin/roles/hod.html', hods=hods, title='HOD', username=get_username(), isadmin=get_isadmin())
def validate_hod_id(self, field): cursor.execute( "SELECT employee_id FROM employee WHERE employee_id = %s", (field.data, )) if cursor.fetchone() == None: raise ValidationError('Employee does not exists!') cursor.execute("SELECT role FROM employee WHERE employee_id = %s", (field.data, )) if cursor.fetchone()[0] != 'FACULTY': raise ValidationError('Employee already holds another position!')
def validate_department_id(self, field): cursor.execute( "SELECT department_id FROM department WHERE department_id = %s", (field.data, )) if cursor.fetchone() == None: raise ValidationError('Department does not exist!') cursor.execute( "SELECT department_id FROM hod WHERE department_id = %s", (field.data, )) if cursor.fetchone(): raise ValidationError('HOD already appointed!')
def list_departments(): if get_isadmin() == False: return redirect(url_for('home.error403')) cursor.execute( "SELECT * FROM department WHERE department_id != 'NONE' ORDER BY department_id ASC;" ) departments = cursor.fetchall() return render_template('admin/departments/departments.html', departments=departments, title="Departments", username=get_username(), isadmin=get_isadmin())
def history_hod(): if get_isadmin() == False: return redirect(url_for('home.error403')) hod = True cursor.execute( "SELECT * FROM hod_history ORDER BY department_id ASC, start_date ASC, time ASC" ) history = cursor.fetchall() return render_template('admin/history/history.html', hod=hod, history=history, title="HOD History", username=get_username(), isadmin=get_isadmin())
def adminlogin(): form = LoginForm() if form.validate_on_submit(): cursor.execute( "SELECT employee_id FROM employee WHERE employee_id = %s", (form.username.data, )) if cursor.fetchone(): cursor.execute( "SELECT password FROM employee WHERE employee_id = %s", (form.username.data, )) if cursor.fetchone()[0] == form.password.data: cursor.execute( "SELECT isadmin FROM employee WHERE employee_id = %s", (form.username.data, )) if (cursor.fetchone()[0] == True): cursor.execute( "SELECT isadmin FROM employee WHERE employee_id = %s", (form.username.data, )) global username global role global isadmin role = cursor.fetchone()[0] isadmin = True username = form.username.data flash('You have successfully been successfully logged in!') return redirect(url_for('admin.dashboard')) flash('Invalid credentials!') return render_template('auth/login.html', form=form, title='Login', isadmin=isadmin, username=username, role=role)
def history_ccf(): if get_isadmin() == False: return redirect(url_for('home.error403')) hod = False cursor.execute( "SELECT * FROM ccf_history ORDER BY position ASC, start_date DESC, time ASC" ) history = cursor.fetchall() return render_template('admin/history/history.html', hod=hod, history=history, title="CCF History", username=get_username(), isadmin=get_isadmin())
def employees(): cursor.execute("SELECT * FROM employee ORDER BY employee_id ASC ") employees = cursor.fetchall() cursor.execute( "SELECT * FROM department WHERE department_id != 'NONE' ORDER BY department_id ASC" ) departments = cursor.fetchall() return render_template('about/employees.html', title='Employees', employees=employees, departments=departments, username=get_username(), isadmin=get_isadmin(), role=get_role())
def employees(): if get_isadmin() == False: return redirect(url_for('home.error403')) cursor.execute("SELECT * FROM employee ORDER BY employee_id ASC ") employees = cursor.fetchall() cursor.execute( "SELECT * FROM department WHERE department_id != 'NONE' ORDER BY department_id ASC" ) departments = cursor.fetchall() return render_template('admin/employees.html', employees=employees, departments=departments, title="Employees", username=get_username(), isadmin=get_isadmin())
def add_route(): if get_isadmin() == False: return redirect(url_for('home.error403')) form = AddRouteForm() if form.validate_on_submit(): cursor.execute( "INSERT INTO route(role, start_route, end_route) VALUES(%s, %s, %s)", (form.role.data, form.start_route.data, form.end_route.data)) conn.commit() flash("Route Added Successfully") return redirect(url_for('admin.list_routes')) return render_template('admin/route/routes.html', title="Add Route", form=form, username=get_username(), isadmin=get_isadmin())
def add_position(): if get_isadmin() == False: return redirect(url_for('home.error403')) form = AddPositionForm() if form.validate_on_submit(): cursor.execute( "INSERT INTO pos(position, position_name) VALUES(%s, %s)", (form.position_id.data, form.position_name.data)) conn.commit() flash('You have successfully added a new psoition!') return redirect(url_for('admin.list_positions')) return render_template('admin/positions/position.html', form=form, action="Add", title="Add Position", username=get_username(), isadmin=get_isadmin())
def delete_department(department_id): if get_isadmin() == False: return redirect(url_for('home.error403')) cursor.execute("SELECT * from employee WHERE department_id = %s", (department_id, )) employees = cursor.fetchone() if employees: flash( "To remove the department, first remove all faculties enrolled in that department." ) return redirect(url_for('home.error')) cursor.execute("DELETE FROM department WHERE department_id = %s", (department_id, )) conn.commit() flash('You have successfully deleted the department!') return redirect(url_for('admin.list_departments')) return render_template(title="Delete Department")
def add_department(): if get_isadmin() == False: return redirect(url_for('home.error403')) form = AddDepartmentForm() if form.validate_on_submit(): cursor.execute( "INSERT INTO department(department_id, department_name) VALUES(%s, %s)", (form.department_id.data, form.department_name.data)) conn.commit() flash('You have successfully added a new department!') return redirect(url_for('admin.list_departments')) return render_template('admin/departments/department.html', action="Add", form=form, title="Add Department", username=get_username(), isadmin=get_isadmin())
def add_ccf(): if get_isadmin() == False: return redirect(url_for('home.error403')) add_ccf = True form = AddCCFForm() if form.validate_on_submit(): cursor.execute( "INSERT INTO ccf(position, employee_id, appointed_date) VALUES(%s, %s, %s)", (form.position.data, form.employee_id.data, date.today())) cursor.execute("UPDATE employee SET role = %s WHERE employee_id = %s", (form.position.data, form.employee_id.data)) conn.commit() flash('You have successfully added a new position!') return redirect(url_for('admin.list_ccf')) return render_template('admin/roles/ccfs.html', action="Add", add_ccf=add_ccf, form=form, title="Add CCF", username=get_username(), isadmin=get_isadmin())
def delete_employee(employee_id): if get_isadmin() == False: return redirect(url_for('home.error403')) cursor.execute("DELETE FROM hod WHERE hod_id = %s", (employee_id, )) cursor.execute("DELETE FROM ccf WHERE employee_id = %s", (employee_id, )) cursor.execute("DELETE FROM leaves_left WHERE employee_id = %s", (employee_id, )) cursor.execute("DELETE FROM employee WHERE employee_id = %s", (employee_id, )) db.employee.remove({'_id': employee_id}) conn.commit() flash('You have successfully deleted the employee!') return redirect(url_for('admin.employees')) return render_template(title="Delete Department")
def add_hod(): if get_isadmin() == False: return redirect(url_for('home.error403')) add_hod = True form = AddHODForm() if form.validate_on_submit(): cursor.execute( "SELECT department_id FROM employee WHERE employee_id = %s", (form.hod_id.data, )) if cursor.fetchone()[0] == form.department_id.data: cursor.execute( "INSERT INTO hod(department_id, hod_id, appointed_date) VALUES(%s, %s, %s)", (form.department_id.data, form.hod_id.data, date.today())) cursor.execute( "UPDATE employee SET role = %s WHERE employee_id = %s", ( 'HOD', form.hod_id.data, )) conn.commit() flash('You have successfully added a new HOD!') else: flash('Invalid Entry!') return redirect(url_for('admin.list_hod')) return render_template('admin/roles/hods.html', action="Add", add_hod=add_hod, form=form, title="Add HOD", username=get_username(), isadmin=get_isadmin())
def delete_ccf(position): if get_isadmin() == False: return redirect(url_for('home.error403')) cursor.execute("SELECT * FROM ccf WHERE position = %s", (position, )) data = cursor.fetchone() cursor.execute( "INSERT INTO ccf_history(employee_id, position, time, start_date, end_date) VALUES(%s, %s, %s, %s, %s)", (data[0], data[1], (datetime.now()).strftime("%H:%M:%S"), data[2], date.today())) cursor.execute("DELETE FROM ccf WHERE position = %s", (position, )) cursor.execute( "UPDATE employee SET role = 'FACULTY' WHERE employee_id = %s", (data[0], )) conn.commit() flash('You have successfully deleted the ccf!') return redirect(url_for('admin.list_ccf')) return render_template(title="Delete CCF")
def delete_position(position_id): if get_isadmin() == False: return redirect(url_for('home.error403')) conn.commit() cursor.execute("UPDATE employee SET role = 'FACULTY' WHERE role = %s", (position_id, )) cursor.execute("DELETE FROM ccf WHERE position = %s", (position_id, )) cursor.execute("DELETE FROM pos WHERE position = %s", (position_id, )) flash('You have successfully deleted the position!') return redirect(url_for('admin.list_positions')) return render_template(title="Delete Position")
def my_applications(): if (get_username() == ""): flash ("Please Login!") return redirect(url_for('auth.login')) username = get_username() cursor.execute("SELECT * FROM leave_application WHERE employee_id = %s ORDER BY leave_id DESC", (username,)) leaves = cursor.fetchall() cursor.execute("SELECT * FROM comments ORDER BY leave_id DESC") comments = cursor.fetchall() cursor.execute("SELECT * FROM leaves_left WHERE employee_id = %s ORDER BY year ASC", (username,)) leaves_left = cursor.fetchall() return render_template('user/leaves/my_applications.html', leaves = leaves, comments = comments, leaves_left = leaves_left, title="My Application" , username = username, isadmin = get_isadmin(), role = get_role())
def delete_hod(department_id): if get_isadmin() == False: return redirect(url_for('home.error403')) cursor.execute("SELECT * FROM hod WHERE department_id = %s", (department_id, )) data = cursor.fetchone() cursor.execute( "INSERT INTO hod_history(hod_id, department_id, time, start_date, end_date) VALUES(%s, %s, %s, %s, %s)", (data[0], data[1], (datetime.now()).strftime("%H:%M:%S"), data[2], date.today())) cursor.execute("DELETE FROM hod WHERE department_id = %s", (department_id, )) cursor.execute( "UPDATE employee SET role = 'FACULTY' WHERE employee_id = %s", (data[0], )) conn.commit() flash('You have successfully deleted the HOD!') return redirect(url_for('admin.list_hod')) return render_template(title="Delete HOD")
def leave_requests(): if (get_username() == ""): flash ("Please Login!") return redirect(url_for('auth.login')) username = get_username() cursor.execute("SELECT leave_application.leave_id, leave_type, leave_application.employee_id, applied_date, start_date, end_date, status, application, leave_application.department_id FROM leave_application, leave_requests WHERE leave_requests.role = %s and leave_application.leave_id = leave_requests.leave_id", (get_role(),)) temp_requests = cursor.fetchall() requests = [] if get_role() == 'HOD': cursor.execute("SELECT department_id FROM employee WHERE employee_id = %s", (username,)) department_id = cursor.fetchone()[0] for request in temp_requests: if department_id == request[8]: requests.append(request) else : requests = temp_requests cursor.execute("SELECT * FROM comments ORDER BY leave_id DESC") comments = cursor.fetchall() return render_template('user/leaves/leave_requests.html', requests = requests, comments = comments, title="Leave Requests", username = username, isadmin = get_isadmin(), role = get_role())
def validate_username(self, field): cursor.execute( "SELECT employee_id FROM employee WHERE employee_id = %s", (field.data, )) if cursor.fetchone(): raise ValidationError('Username is already in use!')
def validate_department_id(self, field): cursor.execute( "SELECT department_id FROM department WHERE department_id = %s", (field.data, )) if (cursor.fetchone() is None): raise ValidationError('Department does not exist!')