def mentor_shortlist(): if current_user.is_company(): cohort = Company.query.filter_by(email=current_user.email).first() mentors = Mentor.query.filter_by(cohort=cohort) prefMentors = [cohort.mentor1, cohort.mentor2, cohort.mentor3] elif current_user.is_admin(): mentors = None prefMentors = None elif current_user.is_mentor(): mentors = None prefMentors = None else: mentee = Mentee.query.filter_by(email=current_user.email).first() mentors = Mentor.query.filter_by(mentee=mentee) prefMentors = [mentee.mentor1, mentee.mentor2, mentee.mentor3] mentorList = [] for mentor in mentors: user = User.query.filter_by(email=mentor.email).first() # clean the data a bit before passing to mentees if current_user.access == 0: mentor.email = None mentor.email_hash = user.email_hash mentorList.append(mentor) return render_template('mentorshortlist.html', title='Mentor Shortlist', mentors=mentorList, prefMentors=prefMentors)
def redirect_job_index(): if current_user.is_admin(): return redirect(url_for('admin.job')) elif current_user.is_company(): return redirect(url_for('company.jobs')) else: return redirect(url_for('index.index'))
def redirect_job_index(): if current_user.is_admin(): return redirect(url_for("myadmin.job")) elif current_user.is_company(): return redirect(url_for("company.jobs")) else: return redirect(url_for("front.index"))
def edit_picture(): profile_pic_filepath = 'https://s3.ca-central-1.amazonaws.com/enlight-hub-profile-pictures/' if current_user.is_mentor(): profile_pic_filepath += 'mentors/' + str(current_user.email_hash) + '-profile-pic.png' elif current_user.is_company(): profile_pic_filepath += 'mentees/' + str(current_user.email_hash) + '-profile-pic.png' else: profile_pic_filepath += 'mentees/' + str(current_user.email_hash) + '-profile-pic.png' return render_template('edit_picture.html', title='Edit Profile Picture', profile_pic_filepath=profile_pic_filepath)
def shortlist(): if current_user.is_company(): return redirect(url_for('mentor_shortlist')) elif current_user.is_admin(): flash('Feature not available for admin.') return redirect(url_for('dashboard')) elif current_user.is_mentor(): return redirect(url_for('mentee_shortlist')) else: return redirect(url_for('mentor_shortlist'))
def homepage(): if current_user.is_admin(): return render_template('home_mentor.html', title='Home') elif current_user.is_mentor(): return render_template('home_mentor.html', title='Home') elif current_user.is_company(): return render_template('home_cohort.html', title='Home') else: app = Application.query.filter_by(email=current_user.email).first() return render_template('home_gm.html', title='Home', app=app)
def save_pref(Id): if current_user.is_mentor(): mentor = Mentor.query.filter_by(email=current_user.email).first() if not mentor.mentee1 and mentor.mentee1 != Id: mentor.mentee1 = Id flash('Added to preferred mentees') elif not mentor.mentee2 and mentor.mentee2 != Id: mentor.mentee2 = Id flash('Added to preferred mentees') elif not mentor.mentee3 and mentor.mentee3 != Id: mentor.mentee3 = Id flash('Added to preferred mentees') else: flash('You already have 3 preferred mentees') db.session.commit() return redirect(url_for('mentee_shortlist')) elif current_user.is_company(): cohort = Cohort.query.filter_by(email=current_user.email).first() if not cohort.mentor1 and cohort.mentor1 != Id: cohort.mentor1 = Id flash('Added to preferred mentors') elif not cohort.mentor2 and cohort.mentor2 != Id: cohort.mentor2 = Id flash('Added to preferred mentors') elif not cohort.mentor3 and cohort.mentor3 != Id: cohort.mentor3 = Id flash('Added to preferred mentors') else: flash('You already have 3 preferred mentors') db.session.commit() return redirect(url_for('mentor_shortlist')) elif current_user.is_admin(): flash('Feature not available.') else: mentee = Mentee.query.filter_by(email=current_user.email).first() if not mentee.mentor1 and mentee.mentor1 != Id: mentee.mentor1 = Id flash('Added to preferred mentors') elif not mentee.mentor2 and mentee.mentor2 != Id: mentee.mentor2 = Id flash('Added to preferred mentors') elif not mentee.mentor3 and mentee.mentor3 != Id: mentee.mentor3 = Id flash('Added to preferred mentors') else: flash('You already have 3 preferred mentors') db.session.commit() return redirect(url_for('mentor_shortlist'))
def del_mentorpref(mentorId): user = User.query.filter_by(email_hash=mentorId).first() mentor = Mentor.query.filter_by(email=user.email).first() if current_user.is_company(): cohort = Company.query.filter_by(email=current_user.email).first() mentor.cohort = None db.session.commit() flash('Removed from shortlist.') elif current_user.is_admin(): flash('Feature not available.') elif current_user.is_mentor(): flash('Removed from shortlist.') else: mentee = Mentee.query.filter_by(email=current_user.email).first() mentor.mentee = None db.session.commit() flash('Shortlist has been updated.') return redirect(url_for('mentor_list'))
def del_pref(Id): if current_user.is_mentor(): mentor = Mentor.query.filter_by(email=current_user.email).first() if mentor.mentee1 == Id: mentor.mentee1 = None flash('Removed from preferred mentees') elif mentor.mentee2 == Id: mentor.mentee2 = None flash('Removed from preferred mentees') elif mentor.mentee3 == Id: mentor.mentee3 = None flash('Removed from preferred mentees') db.session.commit() return redirect(url_for('mentee_shortlist')) elif current_user.is_company(): cohort = Cohort.query.filter_by(email=current_user.email).first() if cohort.mentor1 == Id: cohort.mentor1 = None flash('Removed from preferred mentors') elif cohort.mentor2 == Id: cohort.mentor2 = None flash('Removed from preferred mentors') elif cohort.mentor3 == Id: cohort.mentor3 = None flash('Removed from preferred mentors') db.session.commit() return redirect(url_for('mentor_shortlist')) elif current_user.is_admin(): flash('Feature not available.') else: mentee = Mentee.query.filter_by(email=current_user.email).first() if mentee.mentor1 == Id: mentee.mentor1 = None flash('Removed from preferred mentors') elif mentee.mentor2 == Id: mentee.mentor2 = None flash('Removed from preferred mentors') elif mentee.mentor3 == Id: mentee.mentor3 = None flash('Removed from preferred mentors') db.session.commit() return redirect(url_for('mentor_shortlist'))
def company_user(companyId): company = Company.query.filter_by(id=companyId).first() try: # check if user is defined company.email except AttributeError: return render_template('404.html') memberList = Mentee.query.filter_by(company_l=company) if memberList: for member in memberList: user = User.query.filter_by(email=member.email).first() member.email_hash = user.email_hash user = None # pass mentee info if current user is company if current_user.is_company(): user = Mentee.query.filter_by(email=current_user.email).first() return render_template('company_profile.html', title='Company Profile', company=company, members=memberList, user=user)
def upload(): s3 = boto3.resource('s3') s3_filename = str(current_user.email_hash) + "-profile-pic.png" if current_user.is_mentor(): s3.Bucket('enlight-hub-profile-pictures').put_object(Key='mentors/' + s3_filename, Body=request.files['myfile']) form = EditMentorProfileForm(current_user.email) info = Mentor.query.filter_by(email=current_user.email).first() form.email.data = current_user.email form.first_name.data = info.first_name form.last_name.data = info.last_name form.about_me.data = info.about_me form.avail.data = info.avail form.skill.data = info.skill form.industry.data = info.industry form.company.data = info.company form.position.data = info.position form.linked.data = info.linked form.twitter.data = info.twitter elif current_user.is_company(): s3.Bucket('enlight-hub-profile-pictures').put_object(Key='mentees/' + s3_filename, Body=request.files['myfile']) form = EditCohortProfileForm(current_user.email) info = Cohort.query.filter_by(email=current_user.email).first() form.email.data = current_user.email form.company_name.data = info.company form.founder_names.data = info.founder form.industry.data = info.industry form.team_skills.data = info.skills form.help_needed.data = info.help_req else: s3.Bucket('enlight-hub-profile-pictures').put_object(Key='mentees/' + s3_filename, Body=request.files['myfile']) form = EditMenteeProfileForm(current_user.email) info = Mentee.query.filter_by(email=current_user.email).first() form.email.data = current_user.email form.company_name.data = info.company form.founder_names.data = info.founder form.industry.data = info.industry form.team_skills.data = info.skills form.help_needed.data = info.help_req flash('Profile picture successfully uploaded. Please allow some time for profile to update.') return redirect(url_for('edit_profile'))
def mentor_list(): mentorList = Mentor.query.all() cohort = None mentee = None for mentor in mentorList: user = User.query.filter_by(email=mentor.email).first() # clean the data a bit before passing to mentees if current_user.access == 0: mentor.email = None mentor.email_hash = user.email_hash mentor.mentees = [] for m in mentor.users: mentee = Mentee.query.filter_by(email=m.email).first() mentor.mentees.append(mentee) if current_user.is_company(): cohort = Company.query.filter_by(email=current_user.email).first() elif current_user.is_admin(): print('no data to grab') elif current_user.is_mentor(): print('no data to grab') else: mentee = Mentee.query.filter_by(email=current_user.email).first() return render_template('mentorlist.html', title='Mentor List', mentors=mentorList, menteeInfo=mentee, cohortInfo=cohort)
def edit_profile(): profile_pic_filepath = 'https://s3.ca-central-1.amazonaws.com/enlight-hub-profile-pictures/' if current_user.is_admin(): return render_template('404.html') elif current_user.is_mentor(): form = EditMentorProfileForm(current_user.email) info = Mentor.query.filter_by(email=current_user.email).first() profile_pic_filepath += 'mentors/' + str(current_user.email_hash) + '-profile-pic.png' if form.validate_on_submit(): current_user.email = form.email.data current_user.set_id() info.first_name = form.first_name.data info.last_name = form.last_name.data info.email = form.email.data info.about_me = form.about.data info.headline = form.headline.data info.avail = form.avail.data info.skill = form.skill.data info.mentor_company = form.company.data info.position = form.position.data info.industry = dict(form.industry.choices).get(form.industry.data) info.university = dict(form.university.choices).get(form.university.data) info.major = dict(form.major.choices).get(form.major.data) info.grad_year = form.grad_year.data info.linkedin = form.linkedin.data info.twitter = form.twitter.data db.session.commit() flash('Your changes have been saved.') return redirect(url_for('user', userId=current_user.email_hash)) elif request.method == 'GET': form.first_name.data = info.first_name form.last_name.data = info.last_name form.email.data = current_user.email form.headline.data = info.headline form.about.data = info.about_me form.avail.data = info.avail form.skill.data = info.skills form.company.data = info.mentor_company form.position.data = info.position form.industry.data = info.industry form.university.data = info.university form.major.data = info.major form.grad_year.data = info.grad_year form.linkedin.data = info.linkedin form.twitter.data = info.twitter return render_template('edit_profile.html', title='Edit Profile', form=form) elif current_user.is_company(): form = EditCohortProfileForm(current_user.email) info = Company.query.filter_by(email=current_user.email).first() if form.validate_on_submit(): current_user.email = form.email.data current_user.set_id() info.email = form.email.data info.company = form.company_name.data info.members = form.member_names.data info.industry = dict(form.industry.choices).get(form.industry.data) info.help_req = form.help_needed.data db.session.commit() flash('Your changes have been saved.') return redirect(url_for('user', userId=current_user.email_hash)) elif request.method == 'GET': form.email.data = current_user.email form.company_name.data = info.company form.member_names.data = info.members form.industry.data = info.industry form.university.data = info.university form.major.data = info.major form.grad_year.data = info.grad_year form.help_needed.data = info.help_req return render_template('edit_profile.html', title='Edit Profile', form=form) else: form = EditMenteeProfileForm(current_user.email) info = Mentee.query.filter_by(email=current_user.email).first() profile_pic_filepath += 'mentees/' + str(current_user.email_hash) + '-profile-pic.png' if form.validate_on_submit(): # current_user.email = form.email.data current_user.set_id() info.first_name = form.first_name.data info.last_name = form.last_name.data info.headline = form.headline.data info.about = form.about.data info.company = form.company.data info.university = dict(form.university.choices).get(form.university.data) info.major = dict(form.major.choices).get(form.major.data) info.year = dict(form.year.choices).get(form.year.data) info.industry = dict(form.industry.choices).get(form.industry.data) info.email = form.email.data info.skills = form.skill.data info.linkedin = form.linkedin.data info.twitter = form.twitter.data db.session.commit() flash('Your changes have been saved.') return redirect(url_for('user', userId=current_user.email_hash)) elif request.method == 'GET': form.first_name.data = info.first_name form.last_name.data = info.last_name form.headline.data = info.headline form.about.data = info.about form.university.data = info.university form.major.data = info.major form.year.data = info.year form.email.data = current_user.email form.company.data = info.company form.industry.data = info.industry form.skill.data = info.skills form.linkedin.data = info.linkedin form.twitter.data = info.twitter return render_template('edit_profile.html', title='Edit Profile', form=form)
def user(userId): user = User.query.filter_by(email_hash=userId).first() profile_pic_filepath = 'https://s3.ca-central-1.amazonaws.com/enlight-hub-profile-pictures/' try: # check if user is defined user.id except AttributeError: return render_template('404.html') mentees = [] skill_array = [] prefs = [] if user == current_user: if current_user.is_admin(): return render_template('404.html') elif current_user.is_mentor(): info = Mentor.query.filter_by(email=user.email).first() if info.skills is not None: skill_array = info.skills.split(", ") for m in info.users: if m.is_company(): mentee = Cohort.query.filter_by(email=m.email).first() else: mentee = Mentee.query.filter_by(email=m.email).first() user_m = User.query.filter_by(email=mentee.email).first() mentee.email_hash = user_m.email_hash mentees.append(mentee) else: info = Mentee.query.filter_by(email=user.email).first() profile_pic_filepath += 'mentees/' + str(current_user.email_hash) + '-profile-pic.png' if info.skills is not None: skill_array = info.skills.split(", ") # find preferred mentors tempList = [] if info.mentor1 is not None: user_p1 = User.query.filter_by(email_hash=info.mentor1).first() tempList.append(user_p1) if info.mentor2 is not None: user_p2 = User.query.filter_by(email_hash=info.mentor2).first() tempList.append(user_p2) if info.mentor3 is not None: user_p3 = User.query.filter_by(email_hash=info.mentor3).first() tempList.append(user_p3) for tempu in tempList: mentor = Mentor.query.filter_by(email=tempu.email).first() user_m = User.query.filter_by(email=mentor.email).first() mentor.email_hash = user_m.email_hash prefs.append(mentor) elif current_user.is_admin(): if user.is_admin(): # dont load profile for return render_template('404.html') elif user.is_mentor(): info = Mentor.query.filter_by(email=user.email).first() profile_pic_filepath += 'mentors/' + str(current_user.email_hash) + '-profile-pic.png' if info.skill is not None: skill_array = info.skill.split(", ") elif current_user.is_company(): info = Cohort.query.filter_by(email=user.email).first() profile_pic_filepath += 'mentees/' + str(current_user.email_hash) + '-profile-pic.png' if info.skills is not None: skill_array = info.skills.split(", ") else: info = Mentee.query.filter_by(email=user.email).first() profile_pic_filepath += 'mentees/' + str(current_user.email_hash) + '-profile-pic.png' if info.skills is not None: skill_array = info.skills.split(", ") elif current_user.is_mentor(): if user.is_admin(): return render_template('404.html') elif user.is_mentor(): return render_template('404.html') elif user.is_company(): info = Cohort.query.filter_by(email=user.email).first() profile_pic_filepath += 'mentees/' + str(current_user.email_hash) + '-profile-pic.png' if info.skills is not None: skill_array = info.skills.split(", ") else: # current user = mentor, can only view mentees info = Mentee.query.filter_by(email=user.email).first() profile_pic_filepath += 'mentees/' + str(current_user.email_hash) + '-profile-pic.png' if info.skills is not None: skill_array = info.skills.split(", ") else: if user.is_admin(): return render_template('404.html') elif user.is_mentor(): # current user = mentee, can only view mentors info = Mentor.query.filter_by(email=user.email).first() profile_pic_filepath += 'mentors/' + str(current_user.email_hash) + '-profile-pic.png' if info.skill is not None: skill_array = info.skill.split(", ") # clean the data a bit before passing to mentees info.email = None user.email = None else: return render_template('404.html') return render_template('user.html', title='Profile', user=user, info=info, mentor=user.mentor, mentees=mentees, skill_array=skill_array)
def cohort_faq(): if current_user.is_company(): return render_template('faq.html', title='FAQ') else: return render_template('404.html')