def member_add_schedule_page(): auth = session.get('auth_type') print(auth) if (auth != "Team leader" and auth != "Subteam leader"): flash("Not an authorized person", 'danger') return redirect(url_for("home.home_page")) member_id = session.get('member_id') form = AddScheduleForm() if (request.method == 'POST' and form.submit_add_schedule.data or form.validate()): name = form.name.data deadline = form.deadline.data done = form.done.data description = form.description.data budget = form.budget.data insert( "schedule", "NAME, DEADLINE, DONE, DESCRIPTION, BUDGET, MEMBER_ID", "'{}','{}','{}','{}','{}',{}".format(name, deadline, done, description, budget, member_id)) return redirect(url_for("member_add.member_add_schedule_page")) return render_template("member_add_schedule_page.html", form=form)
def member_add_design_page(): auth = session.get('auth_type') if (auth != "Team leader"): flash("Not an authorized person", 'danger') return redirect(url_for("home.home_page")) form = AddDesignForm() team_id = session.get("team_id") typ = select("vehicle_type.id,vehicle_type.name", "vehicle_type") form = AddDesignForm() form.typ.choices = typ if (request.method == 'POST' and form.submit_add_design.data or form.validate()): name = form.name.data year = form.year.data maxspeed = form.maxspeed.data weight = form.weight.data duration = form.duration.data is_autonomous = form.is_autonomous.data type_id = form.typ.data insert( "design", "NAME, YEAR, MAXSPEED, WEIGHT, DURATION, IS_AUTONOMOUS, TEAM_ID, TYPE_OF_VEHICLE", "'{}','{}','{}','{}','{}','{}','{}','{}'".format( name, year, maxspeed, weight, duration, is_autonomous, team_id, type_id)) return redirect(url_for("member_add.member_add_design_page")) return render_template("member_add_design_page.html", form=form)
def member_add_equipment_page(): auth = session.get('auth_type') if (auth != "Team leader" and auth != "Subteam leader"): flash("Not an authorized person", 'danger') return redirect(url_for("home.home_page")) team_id = session.get('team_id') subteams = select("subteam.id,subteam.name", "subteam join team on subteam.team_id=team.id", "team.id={}".format(team_id)) form = AddEquipmentForm() form.subteam.choices = subteams if (request.method == 'POST' and form.submit_add_equipment.data or form.validate()): name = form.name.data link = form.link.data purchasedate = form.purchasedate.data available = form.available.data subteam_id = form.subteam.data insert( "equipment", "NAME, LINK, PURCHASEDATE, AVAILABLE, PICTURE, TEAM_ID, SUBTEAM_ID", "'{}','{}','{}','{}','-1.png','{}','{}'".format( name, link, purchasedate, available, team_id, subteam_id)) return redirect(url_for("member_add.member_add_equipment_page")) return render_template("member_add_equipment_page.html", form=form)
def insert(): if request.method == 'POST': name = request.form['name'] email = request.form['email'] phone = request.form['phone'] queries.insert(name, email, phone) flash("Employee inserted successfully") return redirect(url_for('index'))
def register(): active = queries.run("""SELECT current_user""") if active[0][0] == None: active.pop(0) active_num = (len(active)) psychologistt = queries.select("name", "psychologist", asDict=True) patientt = queries.select("name", "patient", asDict=True) total_user = len(psychologistt) + len(patientt) form = RegistrationForm() if form.validate_on_submit(): string = 'Account created for ' + form.name.data requests = dict(list(request.form.items())) print("AB" * 30) print(requests) if requests["user_type"] == "psychologist": string = "'{}' , '{}' , '{}', '{}'".format(requests["name"], requests["address"], requests["mail"], requests["password"]) success = queries.insert(requests["user_type"], "name,address,mail,password", string) if (success[-1] == -1): string = "you could not signed up due to " + str(success[0]) flash(string, "error") else: string = "'{}' , '{}' , '{}'".format(requests["name"], requests["mail"], requests["password"]) success = queries.insert(requests["user_type"], "name,mail,password", string) if (success[-1] == -1): string = "you could not signed up due to " + str(success[0]) flash(string, "error") return render_template('register.html', session_id=(session["id"]), session_type=session["type"], active_num=active_num, title='Register', form=form) flash("you have signed up", "success") return redirect("/login") return render_template('register.html', session_id=(session["id"]), session_type=session["type"], active_num=active_num, title='Register', form=form, total_user=total_user)
def admin_add_team_page(): if (session.get('auth_type') != 'admin'): flash('No admin privileges...', 'danger') return redirect(url_for('home.home_page')) else: form = AddTeamForm() if (request.method == 'POST' and form.submit_add_team.data or form.validate()): name = form.name.data email = form.mail.data address = form.address.data year = form.year.data insert( "team", "name,num_members,found_year,email,adress,logo,competition_id", "'{}',0,'{}','{}','{}','-1.png',NULL".format( name, year, email, address)) return redirect(url_for('admin_add.admin_add_team_page')) return render_template('admin_add_team_page.html', imgName=None, form=form)
def member_add_competition_page(): auth = session.get('auth_type') if (auth != "Team leader"): flash("Not an authorized person", 'danger') return redirect(url_for("home.home_page")) form = AddCompetitionForm() if (request.method == 'POST' and form.submit_add_competition.data or form.validate()): name = form.name.data description = form.description.data reward = form.reward.data date = form.date.data country = form.country.data insert( "competition", "name,date,country,description,reward,team_id", "'{}','{}','{}','{}','{}',{}".format(name, date, country, description, reward, session.get('team_id'))) return render_template("member_add_competition_page.html", form=form)
def admin_add_team_leader_page(): if (session.get('auth_type') != "admin"): flash("Not an authorized person", 'danger') return redirect(url_for("home.home_page")) form = AddTeamLeaderForm() teams = select("id,name", "team") form.team.choices = teams majors = select("id,name", "major") form.major.choices = majors if (request.method == 'POST' and form.submit_add_team_leader.data or form.validate()): name = form.name.data age = form.age.data phone = form.phone.data mail = form.mail.data clas = form.clas.data status = form.status.data username = form.username.data team_id = form.team.data major = form.major.data insert( "person", "NAME, AGE, PHONE, CV, EMAIL, CLASS, AUTH_TYPE, STATUS, TEAM_ID, SUBTEAM_ID, MAJOR_ID", "'{}','{}','{}','-1','{}',{},3,{},{},{},{}".format( name, age, phone, mail, clas, status, team_id, 1, major)) person_id = select("id", "person", "name='{}'".format(name))[0] insert("member", "ROLE, ENTRYDATE, ACTIVE, PICTURE, ADDRESS, PERSON_ID", "'Uye',CURRENT_DATE,true,'-1','Address',{}".format(person_id)) member_id = select("id", "member", "person_id={}".format(person_id))[0] insert( "users", "username,password,member_id", "'{}',crypt('1234',gen_salt('bf')),{}".format(username, member_id)) return redirect(url_for("admin_add.admin_add_team_leader_page")) return render_template("admin_add_team_leader_page.html", form=form)
def appointment_page(id=0, type=0): active = queries.run("""SELECT current_user""") if active[0][0] == None: active.pop(0) active_num = (len(active)) psychologistt = queries.select("name", "psychologist", asDict=True) patientt = queries.select("name", "patient", asDict=True) total_user = len(psychologistt) + len(patientt) print("W" * 30) print(list(request.form.items())) psychologist = queries.select("id,name,mail", "psychologist", asDict=True) if (request.method == "GET"): return render_template("appointment.html", session_id=(session["id"]), session_type=session["type"], active_num=active_num, total_user=total_user, psychologist=psychologist, id=id) psychologist = queries.select("id,name", "psychologist", asDict=True) print("?-" * 26) print("request:", dict(list(request.form.items()))) requests = dict(list(request.form.items())) psy = queries.select("id", "psychologist", "mail = '{}'".format(requests["mail"]), asDict=True) print(psy) queries.insert( "appointment", "psychologist_id,patient_id,day,time", "{},{},{},{}".format(psy["id"], session["id"], requests["day"], requests["time"])) return render_template("appointment.html", session_id=(session["id"]), session_type=session["type"], active_num=active_num, total_user=total_user, psychologist=psychologist, id=id)
def member_add_sponsor_page(): auth = session.get('auth_type') sponsortypechoices = select("sponsortype.id,sponsortype.name", "sponsortype") form = AddSponsorForm() form.typ.choices = sponsortypechoices if (auth != "Team leader"): flash("Not an authorized person", 'danger') return redirect(url_for("home.home_page")) if (request.method == 'POST' and form.submit_add_sponsor.data or form.validate()): name = form.name.data description = form.description.data address = form.address.data field = form.field.data country = form.country.data type_id = form.typ.data insert( "sponsor", "name,description,field,country,logo,address,type_id", "'{}','{}','{}','{}','-1.png','{}',{}".format( name, description, field, country, address, type_id)) return redirect(url_for("member_add.member_add_sponsor_page")) return render_template("member_add_sponsor_page.html", form=form)
def member_add_tutorial_page(): if (session['auth_type'] != "Team leader" and session['auth_type'] != "Subteam leader" and session['auth_type'] != "Member"): flash("Not an authorized person", 'danger') return redirect(url_for("home.home_page")) form = AddTutorialForm() if (request.method == 'POST' and form.submit_add_tutorial.data or form.validate()): name = form.name.data area = form.area.data description = form.description.data link = form.link.data isvideo = form.isvideo.data member_id = session.get('member_id') insert( "tutorial", "NAME, AREA, DESCRIPTION, LINK, PICTURE, ISVIDEO, MEMBER_ID", "'{}','{}','{}','{}','-1.png',{},{}".format( name, area, description, link, isvideo, member_id)) return redirect(url_for("visitor.visitor_tutorials_page")) return render_template("member_add_tutorial_page.html", form=form)
from queries import insert for i in range(4): name = "Movie {}".format(i) image = "movie{}.png".format(i) insert(table="movie", columns="name,image", values="'{}','{}'".format(name, image)) for i in range(4): name = "Actor {}".format(i) image = "actor{}.png".format(i) insert(table="actor", columns="name,image", values="'{}','{}'".format(name, image)) insert("index", "movie_id,actor_id", "1,1") insert("index", "movie_id,actor_id", "1,3") insert("index", "movie_id,actor_id", "1,4") insert("index", "movie_id,actor_id", "2,3") insert("index", "movie_id,actor_id", "2,4") insert("index", "movie_id,actor_id", "2,1") insert("index", "movie_id,actor_id", "3,4") insert("index", "movie_id,actor_id", "3,3") insert("index", "movie_id,actor_id", "4,4") insert("index", "movie_id,actor_id", "4,1")
def psychologist_page(id): print("AA" * 23, request.form) global adds active = queries.run("""SELECT current_user""") if active[0][0] == None: active.pop(0) active_num = (len(active)) psychologistt = queries.select("name", "psychologist", asDict=True) patientt = queries.select("name", "patient", asDict=True) total_user = len(psychologistt) + len(patientt) if (request.method == "POST"): if ("comment" in request.form): requests = dict(list(request.form.items())) queries.insert( "comment", "patient_id,psychologist_id,comment", "'{}','{}','{}'".format(session["id"], id, requests["comment_content"])) elif ("point" in request.form): requests = dict(list(request.form.items())) selected = queries.select( "id", "point", "patient_id = {} AND psychologist_id = {}".format( session["id"], id)) print("SEEEELELLLLLLLEEEECCCCCTTEEEEEDDDDDDDD") print(selected) if (len(selected) == 0): queries.insert( "point", "point,patient_id,psychologist_id", "'{}','{}','{}'".format(requests["point"], session["id"], id)) else: print("UPDATINGGGGG") queries.update( "point", "point = {}".format(requests["point"]), "patient_id = {} AND psychologist_id = {}".format( session["id"], id)) elif ("give_Add" in request.form): adds.append(id) elif (list(request.form.items())[0][1] == "delete"): com_id = list(request.form.items())[0][0] queries.delete("comment", "comment.id = {}".format(com_id)) elif ("Cancel" in list(request.form.items())[0]): requests = dict(list(request.form.items())) delete_one = list(requests.keys())[0] queries.delete("appointment", "appointment.id={}".format(delete_one)) else: print("HA" * 30, list(request.form.items())) queries.update( "comment", "comment = '{}'".format(list(request.form.items())[0][1]), "id = {}".format(list(request.form.items())[1][0])) queries.update( "comment", "comment = '{}'".format(list(request.form.items())[1][1]), "id = {}".format(list(request.form.items())[0][0])) psychologist = queries.select("id,name,mail,address", "psychologist", "id={}".format(id), asDict=True) point = queries.select("point", "point", "psychologist_id = {}".format(id), asDict=False) sum_ = 0 for i in range(len(point)): sum_ += point[i][0] if (len(point) != 0): sum_ = sum_ / float(len(point)) point = sum_ appointments = queries.select("id,day,time,patient_id,psychologist_id", "appointment", "appointment.psychologist_id={}".format(id), asDict=True) patients = queries.select("name,id", "patient", asDict=True) if isinstance(appointments, dict): appointments = [appointments] comments = queries.select("id,patient_id,psychologist_id,comment", "comment", "comment.psychologist_id = {}".format( psychologist["id"]), asDict=True) if isinstance(comments, dict): comments = [comments] sql = "SELECT appointment.id, appointment.day,appointment.time, patient.name,psychologist.name,psychologist.id FROM patient INNER JOIN appointment ON patient.id = appointment.patient_id INNER JOIN psychologist ON appointment.psychologist_id = psychologist.id WHERE psychologist.id = {};".format( id) joined = queries.run(sql) return render_template("psychologist_page.html", joined=joined, active_num=active_num, total_user=total_user, point=point, comments=comments, psychologist=psychologist, appointments=appointments, patients=patients, session_id=session["id"], session_type=session["type"], asDict=True)