def patient_page(id): 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"): requests = dict(list(request.form.items())) delete_one = list(requests.keys())[0] queries.delete("appointment", "appointment.id={}".format(delete_one)) patients = queries.select("id,name,mail", "patient", "id={}".format(id), asDict=True) appointments = queries.select("id,day,time,patient_id,psychologist_id", "appointment", "appointment.patient_id={}".format(id), asDict=True) psychologist = queries.select("id,name", "psychologist", asDict=True) if isinstance(appointments, dict): appointments = [appointments] return render_template("patient_page.html", active_num=active_num, total_user=total_user, psychologist=psychologist, appointments=appointments, patients=patients, asDict=True, page_id=int(id), session_id=(session["id"]), session_type=session["type"])
def visitor_teaminfo_page(team_id): teaminfo = select( columns= "team.name,team.num_members,team.found_year,team.email,team.adress,team.logo", table="team", # the selected team where="id = {}".format(team_id)) team_designs = select( columns= "design.name,design.year,design.maxspeed,design.weight,design.duration,design.is_autonomous,design.id,team.id", table="design join team on design.team_id=team.id", where="team.id = {}".format(team_id)) competition = select( columns= "competition.name,competition.date,competition.country,competition.description,competition.reward", table="team join competition on team.competition_id=competition.id", where="team.id = {}".format(team_id)) members_info = select( columns= "person.name,person.age,person.phone,person.cv,person.email,person.class,member.picture,subteam.name", table= "team join person on team.id=person.team_id join member on member.person_id=person.id join subteam on person.subteam_id=subteam.id", where="team.id = {}".format(team_id)) sponsors = select( columns="sponsor.name,sponsortype.name,sponsor.logo", table= "team join sponsorindex on team.id=sponsorindex.team_id join sponsor on sponsor.id=sponsorindex.sponsor_id join sponsortype on sponsortype.id=sponsor.type_id", where="team.id = {}".format(team_id)) return render_template("teaminfo_page.html", teaminfo=teaminfo, team_designs=team_designs, competition=competition, members_info=members_info, sponsors=sponsors)
def home_page(): session["id"] = None session["type"] = None 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(session) 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;" joined = queries.run(sql) print("\|/" * 15) print(joined) appointment = queries.select("id,psychologist_id,patient_id,day,time", "appointment", asDict=True) patients = queries.select("name,id", "patient", asDict=True) psychologist = queries.select("id,name", "psychologist", asDict=True) return render_template("home_page.html", session_id=(session["id"]), session_type=session["type"], joined=joined, active_num=active_num, total_user=total_user, id=10, appointment=appointment, patients=patients, psychologist=psychologist)
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 checkMemberLogin(username, password): success = False try: connection = db.connect(os.getenv("DATABASE_URL")) cursor = connection.cursor() statement = """SELECT * FROM USERS WHERE USERNAME = '******' AND PASSWORD = crypt('%s',PASSWORD) """ % (username, password) cursor.execute(statement) result = cursor.fetchone() print("LOGIN RESULT", result) if ((result != None) and (len(result) >= 1)): flash('You have been logged in!', 'success') session['logged_in'] = True session['username'] = username session['member_id'] = result[2] session['team_id'] = select( "team.id", "team join person on person.team_id=team.id join member on member.person_id=person.id", "member.id={}".format(result[2]))[0] print("HEREEE", session.get('team_id')) session['auth_type'] = select( "auth_type.name", "person join member on member.person_id=person.id join auth_type on person.auth_type=auth_type.id", "member.id={}".format(result[2]))[0] print("GIRISTEKI AUTH TYPE:", session.get('auth_type'), session.get('team_id')) success = True return redirect(url_for('home.home_page')) except db.DatabaseError: connection.rollback() flash('Login Unsuccessful. Please check username and password', 'danger') finally: connection.close() return success
def validate_mail(self, mail): maill = queries.select("mail", "patient", where="mail = '{}'".format(mail.data)) if (len(maill) != 0): raise ValidationError("this mail has been taken already") mail = queries.select("mail", "psychologist", where="mail = '{}'".format(mail.data)) if (len(mail) != 0): raise ValidationError("this mail has been taken already")
def admin_edit_competition_page(id): form = EditCompetitionForm() imageForm = UploadImageForm() imageFolderPath = os.path.join(os.getcwd(), 'static/images/competitions') if (request.method == 'POST' and form.submit_competition.data or form.validate()): name = form.name.data date = form.date.data country = form.country.data description = form.description.data reward = form.reward.data image = imageForm.image.data filename = select("logo", "competition", "id={}".format(id)) if (image): extension = image.filename.split('.')[1] current_date = time.gmtime() filename = secure_filename("{}_{}.{}".format( id, current_date[0:6], extension)) filePath = os.path.join(imageFolderPath, filename) images = os.listdir(imageFolderPath) digits = int(math.log(int(id), 10)) + 1 for im in images: if (im[digits] == '_' and im[0:digits] == str(id)): os.remove(os.path.join(imageFolderPath, im)) image.save(filePath) elif (image): flash('Please upload a file in JPG format', "danger") print("Before update: ", date) update( "competition", "name='{}', date=DATE('{}'), country='{}', description='{}', reward='{}',logo='{}'" .format(name, date, country, description, reward, filename), "id={}".format(id)) return redirect( url_for('admin_edit.admin_edit_competition_page', id=id)) else: if (session.get('auth_type') != 'Team leader'): flash('No admin privileges...', 'danger') return redirect(url_for('home.home_page')) result = select('id,name,date,country,description,reward', 'competition, logo', 'id={}'.format(id))[0] form.description.data = result[4] return render_template('admin_edit_competition_page.html', form=form, result=result, imgName=result[5], uploadImg=imageForm) return render_template('admin_edit_competition_page.html', form=form, result=result, imgName=result[5], uploadImg=imageForm)
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 sign_out(): 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) session["id"] = None session["name"] = None print("||" * 33) return redirect(url_for('login_page'))
def login_page(): 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 = LoginForm() session["id"] = None session["type"] = None if form.validate_on_submit(): user = queries.select("id,name,mail,password", "patient", where="mail = '{}'".format(form.mail.data), asDict=True) if (user): if (user["mail"] == form.mail.data and user["password"] == form.password.data): session["id"] = user["id"] session["name"] = user["name"] session["type"] = "patient" session["address"] = "NULL" session["mail"] = user["mail"] return redirect(url_for('patient_page', id=user["id"])) user = queries.select("id,name,mail,address,password", "psychologist", where="mail = '{}'".format(form.mail.data), asDict=True) if (len(user) != 0): if (user["mail"] == form.mail.data and user["password"] == form.password.data): session["id"] = user["id"] session["type"] = "psychologist" session["name"] = user["name"] session["mail"] = user["mail"] session["address"] = user["address"] return redirect(url_for('psychologist_page', id=user["id"])) flash('Login Unsuccessful. Please check username and password', 'danger') return render_template('login.html', session_id=(session["id"]), session_type=session["type"], active_num=active_num, title='Login', form=form, total_user=total_user)
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 visitor_teams_page(): teams = select( columns="team.name,competition.name,team.email,team.adress,team.id", table= "team left outer join competition on team.competition_id=competition.id order by team.name desc" ) return render_template("teams_page.html", teams=teams)
def sign_out_delete(): 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 (session["type"] == "patient"): queries.delete("patient", "id = {}".format(session["id"])) else: queries.delete("psychologist", "id = {}".format(session["id"])) session["id"] = None session["name"] = None return redirect(url_for('login_page'))
def visitor_tutorials_page(): tutorials = select( columns= "tutorial.name,tutorial.area,tutorial.description,tutorial.link,tutorial.picture,person.name,member_id,tutorial.id", table= "tutorial join member on tutorial.member_id=member.id join person on person.id=member.person_id order by tutorial.name" ) return render_template("tutorials_page.html", tutorials=tutorials)
def member_edit_design_page(design_id): auth = session.get('auth_type') if (auth != "Team leader"): flash("Not an authorized person") return redirect(url_for("home.home_page")) typs = select("vehicle_type.id,vehicle_type.name", "vehicle_type") team_id = session.get('team_id') member_id = session.get('member_id') form = EditDesignForm() form.typ.choices = typs if (request.method == 'POST' and form.submit_edit_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 typ = form.typ.data update( "design", "name='{}',year='{}',maxspeed='{}',weight='{}',duration='{}', is_autonomous='{}', team_id='{}', type_of_vehicle = '{}'" .format(name, year, maxspeed, weight, duration, is_autonomous, team_id, typ), where="id={}".format(design_id)) return redirect( url_for("visitor.visitor_teaminfo_page", team_id=team_id)) else: result = select( "design.name,year,maxspeed,weight,duration,is_autonomous,vehicle_type.id", "design join vehicle_type on design.type_of_vehicle=vehicle_type.id", "design.id={}".format(design_id)) print(result) form.name.data = result[0] form.year.data = result[1] form.maxspeed.data = result[2] form.weight.data = result[3] form.duration.data = result[4] form.is_autonomous.data = result[5] form.typ.data = result[6] return render_template("member_edit_design_page.html", form=form, result=result)
def psychologist_page_all(): 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) psys = queries.select("id,name,mail, address", "psychologist", asDict=True) point_id_dict = {} for psy in psys: point = queries.select("point", "point", "psychologist_id = {}".format(psy["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_id_dict[psy["id"]] = sum_ print("||||" * 20) print(point_id_dict) for psy in psys: psy["point"] = point_id_dict[psy["id"]] print(psys) psys = sorted(psys, key=lambda k: k['point'], reverse=True) print(psys) for i in range(0, len(adds)): adds[i] = int(adds[i]) for i in range(len(psys)): if (psys[-i]["id"] in adds): temp = psys[-i] psys.pop(-i) psys.insert(0, temp) print(psys) return render_template("psychologist_page_all.html", session_id=(session["id"]), session_type=session["type"], active_num=active_num, psys=psys, point_id_dict=point_id_dict, total_user=total_user)
def download(): cvFolder = os.path.join(admin_edit.root_path, "static/cv") filename = select("person.cv", "person join member on member.person_id=person.id", "person.id={}".format(session.get('person_id')))[0] return send_from_directory(directory=cvFolder, filename=filename, as_attachment=True, cache_timeout=0)
def select(self, queryfunc, subpath=None) : """Returns the results of the query function when given the database. The database can be restricted using the 'subpath' argument.""" queryfunc = util.assert_type(queryfunc, queries.Func) with self.lock.read_lock : data = self.data if subpath is not None and assert_type(subpath, queries.Path) : data = subpath.get(data) return queries.select(data, queryfunc)
def admin_members_page(): if (session.get('auth_type') != 'admin'): flash('No admin privileges...', 'danger') return redirect(url_for('home.home_page')) else: result = select( columns= "person.name,person.email,auth_type.name,team.name,person.id", table="person join team on person.team_id=team.id \ join auth_type on person.auth_type=auth_type.id \ order by team.name asc, auth_type.name desc") return render_template('admin_members_page.html', members=result)
def admin_teams_page(): if (session.get('auth_type') != 'admin'): flash('No admin privileges...', 'danger') return redirect(url_for('home.home_page')) else: result = select( columns= "team.name,team.email,team.num_members,team.found_year,competition.name,team.id", table= "team left outer join competition on team.competition_id=competition.id \ order by team.name asc") return render_template('admin_teams_page.html', teams=result)
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 forgot_page(): active = queries.run("""SELECT current_user""") if active[0][0] == None: active.pop(0) form = LoginForm() 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 form.validate_on_submit(): queries.update("patient", "password = {}".format(form.password.data), where="mail = '{}'".format(form.mail.data)) return render_template('forgot_page.html', session_id=(session["id"]), session_type=session["type"], form=form, active_num=active_num, total_user=total_user)
def member_list_members_page(): auth = session.get('auth_type') if (auth != "Team leader" and auth != 'Member' and auth != 'Subteam leader'): flash("Not an authorized person", 'danger') return redirect(url_for("home.home_page")) members = select( columns="person.name,person.email,auth_type.name,team.name,person.id", table="person join team on person.team_id=team.id \ join auth_type on person.auth_type=auth_type.id", where="team.id={} order by team.name asc, auth_type.name desc".format( session.get('team_id'))) return render_template("member_members_page.html", members=members)
def team_schedule_page(): auth = session.get('auth_type') if (auth != 'Team leader' and auth != 'Member' and auth != 'Subteam leader'): flash('unauth', 'danger') return redirect(url_for("home.home_page")) schedule = select( columns= "schedule.name,schedule.deadline,schedule.done,schedule.description,person.name,schedule.id", table= "schedule join member on schedule.member_id=member.id join person on person.id=member.person_id join team on team.id=person.team_id order by schedule.done,schedule.deadline", where="team.id={}".format(session.get('team_id'))) return render_template("schedule_page.html", schedule=schedule)
def team_equipments_page(): auth = session.get('auth_type') if (auth != 'Team leader' and auth != 'Member' and auth != 'Subteam leader'): flash('unauth', 'danger') return redirect(url_for("home.home_page")) equipments = select( columns= "equipment.name,equipment.link,equipment.purchasedate,equipment.available,equipment.picture,subteam.name,equipment.id", table= "equipment join team on equipment.team_id = team.id join subteam on equipment.subteam_id=subteam.id", where="team.id = {}".format(session.get("team_id"))) return render_template("equipments_page.html", equipments=equipments)
def visitor_schedule_page(): auth = session.get('auth_type') if (auth != 'Team leader' and auth != 'Subteam leader' and auth != 'Member'): flash("Unauth", 'danger') return redirect(url_for("home.home_page")) member_id = session.get('member_id') schedule = select( columns= "schedule.name,schedule.deadline,schedule.done,schedule.description,person.name,schedule.id", table= "schedule join member on schedule.member_id=member.id join person on person.id=member.person_id", where="member.id={} order by schedule.done,schedule.deadline".format( member_id)) return render_template("schedule_page.html", schedule=schedule)
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_edit_schedule_page(schedule_id): auth = session.get('auth_type') print(auth) if (auth != "Team leader" and auth != "Subteam leader"): flash("Not an authorized person") return redirect(url_for("home.home_page")) member_id = session.get('member_id') form = EditScheduleForm() if (request.method == 'POST' and form.submit_edit_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 update( "schedule", "name='{}',deadline='{}',done='{}',description='{}',budget='{}', member_id='{}'" .format(name, deadline, done, description, budget, member_id), where="id={}".format(schedule_id)) return redirect(url_for("team.team_schedule_page")) else: result = select("schedule.name,deadline,done,description,budget", "schedule", "schedule.id={}".format(schedule_id)) print(result) form.name.data = result[0] form.deadline.data = result[1] form.done.data = result[2] form.description.data = result[3] form.budget.data = result[4] return render_template("member_edit_schedule_page.html", form=form, result=result)
def admin_edit_team_page(id): auth = session.get('auth_type') if (auth != 'admin' and (auth != 'Team leader' and id != session.get('team_id'))): flash('No admin privileges...', 'danger') return redirect(url_for('home.home_page')) form = EditTeamForm() competitions = select("id,name", "competition") form.competition.choices = competitions imgForm = UploadImageForm() imgFolder = os.path.join(os.getcwd(), 'static/images/team') if (request.method == 'POST' and form.submit_team.data or form.validate()): name = form.name.data members = form.memberCtr.data year = form.year.data email = form.email.data address = form.address.data competition = form.competition.data image = imgForm.image.data if (image and '.jpg' in image.filename or '.jpeg' in image.filename or '.png' in image.filename): date = time.gmtime() extension = image.filename.split('.')[1] filename = secure_filename("{}_{}.{}".format( id, date[0:6], extension)) filePath = os.path.join(imgFolder, filename) images = os.listdir(imgFolder) digits = int(math.log(int(id), 10)) + 1 for im in images: if (im[digits] == '_' and im[0:digits] == str(id)): os.remove(os.path.join(imgFolder, im)) image.save(filePath) update("team", "logo='{}'".format(filename), "id={}".format(id)) elif (image): flash("Please upload a file in JPG format", 'danger') update( "team", "name='{}', num_members={}, found_year='{}', email='{}', adress='{}', competition_id={}" .format(name, members, year, email, address, competition), where="id={}".format(id)) return redirect(url_for('admin_edit.admin_edit_team_page', id=id)) else: result = select( columns= "team.name,team.num_members,team.found_year,team.email,team.adress,team.logo,competition.id", table= "team left outer join competition on team.COMPETITION_ID=competition.id", where="team.id={}".format(id)) print("EDIT TEAM RESULT", result) form.name.data = result[0] form.memberCtr.data = result[1] form.year.data = result[2] form.email.data = result[3] form.address.data = result[4] img_name = result[5] form.competition.data = result[6] return render_template('admin_edit_team_page.html', form=form, result=result, uploadImg=imgForm, imgName=img_name) return render_template('admin_edit_team_page.html', form=form, result=result, uploadImg=imgForm, imgName=img_name)
def admin_edit_member_page(person_id): # TODO:: Alter table to include social accounts links in person database. auth = session.get('auth_type') if (auth != 'admin'): flash("No admin", 'danger') return redirect(url_for("home.home_page")) form = EditMemberForm() subteams = select( "subteam.id,subteam.name", "subteam join team on subteam.team_id=team.id join person on person.team_id=team.id", "person.id={}".format(person_id)) form.subteam.choices = subteams majors = select("major.id,major.name", "major") form.major.choices = majors auth_types = select("id,name", "auth_type") form.auth_type.choices = auth_types cvForm = UploadCVForm() cvPath = None cvFolder = os.path.join(os.getcwd(), 'static/cv') imgForm = UploadImageForm() imgPath = None imgFolder = os.path.join(os.getcwd(), 'static/images/person') member_id = select("member.id", "member join person on person.id=member.person_id", where="person.id={}".format(person_id))[0] if form.validate_on_submit(): team = form.team.data subteam = form.subteam.data role = form.role.data auth_type = form.auth_type.data email = form.email.data name = form.name.data address = form.address.data active = form.active.data age = form.age.data phone = form.phone.data clas = form.clas.data major = form.major.data cv = cvForm.cv.data image = imgForm.image.data if (cv and '.pdf' in cv.filename): date = time.gmtime() filename = secure_filename("{}_{}.pdf".format( person_id, date[0:6])) cvPath = os.path.join(cvFolder, filename) cvs = os.listdir(cvFolder) digits = int(math.log(int(person_id), 10)) + 1 for c in cvs: if (c[digits] == '_' and c[0:digits] == str(person_id)): os.remove(os.path.join(cvFolder, c)) cv.save(cvPath) update("person", "cv='{}'".format(filename), "id={}".format(person_id)) session['person_id'] = person_id elif (cv): flash("Upload a PDF file.", 'danger') if (image and '.jpg' in image.filename or '.jpeg' in image.filename or '.png' in image.filename): date = time.gmtime() extension = image.filename.split('.')[1] filename = secure_filename("{}_{}.{}".format( person_id, date[0:6], extension)) imgPath = os.path.join(imgFolder, filename) images = os.listdir(imgFolder) digits = int(math.log(int(person_id), 10)) + 1 for im in images: if (im[digits] == '_' and im[0:digits] == str(person_id)): os.remove(os.path.join(imgFolder, im)) image.save(imgPath) update("member", "picture='{}'".format(filename), "id={}".format(member_id)) elif (image): flash("Please upload a file in JPG format", 'danger') teamID = select(columns="id", table="team", where="name='{}'".format(team))[0] majorID = select(columns="id", table="major", where="id='{}'".format(major))[0] update("member", "role='{}', active={}, address='{}'".format( role, active, address), where="id={}".format(member_id)) update("person", "name='{}', age='{}', phone='{}',email='{}', \ class={}, auth_type={}, team_id={}, subteam_id={}, major_id={}".format( name, age, phone, email, clas, auth_type, teamID, subteam, majorID), where="id={}".format(person_id)) return redirect( url_for('admin_edit.admin_edit_member_page', person_id=person_id, cvPath=person_id)) else: result = select( "person.name,person.email,team.name,subteam.id,member.role,member.active, \ member.entrydate,auth_type.id,member.address,person.phone,major.id, \ person.class,person.age,person.cv,member.picture", "person join member on member.person_id=person.id \ join team on person.team_id=team.id \ join subteam on person.subteam_id=subteam.id \ join auth_type on person.auth_type=auth_type.id \ join major on person.major_id=major.id ", "person.id={}".format(person_id)) form.name.data = result[0] form.email.data = result[1] form.team.data = result[2] form.subteam.data = result[3] form.role.data = result[4] form.active.data = result[5] form.entry.data = result[6] form.auth_type.data = result[7] form.address.data = result[8] form.phone.data = result[9] form.major.data = result[10] form.clas.data = result[11] form.age.data = result[12] cvPath = result[13] img_name = result[14] return render_template('admin_edit_member_page.html', form=form, uploadImg=imgForm, uploadCV=cvForm, cvPath=cvPath, imgName=img_name)