-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
104 lines (75 loc) · 2.81 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import db_connect
from bson import ObjectId
from flask import *
from flask_restful import Api
from apis import student, prof
import qrcode
app = Flask(__name__)
api = Api(app)
@app.route("/")
def prof_or_student():
return render_template("auths.html")
@app.route("/student/signin")
def student_form():
return render_template("formstudent/form_student.html")
@app.route("/prof/signin")
def prof_form():
return render_template("form_prof.html")
@app.route("/student/54321")
def student_list():
students = db_connect.db.students.find()
list_student = list(students)
return render_template("liststud/list_student.html", len=len(list_student), students=list_student)
@app.route("/prof/12345")
def prof_list():
profs = db_connect.db.profs.find()
list_prof = list(profs)
return render_template("list_prof.html", len=len(list_prof), profs=list_prof)
@app.route("/p_inscrit")
def p_inscrit():
profs = db_connect.db.profs.find()
list_prof = list(profs)
return render_template("p_inscrit.html", len=len(list_prof), profs=list_prof)
@app.route("/e_inscrit")
def e_inscrit():
students = db_connect.db.students.find()
list_student = list(students)
return render_template("e_inscrit.html", len=len(list_student), students=list_student)
@app.route("/prof/<id>/details")
def prof_details(id):
profs = db_connect.db.profs.find_one({"_id": ObjectId(id)})
return render_template("prof_details.html", prof=profs)
@app.route("/student/<id>/details")
def student_details(id):
students = db_connect.db.students.find_one({"_id": ObjectId(id)})
return render_template("student_details.html", student=students)
@app.route("/prof/<id>/qrcode")
def prof_qrcode(id):
img = qrcode.make(id)
img_location = "pic_qr/" + id + ".jpg"
img_path = "static/" + img_location
img.save(img_path)
newvalues = {"$set": {"qrcode": img_location}}
db_connect.db.profs.update_one({"_id": ObjectId(id)}, newvalues)
profs = db_connect.db.profs.find_one({"_id": ObjectId(id)})
return render_template("prof_qr.html", prof=profs)
@app.route("/student/<id>/qrcode")
def student_qrcode(id):
img = qrcode.make(id)
img_location = "pic_qr/" + id + ".jpg"
img_path = "static/" + img_location
img.save(img_path)
newvalues = {"$set": {"qrcode": img_location}}
db_connect.db.students.update_one({"_id": ObjectId(id)}, newvalues)
students = db_connect.db.students.find_one({"_id": ObjectId(id)})
return render_template("student_qr.html", student=students)
@app.route("/scanner_e")
def scanner_e():
return render_template("scanner_etudiant.html")
@app.route("/scanner_p")
def scanner_p():
return render_template("scanner_prof.html")
api.add_resource(student.Students, "/student")
api.add_resource(prof.Profs, "/prof")
if __name__ == "__main__":
app.run(debug=True)