def user(username): try: '''Home page for logged in user''' if 'username' in session: username = session['username'] student = helpFunc.getStudent(get_conn(), username) #Log in admin #hideContent is for html purposes (to hide the download div) if username == "admin": return render_template('logAdmin.html', pageTitle='Welcome, Admin', hideContent=True) #Log in student name = student['name'] return render_template('logUser.html', pageTitle='Aloha, ' + name.title(), name=name, sid=student['sid'], hideContent=True) else: flash('You are not logged in. Please login or join.') return redirect(url_for('index')) except Exception as err: flash('Some kind of error ' + str(err)) return redirect(url_for('index'))
def schedule(sid=0, month=None, year=None): ''' Show all classes that student is scheduled for ''' #No month/year passed in. Use current month and year if month is None and year is None: month = datetime.now().strftime("%B") year = datetime.now().year if 'username' in session: username = session['username'] student = helpFunc.getStudent(get_conn(), username) if username == 'admin' or (student is not None and student['username'] == username): if sid == 0: #No sid entered. Use sid of logged in student if username == 'admin': flash("Admin, please choose a student to view.") return redirect(url_for('showStudents')) else: student = helpFunc.getStudent(get_conn(), username) sid = student['sid'] classes = helpFunc.getMonthClasses( get_conn(), sid, month, year) #Get all classes corresponding to sid, month, and year dropdown = helpFunc.getMonths( get_conn(), sid) #Used to populate dropdown in template return render_template( 'schedule.html', classes=classes, sid=sid, totalMonths=dropdown, pageTitle=helpFunc.getStudentByID(get_conn(), sid)['name'] + "'s Schedule") flash("You don't have permission to access this page.") return redirect(url_for('index'))
def studentPayment(username=None): if 'username' in session: student = None if session['username'] != 'admin': if username is None or session['username'] == username: student = helpFunc.getStudent(get_conn(), session['username']) else: flash("You don't have permission to access this page.") return redirect(url_for('index')) elif session['username'] == 'admin': if username is not None: student = helpFunc.getStudent(get_conn(), username) else: flash("Please choose a student to view information.") return redirect(url_for('showStudents')) if student is not None: paymentInfo = helpFunc.getStudentPayment(get_conn(), student['sid']) return render_template('studentPayment.html', pageTitle="Payment Records for " + student['name'], paymentInfo=paymentInfo, username=session['username']) else: flash("Student's payment info does not exist.") return redirect(url_for('index')) flash("You don't have permission to access this page.") return redirect(url_for('index'))
def oneStudent(sid=0): '''Student profile page''' if request.method == 'GET': if (sid == 0): #logged in student tries to access their own profile sid = helpFunc.getStudent(get_conn(), session['username'])[ 'sid'] #get their sid using logged in username student = helpFunc.getStudentByID(get_conn(), sid) #Give access only if logged in student is trying to access their own profile or admin if student['username'] == session['username'] or session[ 'username'] == 'admin': classRow = helpFunc.getClassbyID(get_conn(), student["cid"]) return render_template('oneStudent.html', pageTitle=student["name"], studentRow=student, classRow=classRow) return redirect(url_for('index'))
def reschedule(classDate=None, cid=None): """Cancels user's existing class and books new class""" if 'username' in session and session['username'] != "admin": username = session['username'] dateSpecific = helpFunc.getClassbyDate(get_conn(), classDate, username) """CANCELLATION OF CLASS""" if cid is None: if dateSpecific is not None: cid = dateSpecific['cid'] if request.method == 'GET': #ask user to confirm they want to cancel return render_template('cancelConfirm.html', pageTitle='Reschedule', dateSpecific=dateSpecific, classInfo=helpFunc.getClassbyID( get_conn(), cid)) if request.form[ "submit"] == 'Yes': #user confirms cancellation, display alt classes grade = helpFunc.getStudent(get_conn(), username)['grade'] return render_template( 'altClasses.html', pageTitle='Alternate Classes', allClasses=helpFunc.rescheduleOptions( get_conn(), grade, cid), deleted=helpFunc.cancelClass(get_conn(), dateSpecific)) #user decides not to cancel. if request.form["submit"] == 'No': flash('Ok. Your class has not been cancelled.') return redirect(url_for('schedule')) """BOOKING NEW CLASS""" if dateSpecific is None: #new class doesn't already exist return render_template('newClassConfirm.html', pageTitle='Your Booking', added=helpFunc.reschedule( get_conn(), cid, classDate, username)) return redirect(url_for('index'))