def register(): if session.has_key('user'): session.pop('user') if request.method=="GET": return render_template("register.html", loggedout=True) elif request.method=='POST': if request.form['button']=='Register': username=request.form['username'] password=request.form['password'] osis=request.form['osis'] digit=request.form['digit'] name=request.form['name'] email=request.form['email'] lunch=request.form['lunch'] exist=database.add_student(username,password) if exist: return render_template("register.html",loggedout=True,exists=exist) database.set_osis(username,osis) database.set_id(username,digit) database.set_name(username,name) database.set_email(username,email) database.set_period(username, int(lunch), [str(lunch), "Cafe", "Chi Kun Wang", "ZLN5", "0"+str(lunch)]) return redirect(url_for("profile")) return redirect(url_for("register"))
def classinfo(): if not session.has_key('user'): return redirect(url_for("about")) username=session['user'] name=database.get_name(username) osis=database.get_osis(username) digits=database.get_id(username) email=database.get_email(username) schedule=database.get_schedule(username) classes=database.get_class_info() if request.method=='GET': return render_template("class.html" ,name=name ,osis=osis ,digits=digits ,email=email ,classes=classes ,schedule=schedule ,get=True) if request.method=="POST": value=request.form['button'] value=value.split(" ") index=int(value[1])-1 validate=True if (str(value[0])=="set"): period=classes[index][0] clas=classes[index] schedule=database.get_schedule(username) if schedule[int(period)-1][1]=="free": database.set_period(username,period,clas) else: validate=False if (str(value[0])=="req"): req=classes[index] period=classes[index][0] if database.has_lunch(username,period) or l_equal(schedule[int(period)-1],req): validate=False else: database.post_request(username,req) return render_template("class.html" ,name=name ,osis=osis ,digits=digits ,email=email ,classes=classes ,schedule=schedule ,validate=validate)
def edit(): if not session.has_key('user'): return redirect(url_for("about")) username=session['user'] email=database.get_email(username) osis=database.get_osis(username) digit=database.get_id(username) if request.method=='GET': return render_template("edit.html" ,username=username ,email=email ,osis=osis ,digit=digit ,loggedout=False) if request.method=='POST': if request.form['button']=='Edit': password=request.form['password'] email=request.form['email'] digit=request.form['digit'] osis=request.form['osis'] lunch=request.form['lunch'] schedule=database.get_schedule(username) current_lunch=database.get_lunch(username) pos=database.get_period(username,int(lunch))[1] if not (pos == 'free' or pos=='Cafe'): return render_template("edit.html" ,username=username ,email=email ,osis=osis ,digit=digit ,loggedout=False ,invalid=True) database.set_period(username,current_lunch,["","free","n/a","",""]) database.set_period(username,lunch,[str(lunch),"Cafe","Chi Kun Wang","ZLN5","0"+str(lunch)]) database.set_password(username,password) database.set_email(username,email) database.set_id(username,digit) database.set_osis(username,osis) return redirect(url_for('profile')) return redirect(url_for('edit'))