def mentor_list(): user = session['user'] if user['type'] != 'Manager': return redirect(url_for('index')) return render_template('mentor_list.html', mentors=Mentor.get_list_of_mentors(), user=user)
def remove_mentor(user_id): user = session['user'] if user['type'] == 'Manager': mentor = Mentor.get_mentor_by_id(user_id) mentor.delete() return redirect(url_for('mentor_list')) return redirect(url_for('error.html'))
def details_mentor(user_id): user = session['user'] if user['type'] == 'Manager': mentor_url = "mentor_list" return render_template('details_mentor.html', person=Mentor.get_mentor_by_id(user_id), url=mentor_url, user=user) return redirect(url_for('error.html'))
def add_mentor(): user = session['user'] if user['type'] == 'Manager': mentor_url = "mentor_list" if request.method == "POST": user_id = None login = request.form['login'] email = request.form['email'] name = request.form['name'] surname = request.form['surname'] date_of_birth = None city = None phone = None new_mentor = Mentor(user_id, name, surname, email, date_of_birth, city, phone, login) new_mentor.save() return redirect(url_for(mentor_url)) return render_template('add_mentor.html', url=mentor_url, user=user) return redirect(url_for('error.html'))
def delete_mentor(employee_id): """ Remove mentor from list(data base) :param employee_id: int GET return list of mentors without removed mentor """ mentor = Mentor.get_by_id(employee_id) mentor.delete_employee() flash('Mentor was deleted') return redirect(url_for('employee_controller.list_mentors'))
def list_mentors(): """ GET to generate a list of mentors """ mentors_list = Mentor.list_mentors() add = 'employee_controller.add_mentor' edit = 'employee_controller.edit_mentor' delete = 'employee_controller.delete_mentor' return render_template('viewemployee.html', user=user_session(session['user'], session['type']), employee_list=mentors_list, employee='Mentor', add=add, edit=edit, delete=delete)
def edit_mentor(employee_id): """ Edit mentor formula to edit mentor details :param employee_id: int GET return edit mentor formula POST return list of mentors with edited mentor changes saved """ mentor = Mentor.get_by_id(employee_id) if request.method == 'POST': save_employee('mentor', 'edit', mentor) flash('Mentor was edited') return redirect(url_for('employee_controller.list_mentors')) return render_template('editemployee.html', user=user_session(session['user'], session['type']), employee=mentor, list='employee_controller.list_mentors')
def user_session(id, class_name): """Return object with given class name in class_name and id""" if class_name == "Student": return Student.get_by_id(id) elif class_name == "Mentor": return Mentor.get_by_id(id) elif class_name == "Employee": return Employee.get_by_id(id, 'assistant') elif class_name == "Manager": return Manager.get_by_id(id) return None
def schedule(cls): """finds free interviews and assigns applicant and mentor with matching city""" a_notin_is = Applicant.select().join(cls, JOIN.LEFT_OUTER).where(cls.applicant==None) for a in a_notin_is: if a.school is not None: try: mentor = Mentor.get(Mentor.school==a.school) interview_slot = InterviewSlot.get(InterviewSlot.location==a.school) except Mentor.DoesNotExist: return 'No available mentor.' except InterviewSlot.DoesNotExist: return 'No available interview time slot.' cls.insert(applicant=a.id, mentor=mentor.id, interview_slot=interview_slot.id).execute() interview_slot.update_to_reserved() else: return 'Assign closest school to applicants first.'
def create_mentor(cls): for m in cls.mentor_list: mentor = Mentor.create(name=m['name'], school=m['school'])