-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
84 lines (65 loc) · 2.96 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from flask import Flask, render_template, request, url_for, redirect
import data_manager
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
return render_template('index.html')
@app.route('/mentors')
def mentors_list():
mentor_name = request.args.get('mentor-last-name')
city_name = request.args.get('city-name')
if mentor_name:
mentor_details = data_manager.get_mentors_by_last_name(mentor_name)
elif city_name:
mentor_details = data_manager.get_mentors_by_city(city_name)
else:
mentor_details = data_manager.get_mentors()
# We get back a list of dictionaries from the data_manager (for details check 'data_manager.py')
return render_template('mentors.html', mentors=mentor_details, cities=mentor_details)
@app.route('/applicants-phone', methods=['GET', 'POST'])
def search_for_applicant():
first_name = request.args.get('applicant-name')
last_name = request.args.get('applicant-name')
email_ending = request.args.get('e-mail_ending')
if first_name or last_name:
applicant_details = data_manager.get_applicant_data_by_name(first_name, last_name)
if email_ending:
applicant_details = data_manager.get_applicant_data_by_email_ending(
email_ending)
return render_template('index.html', applicants=applicant_details)
@app.route("/applicants", methods=["GET", "POST"])
def applicants_list():
if request.method == "GET":
applicants_detail = data_manager.get_applicants()
return render_template("applicants.html", applicants=applicants_detail)
else:
application_code = request.form["code"]
phone_number = request.form.get("phone_number")
data_manager.update_phone_number(phone_number, application_code)
return redirect("/")
@app.route("/applicants/<code>", methods=['GET', 'POST'])
def update():
applicants_detail = data_manager.get_applicants()
if request.method == "POST":
phone_number = request.form.get("phone_number")
data_manager.update_phone_number(phone_number, application_code)
return redirect("/")
return render_template("update_applicant.html", applicants_detail=applicants_detail)
@app.route("/applicants/<code>/delete", methods=['GET', 'POST'])
def delete():
applicants_detail = data_manager.get_applicants()
return redirect('/applicants')
# delete by email
@app.route("/add-applicant", methods=['GET', 'POST'])
def add():
if request.method == "POST":
first_name = request.form.get("first-name")
last_name = request.form.get("last-name")
phone_number = request.form.get("phone-number")
email = request.form.get("email")
application_code = request.form.get("application-code")
data_manager.add_new_applicant(first_name, last_name, phone_number, email, application_code)
return redirect('/applicants/<code>')
return render_template('add_applicant.html')
if __name__ == '__main__':
app.run(debug=True)