def change_position(): form = ChangePositionForm() if form.validate_on_submit(): print('Change position validated') mongo_cursor = init.get_cursor() details = list( mongo_cursor.find({'faculty_id': (int)(form.faculty_id.data)})) if len(details) == 0: return render_template('error_template.html', error='Faculty-ID:' + form.faculty_id.data + 'does not exist in database') if form.dept_name.data == 'None' and form.position.data == 'HOD': return render_template( 'error_template.html', error='Please specify dept_name while changing HOD') if form.dept_name.data != details[0][ 'dept_name'] and form.position.data == 'HOD': return render_template( 'error_template.html', error='Faculty being made HOD should be of the same dept_name\n' + 'current dept_name of faculty:' + details[0]['dept_name'] + '\n dept_name being assigned:' + form.dept_name.data) admin_logic.change_faculty_position(form.position.data, form.dept_name.data, form.faculty_id.data) return render_template('change_position.html', form=form)
def hod_login(): form = HODLoginForm() if form.validate_on_submit(): print('Form validated succesfully') mongo_cursor = init.get_cursor() details = list( mongo_cursor.find({ 'position': 'HOD', 'dept_name': form.dept_name.data })) if len(details) == 0: return render_template('error_template.html', error='There is no HOD for ' + form.dept_name.data + ' dept_name') print(details) return redirect( url_for('viewLeaves', approver_name=details[0]['name'], position='HOD', dept_name=details[0]['dept_name'])) # viewLeaves(approver_name = details[0]['name'], position = 'HOD', dept_name = details[0]['dept_name']) return render_template('hod_login.html', form=form)
def view_leave_status(faculty_id): leave_details = faculty_logic.check_leave_status(faculty_id) mongo_cursor = init.get_cursor() details = list(mongo_cursor.find({'faculty_id': (int)(faculty_id)})) if len(leave_details) == 0: return render_template('error_template.html', error='No leave application') form = LeaveDetailsForm() if form.validate_on_submit(): name = details[0]['name'] print('Leave details form validated') add_comments((int)(leave_details['leave_id']), name + ': ' + form.comment.data + '\n') new_details = faculty_logic.check_leave_status(faculty_id) form.comment.data = '' ############################### return render_template('leave_details.html', leave_details=new_details, form=form, faculty_id=faculty_id, arr=details) ############################### return render_template('leave_details.html', leave_details=leave_details, form=form, faculty_id=faculty_id, arr=details)
def delete_faculty(): form = DeleteFacultyForm() if form.validate_on_submit(): mongo_cursor = init.get_cursor() details = list( mongo_cursor.find({'faculty_id': (int)(form.faculty_id.data)})) if len(details) == 0: return render_template('error_template.html', error='Faculty-ID:' + form.faculty_id.data + ' is not present in database') if details[0]['position'] == 'HOD' or details[0][ 'position'] == 'DFA' or details[0][ 'position'] == 'DSA' or details[0][ 'position'] == 'DIRECTOR': return (render_template( 'error_template.html', error='Cannot delete HOD account. Assign someone else as ' + details[0]['position'] + '( or add a new ' + details[0]['position'] + ') before deleting this account')) print('Deletion Form validated') admin_logic.delete_faculty_mongo(form.faculty_id.data) return render_template('admin_options.html') return render_template('delete_faculty.html', form=form)
def change_password(faculty_id): mongo_cursor = init.get_cursor() details = list(mongo_cursor.find({'faculty_id': (int)(faculty_id)})) form = ChangePasswordForm() if form.validate_on_submit(): print('Password change form validated') if len(details) == 0: return render_template('error_template.html', error='Faculty-ID:' + form.faculty_id.data + 'does not exist in database') if details[0][ 'password'] == form.current_password.data and form.new_password.data == form.confirm_new_password.data: mongo_cursor.update_one( {'faculty_id': (int)(faculty_id)}, {'$set': { 'password': form.new_password.data }}) return redirect(url_for('faculty')) return render_template('change_password.html', form=form, faculty_id=faculty_id, arr=details)
def update_leaves(faculty_id, leave_to_deduct): cursor = initialize.get_cursor() current_leaves = getRemainingLeaves(faculty_id) cursor.update_one( {'faculty_id': (int)(faculty_id)}, {'$set': { 'leaves_left': int(current_leaves) - int(leave_to_deduct) }})
def get_faculty_type(id): cursor = initialize.get_cursor() arr = list(cursor.find({'faculty_id': (int)(id)})) pos = arr[0]['position'] if (pos == 'Faculty'): return True else: return False
def view_faculty_mongo(): cursor = initialize.get_cursor() # faculty = cursor.find() # for i in faculty: # pprint.pprint(i) arr = list(cursor.find()) return arr
def update_faculty_detail(id, new_name, new_alma_mater, new_education): # id = (int)(input('Enter id:')) cursor = initialize.get_cursor() print('++++++++++++++++++') print(cursor) print('++++++++++++++++++') arr = list(cursor.find({'faculty_id': (int)(id)})) # result = contents.find({ # 'faculty_id': id # }) # arr = list(result) print('--------------------------------------------------') print(arr) print('--------------------------------------------------') faculty_id = arr[0]['faculty_id'] # print('Update Name?Y/n') # c = (input()) if new_name != 'default': name = new_name else: name = arr[0]['name'] # print('Update alma_mater?Y/n') # c = (input()) if new_alma_mater != 'default': alma_mater = new_alma_mater else: alma_mater = arr[0]['alma_mater'] # print('Update education?Y/n') # c = (input()) if new_education != 'default': education = new_education else: education = arr[0]['education'] # print('Update dept_name?Y/n') # c = (input()) # if c=='Y': # dept_name = input('Enter dept_name:') # else: # dept_name = arr[0]['dept_name'] cursor.update_one({'faculty_id': faculty_id}, { '$set': { 'name': name, 'alma_mater': alma_mater, 'education': education, } }) print('UPDATED DONE')
def delete_faculty_mongo(faculty_id): # print('Enter id') # faculty_id = (int)(input()) cursor = initialize.get_cursor() query = { 'faculty_id': (int)(faculty_id), } result = cursor.find(query) for i in result: pprint.pprint(i) cursor.delete_one(query)
def check_leave_status(id): # id = (int)(input('Enter id:')) # result = contents.find({ # 'faculty_id': id # }) cursor = initialize.get_cursor() arr = list(cursor.find({'faculty_id': (int)(id)})) print(arr) return leaves.leave_status(arr[0]['leave_id'])
def dean_login(): form = DeanLoginForm() if form.validate_on_submit(): print('Dean Login Succesful') mongo_cursor = init.get_cursor() details = list(mongo_cursor.find({'position': 'D' + form.area.data})) if len(details) == 0: return render_template('error_template.html', error='There is no D' + form.area.data) print(details) return redirect( url_for('viewLeaves', approver_name=details[0]['name'], position=details[0]['position'])) return render_template('dean_login.html', form=form)
def director_login(): form = DirectorLoginForm() if form.validate_on_submit(): print('Director Login Succesful') mongo_cursor = init.get_cursor() details = list(mongo_cursor.find({'position': 'Director'})) if len(details) == 0: return render_template('error_template.html', error='No Director has been appointed') print(details) return redirect( url_for('viewLeaves', approver_name=details[0]['name'], position=(details[0]['position']).upper())) return render_template('director_login.html', form=form)
def view_faculty_detail(id): #id = (int)(input('Enter id:')) cursor = initialize.get_cursor() print(cursor) print('id:' + id) # result = cursor.find({ # 'faculty_id': (int)(id) # }) # print('RESULT:') # print(result) # print('PRINTNG RESULT ELEMENTS') # for var in result: # pprint.pprint(var) ls = list(cursor.find({'faculty_id': (int)(id)})) print(ls) return ls
def add_faculty_mongo(new_name, new_alma_mater, new_education, new_dept_name, new_position): cursor = initialize.get_cursor() faculty_id = 0 arr = list(cursor.find().sort([('faculty_id', -1)]).limit(1)) if len(arr) == 0: faculty_id = 1 else: faculty_id = arr[0]['faculty_id'] + 1 name = new_name alma_mater = new_alma_mater education = new_education dept_name = new_dept_name leaves_left = default_leaves leave_id = None position = new_position password = '******' faculty = { 'faculty_id': faculty_id, 'name': name, 'alma_mater': alma_mater, 'education': education, 'dept_name': dept_name, 'leaves_left': leaves_left, 'leave_id': leave_id, 'position': position, 'password': password } result = cursor.insert_one(faculty) if result.acknowledged: print('Faculty added succesfully--ID:' + str(result.inserted_id))
def assign_leave_id(faculty_id, leave_id): cursor = initialize.get_cursor() cursor.update_one({'faculty_id': (int)(faculty_id)}, {'$set': { 'leave_id': (int)(leave_id) }})
def getRemainingLeaves(id): cursor = initialize.get_cursor() arr = list(cursor.find({'faculty_id': (int)(id)})) return arr[0]['leaves_left']
def change_faculty_position(req_position, req_dept, new_faculty_id): # position = input('Enter position to be modified:') cursor = initialize.get_cursor() if req_position == 'HOD': dept = req_dept # result = cursor.find({ # 'dept_name':dept # }) old_hod_id = -1 new_hod_id = (int)(new_faculty_id) arr = list(cursor.find({'dept_name': dept})) print(arr) for i in arr: if i['position'] == 'HOD': old_hod_id = i['faculty_id'] print('old hod id:' + str(old_hod_id)) print('new_hod_id:' + str(new_hod_id)) if old_hod_id != -1: cursor.update_one({'faculty_id': old_hod_id}, {'$set': { 'position': 'Faculty' }}) cursor.update_one({'faculty_id': new_hod_id}, {'$set': { 'position': 'HOD' }}) if old_hod_id != -1: leaves.update_position_history((int)(old_hod_id), 'HOD', req_dept) leaves.insert_position_history((int)(new_hod_id), 'HOD', req_dept) if req_position == 'DFA' or req_position == 'DSA' or req_position == 'ADFA' or req_position == 'DIRECTOR': dept = req_dept # result = cursor.find({ # 'dept_name':dept # }) old_id = -1 new_id = (int)(new_faculty_id) arr = list(cursor.find({'position': req_position})) print(arr) if len(arr) != 0: old_id = arr[0]['faculty_id'] # print('old hod id:' + str(old_hod_id)) # print('new_hod_id:' + str(new_hod_id)) if old_id != -1: cursor.update_one({'faculty_id': old_id}, {'$set': { 'position': 'Faculty' }}) cursor.update_one({'faculty_id': new_id}, {'$set': { 'position': req_position }}) if old_id != -1: leaves.update_position_history((int)(old_id), req_position) leaves.insert_position_history((int)(new_id), req_position) # def admin_func(contents): # print('admin access granted') # print('Enter 1 to add new faculty') # print('Enter 2 to view detailed profile') # print('Enter 3 to delete faculty') # print('Enter 4 to update cross-cutting faculty positions') # i = (int)(input()) # if i==1: # add_faculty_mongo(contents) # elif i==2: # view_faculty_mongo(contents) # elif i==3: # delete_faculty_mongo(contents) # elif i==4: # change_faculty_position(contents)
def get_dept_name(id): cursor = initialize.get_cursor() arr = list(cursor.find({'faculty_id': (int)(id)})) return arr[0]['dept_name']
def applyLeave(faculty_id): mongo_cursor = init.get_cursor() details = list(mongo_cursor.find({'faculty_id': (int)(faculty_id)})) leaveApplication = LeaveApplicationForm() if (not leaveApplication.validate_on_submit()): print('Invalid Form') return render_template('leaveApplication.html', form=leaveApplication, faculty_id=faculty_id, name=details[0]['name'], position=details[0]['position'], dept_name=details[0]['dept_name']) if len(details) == 0: return render_template('error_template.html', error='Faculty-ID:' + faculty_id + ' does not exist in database') dept_name = details[0]['dept_name'] if get_current_position_name(1) == 'HOD': status = 'AT HOD ' + dept_name else: status = 'AT ' + get_current_position_name(1) print('Status: ' + status) if faculty_logic.get_faculty_type(faculty_id) == False: status = 'AT DIRECTOR' start_date = leaveApplication.start_date.data end_date = leaveApplication.end_date.data leaves_left = faculty_logic.getRemainingLeaves(faculty_id) diff_date = end_date - start_date days_applied = diff_date.days default_leaves = 15 if (days_applied > leaves_left): if (days_applied < leaves_left + default_leaves): global s_d, e_d, rsn, stus s_d = start_date e_d = end_date rsn = leaveApplication.reason.data stus = status return redirect( url_for('borrowLeaves', faculty_id=faculty_id, days_applied=days_applied, leaves_left=leaves_left)) x = insert_leaves_table(leaveApplication.start_date.data, leaveApplication.end_date.data, leaveApplication.reason.data, faculty_id, status) print(x) if x != -1: faculty_logic.assign_leave_id(faculty_id, x) else: return redirect(url_for('leave_exists')) return redirect(url_for('home'))