idk
This commit is contained in:
43
app.py
43
app.py
@@ -38,6 +38,7 @@ class Event(db.Model):
|
||||
|
||||
class Room(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
type = db.Column(db.String)
|
||||
room = db.Column(db.String(64), unique=True)
|
||||
count = db.Column(db.Integer, default=0)
|
||||
max = db.Column(db.Integer, default=2)
|
||||
@@ -142,6 +143,9 @@ def scan():
|
||||
student = Student.query.filter_by(uid=data["uid"]).first()
|
||||
location = data["location_id"]
|
||||
room = Room.query.filter_by(room=location).first()
|
||||
if not room:
|
||||
room = Room(room=location)
|
||||
db.session.add(room)
|
||||
student.last_reader = location
|
||||
student.last_scan = now()
|
||||
if action == "":
|
||||
@@ -176,12 +180,16 @@ def scan():
|
||||
def lightsBathroom(id):
|
||||
|
||||
room = Room.query.filter_by(room=id).first()
|
||||
bathroom = Room.query.filter_by(room=room.bathroom_id).first()
|
||||
if not room:
|
||||
room = Room(room=id)
|
||||
db.session.add(room)
|
||||
db.session.commit()
|
||||
if (room.bathroom and bathroom.count < bathroom.max):
|
||||
bathroom = Room.query.filter_by(room=room.bathroom_id).first()
|
||||
if not bathroom:
|
||||
bathroomCount = True
|
||||
else:
|
||||
bathroomCount = bathroom.count < bathroom.max
|
||||
if (room.bathroom and bathroomCount):
|
||||
code = 202
|
||||
else:
|
||||
code = 200
|
||||
@@ -222,11 +230,33 @@ def admin_rooms():
|
||||
|
||||
rooms = Room.query.all()
|
||||
|
||||
bathrooms = Room.query.filter_by(
|
||||
type="bathroom"
|
||||
).all()
|
||||
|
||||
return render_template(
|
||||
"admin/rooms.html",
|
||||
rooms=rooms
|
||||
rooms=rooms,
|
||||
bathrooms=bathrooms
|
||||
)
|
||||
|
||||
@app.route(
|
||||
"/admin/room/create",
|
||||
methods=["POST"]
|
||||
)
|
||||
def create_room():
|
||||
|
||||
room = Room(
|
||||
room=request.form["room"],
|
||||
type=request.form["room_type"],
|
||||
max=int(request.form["max"]),
|
||||
count=0
|
||||
)
|
||||
|
||||
db.session.add(room)
|
||||
db.session.commit()
|
||||
|
||||
return admin_rooms()
|
||||
|
||||
@app.route("/admin/anomalies")
|
||||
def admin_anomalies():
|
||||
@@ -294,7 +324,10 @@ def merge_student():
|
||||
)
|
||||
def update_room(id):
|
||||
|
||||
room = Room.query.get(id)
|
||||
room = Room.query.filter_by(id=id).first()
|
||||
room.type = request.form[
|
||||
"room_type"
|
||||
]
|
||||
|
||||
room.max = int(
|
||||
request.form["max"]
|
||||
@@ -304,7 +337,7 @@ def update_room(id):
|
||||
"bathroom_id"
|
||||
]
|
||||
|
||||
room.tracks_bathroom = (
|
||||
room.bathroom = (
|
||||
"tracks_bathroom"
|
||||
in request.form
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user