Skip to content

Commit 123e3cb

Browse files
committed
Refactored the view packet page using the new did_sign() function
1 parent e6659a4 commit 123e3cb

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

packet/routes/shared.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from itertools import chain
21
from datetime import datetime
32
from flask import render_template, redirect
43

54
from packet import auth, app
65
from packet.utils import before_request
7-
from packet.models import MiscSignature, Packet
6+
from packet.models import Packet
87

98

109
@app.route('/logout')
@@ -22,28 +21,20 @@ def freshman_packet(freshman_username, packet_id, info=None):
2221
if packet is None:
2322
return "Invalid packet or freshman", 404
2423
else:
25-
can_sign = False
26-
did_sign = False
27-
28-
if app.config["REALM"] == "csh":
29-
can_sign = packet.is_open()
30-
31-
for sig in filter(lambda sig: sig.member == info["uid"], chain(packet.upper_signatures,
32-
packet.misc_signatures)):
33-
if isinstance(sig, MiscSignature):
34-
did_sign = True
35-
else:
36-
did_sign = sig.signed
37-
38-
break
39-
else:
40-
for sig in filter(lambda sig: sig.freshman_username == info["uid"], packet.fresh_signatures):
41-
can_sign = packet.is_open()
42-
did_sign = sig.signed
43-
break
44-
45-
return render_template("packet.html", info=info, packet=packet, can_sign=can_sign, did_sign=did_sign,
46-
required=packet.signatures_required(), received=packet.signatures_received(),
24+
can_sign = packet.is_open()
25+
26+
# If the packet is open and the user is an off-floor freshman set can_sign to False
27+
if packet.is_open() and app.config["REALM"] != "csh":
28+
if info["uid"] not in map(lambda sig: sig.freshman_username, packet.fresh_signatures):
29+
can_sign = False
30+
31+
return render_template("packet.html",
32+
info=info,
33+
packet=packet,
34+
can_sign=can_sign,
35+
did_sign=packet.did_sign(info["uid"], app.config["REALM"] == "csh"),
36+
required=packet.signatures_required(),
37+
received=packet.signatures_received(),
4738
eboard=filter(lambda sig: sig.eboard, packet.upper_signatures),
4839
upper=filter(lambda sig: not sig.eboard, packet.upper_signatures))
4940

0 commit comments

Comments
 (0)