def get_matches(): if g.user: username = session['username'] userRepository = UserRepository() courseRepository = CourseRepository() user = userRepository.find(username) if user.type == "ADMIN": matchesRepository = MatchesRepository() matches = matchesRepository.get_matches() matches_list = [] for match in matches: notetaker_id = match.notetaker_id notetaker = userRepository.find(notetaker_id) noterequester_id = match.noterequester_id noterequester = userRepository.find(noterequester_id) course_id = match.course_id course = courseRepository.find(course_id) match = (notetaker, noterequester, course) matches_list.append(match) return render_template('admin-matches.html', matches=matches, matches_list=matches_list, username=username, userType=user.type) return redirect(url_for('index'))
def approve(username): username = username userRepository = UserRepository() user = userRepository.find(username) user.approved = 1 userRepository.save_changes() return render_template('admin-approval.html', user=user)
def myClasses(): if g.user: username = session['username'] userRepository = UserRepository() user = userRepository.find(username) courseRepository = CourseRepository() userType = user.type matchedCourses = "" if userType == "ADMIN": return redirect(url_for('admin')) if userType == "TAKER": matchedCoursesDupes = [ match.course for match in user.taker_matches ] matchedCourses = set( matchedCoursesDupes) #by using sets, we don't get duplicates elif userType == "REQUESTER": matchedCoursesDupes = [ match.course for match in user.requester_matches ] matchedCourses = set(matchedCoursesDupes) else: return redirect(url_for('index')) myCourses = [e.course for e in user.enrollment] unmatchedCourses = [] for course in myCourses: if course not in matchedCourses: unmatchedCourses.append(course) return render_template('select-course.html', username=username, userType=userType, matchedCourses=matchedCourses, unmatchedCourses=unmatchedCourses, firstName=user.first_name) return redirect(url_for('index'))
def get_feedback(): if g.user: username = session['username'] userRepository = UserRepository() user = userRepository.find(username) feedbackRepository = FeedbackRepository() feedback = feedbackRepository.get_feedback() infoList = [] for row in feedback: rowUsername = row.username rowUser = userRepository.find(rowUsername) info = (rowUser.first_name, rowUser.last_name, rowUser.email) infoList.append(info) return render_template('admin-feedback.html', users=feedback, infoList=infoList, username=username, userType=user.type) return redirect(url_for('index'))
def matches_for_noterequesters(username): if g.user: username = session['username'] userRepository = UserRepository() user = userRepository.find(username) matchesRepository = MatchesRepository() matches = matchesRepository.get_matches_for_noterequester(username) return render_template('admin-view.html', users=matches, username=username, userType=user.type) return redirect(url_for('index'))
def admin(): if g.user: username = session['username'] userRepository = UserRepository() user = userRepository.find(username) if user.type != "ADMIN": return redirect(url_for('index')) #users = userRepository.get_users_by_account_type("TAKER") return render_template('admin-view.html', username=username, userType=user.type) return redirect(url_for('index'))
def post(self): args = self.reqparse.parse_args() if 'username' in session: username = session['username'] subject = args['subject'] course_number = args['course_number'] section = args['section'] enrollmentRepository = EnrollmentRepository() courseRepository = CourseRepository() course = courseRepository.get(subject = subject, course_number = course_number, section = section)[0] crn = course.course_id if enrollmentRepository.course_already_registered(username, crn): return {"error": "You have already registered for this course."}, 400 enrollCourse = Enrollment(username, crn) enrollmentRepository.add_or_update(enrollCourse) enrollmentRepository.save_changes() #check for matches here userRepository = UserRepository() user = userRepository.find(username) userType = user.type matchesRepository = MatchesRepository() oppEnrollments = enrollmentRepository.get_enrollments_of_opposite_type(userType, crn) if oppEnrollments is not None and len(oppEnrollments) > 0: if userType == "REQUESTER": newMatch = Matches(oppEnrollments[0].username, username, crn) matchesRepository.add_or_update(newMatch) elif userType == "TAKER": unmatchedRequesters = matchesRepository.get_unmatched_users(crn, [oppEnrollment.username for oppEnrollment in oppEnrollments]) for requester in unmatchedRequesters: print("New match for the requester: "+requester) newMatch = Matches(username, requester, crn) matchesRepository.add_or_update(newMatch) #match to all requesters who arent matched yet else: print("why are you here??") # fail here, return some error matchesRepository.save_changes() #check enrollment table for the crn # if crn exists, grab the username # check user table to see what the user type is of those usernames # if its the opposite of what you are, make a match and add it to the match table return { "message": "Course has been enrolled in successfully.", "username": username, "crn": crn } else: return {"error": "There is no currently logged in account."}, 401
def feedback(): if g.user: username = session['username'] userRepository = UserRepository() user = userRepository.find(username) form = FeedbackForm(obj=user) if request.method == 'POST': if form.validate() == False: #flash('All fields are required') return render_template('feedback.html', form=form) else: msg = Message(form.subject.data, sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = """ From: %s %s <%s> %s """ % (form.first_name.data, form.last_name.data, form.email.data, form.message.data) mail.send(msg) #making a post to the table feedbackRepository = FeedbackRepository() feedback_text = form.message.data subject = form.subject.data feedbackRepository.add_or_update(username, subject, feedback_text) feedbackRepository.save_changes() return render_template('feedback.html', success=True, username=username, firstName=user.first_name, lastName=user.last_name, userType=user.type) elif request.method == 'GET': form.populate_obj(user) db.session.commit() return render_template('feedback.html', form=form, username=username, firstName=user.first_name, lastName=user.last_name, userType=user.type) return redirect(url_for('index'))
def enrollment(): if g.user: username = session['username'] userRepository = UserRepository() user = userRepository.find(username) userType = user.type if userType != "TAKER" and userType != "REQUESTER": render_template("admin.html", username=username) courseRepository = CourseRepository() subjects = courseRepository.get_distinct_subjects() myCourses = [e.course for e in user.enrollment] print(myCourses) return render_template('enrollment.html', username=username, userType=userType, subjects=subjects, myCourses=myCourses) return redirect(url_for('index'))
def notes(course_id): if g.user: #Do security checks here to make sure only matching students get through this block# #don't want willynilly students trying to upload/download notes# courseRepository = CourseRepository() course = courseRepository.find(course_id) username = session['username'] userRepository = UserRepository() user = userRepository.find(username) userType = user.type if userType == "ADMIN": redirect(url_for('admin')) files = FileRepository().get_files_for_course(course_id) return render_template('upload-download.html', username=username, userType=userType, course=course, course_id=course_id, files=files) return redirect(url_for('index'))
def index(): if g.user: username = session['username'] userRepository = UserRepository() user = userRepository.find(username) userType = user.type matchedCourses = "" if userType == "TAKER": matchedCourses = [match.course for match in user.taker_matches] elif userType == "REQUESTER": matchedCourses = [match.course for match in user.requester_matches] else: return redirect(url_for('admin')) if len( matchedCourses ) > 0: #if you have a match, you're taken to the match page instead return redirect(url_for('myClasses')) return redirect( url_for('enrollment') ) #if you don't have any matches yet, you're back at the class enrollment page return render_template('index.html')
def students(): if g.user: username = session['username'] userRepository = UserRepository() user = userRepository.find(username) if user.type == "ADMIN": approved_notetakers = userRepository.get_users_by_account_type_and_approval( "TAKER", True) unapproved_notetakers = userRepository.get_users_by_account_type_and_approval( "TAKER", False) approved_noterequesters = userRepository.get_users_by_account_type_and_approval( "REQUESTER", True) unapproved_noterequesters = userRepository.get_users_by_account_type_and_approval( "REQUESTER", False) return render_template( 'admin-students.html', approved_notetakers=approved_notetakers, unapproved_notetakers=unapproved_notetakers, approved_noterequesters=approved_noterequesters, unapproved_noterequesters=unapproved_noterequesters, username=username, userType=user.type) return redirect(url_for('index'))