def showCourse(cid): #pdf = functions.getPDF(cid) basics = functions.getBasics(cid) if request.method == 'GET': avgRatings = functions.getAvgRatings(cid) comments = functions.getComments(cid) return render_template('course_page.html', basics=basics, avgRatings=avgRatings, comments=comments) elif request.method == 'POST': #user is rating (which includes commenting) the course. uR = request.form.get('usefulRate') dR = request.form.get('diffRate') rR = request.form.get('relevRate') eR = request.form.get('expectRate') hW = request.form.get('hoursWk') comment = request.form.get('new_comment') functions.makeRatings(functions.getBNum(), cid, rR, uR, dR, eR, hW, comment) #have to recalculate the ratings and fetch the comments again avgRatings = functions.getAvgRatings(cid) comments = functions.getComments(cid) #now we render the page again return render_template('course_page.html', basics=basics, avgRatings=avgRatings, comments=comments)
def createProfile(): if request.method == 'GET': return render_template('create_profile.html') else: values = request.form bNum = functions.getBNum() student_attributes = list(values.values()) student_attributes.insert(0, bNum) studentInfo = functions.insertStudent(student_attributes) return redirect(url_for('uploadPic', n=bNum))
def showCourse(cid): '''directs the user an individual course page for unique semester, year, and prof''' conn = dbi.connect() basics = functions.getBasics(cid) if request.method == 'GET': avgRatings = functions.getAvgRatings(conn, cid) comments = functions.getComments(conn, cid) return render_template('course_page.html', basics = basics, avgRatings = avgRatings, comments=comments) elif request.method == 'POST': action = request.form.get("submit") if action == 'Add to Favorites' : try: bNum = functions.getBNum() print(bNum) functions.addFavorite(conn, bNum, basics['cid']) avgRatings = functions.getAvgRatings(conn, cid) comments = functions.getComments(conn, cid) flash('Course added to favorites') return render_template('course_page.html', basics = basics, avgRatings = avgRatings, comments=comments) except Exception as err: avgRatings = functions.getAvgRatings(conn, cid) comments = functions.getComments(conn, cid) flash('Please log in to favorite a course!') return render_template('course_page.html', basics = basics, avgRatings = avgRatings, comments=comments) elif action == 'Rate': print('trying to rate/comment') #user is rating (which includes commenting) the course. uR = request.form.get('usefulRate') dR = request.form.get('diffRate') rR = request.form.get('relevRate') eR = request.form.get('expectRate') hW = request.form.get('hoursWk') comment = request.form.get('new_comment') functions.makeRatings(functions.getBNum(), cid, rR, uR, dR, eR, hW, comment) #have to recalculate the ratings and fetch the comments again avgRatings = functions.getAvgRatings(conn, cid) comments = functions.getComments(conn, cid) #now we render the page again return render_template('course_page.html', basics = basics, avgRatings = avgRatings, comments=comments)
def logged_in(): conn = dbi.connect() bNum = functions.getBNum() alreadyAMember = functions.checkUser(conn, bNum) # if profile already made, redirect to profile if (alreadyAMember): student = functions.getStudent(bNum) name = student[1] return redirect(url_for('profile', name=name)) else: # if not, create profile return redirect(url_for('createProfile'))
def logged_in(): '''logs student in or sends them to create a profile if they don't have an account''' conn = dbi.connect() bNum = functions.getBNum() alreadyAMember = functions.checkUser(conn, bNum) # if profile already made, redirect to profile if(alreadyAMember): student = functions.getStudent(bNum) name = student[1] return redirect( url_for('profile', name = name) ) else: # if not, create profile return redirect( url_for('createProfile') )
def uploadPic(): if request.method == 'GET': return render_template('portrait_upload.html') else: if 'file' not in request.files: flash('No file part') file = request.files['file'] # if user does not select file, browser also # submit an empty part without filename if file.filename == '': flash('No selected file') if file and functions.allowed_picture_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['PORTRAIT_FOLDER'], filename)) bNum = functions.getBNum() student = functions.getStudent(bNum) name = student[1] functions.insertPicture(bNum, file.filename) return redirect(url_for('profile', name=name))
def login(): if '_CAS_TOKEN' in session: token = session['_CAS_TOKEN'] if 'CAS_USERNAME' in session: is_logged_in = True username = session['CAS_USERNAME'] else: is_logged_in = False username = None if is_logged_in: conn = dbi.connect() bNum = functions.getBNum() student = functions.getStudent(bNum) name = student[1] return redirect(url_for('profile', name=name)) else: return render_template('login.html', username=username, is_logged_in=is_logged_in, cas_attributes=session.get('CAS_ATTRIBUTES'))
def login(): '''sends user to login using Wellesley Authentification''' if '_CAS_TOKEN' in session: token = session['_CAS_TOKEN'] if 'CAS_USERNAME' in session: is_logged_in = True username = session['CAS_USERNAME'] else: is_logged_in = False username = None if is_logged_in: # only occurs for first time login conn = dbi.connect() bNum = functions.getBNum() student = functions.getStudent(bNum) name = student[1] return redirect( url_for('profile', name = name) ) else: return render_template('login.html', username=username, is_logged_in=is_logged_in, cas_attributes = session.get('CAS_ATTRIBUTES'))