Skip to content

Commit 27b80ff

Browse files
JoelEagerdevinmatte
authored andcommitted
Add current packets collection logic
1 parent 22471bb commit 27b80ff

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packet/routes/shared.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from flask import render_template
2+
from datetime import datetime
3+
from itertools import chain
24

35
from packet import auth, app
46
from packet.models import Freshman, Packet
@@ -23,5 +25,18 @@ def freshman_packet(uid, info=None):
2325
@auth.oidc_auth
2426
@before_request
2527
def packets(info=None):
26-
packets = Packet.query.all()
28+
packets = Packet.query.filter(Packet.end > datetime.now()).filter(Packet.start < datetime.now()).all()
29+
30+
# Add the did_sign flag
31+
if app.config["REALM"] == "csh":
32+
# User is an upperclassman
33+
for packet in packets:
34+
for sig in chain(packet.upper_signatures, packet.misc_signatures):
35+
packet.did_sign = sig.member == info["uid"]
36+
else:
37+
# User is a freshman
38+
for packet in packets:
39+
for sig in packet.fresh_signatures:
40+
packet.did_sign = sig.freshman_username == info["uid"]
41+
2742
return render_template("active_packets.html", info=info, packets=packets)

0 commit comments

Comments
 (0)