Skip to content

Commit 8411b1a

Browse files
committed
Refactored and fixed the freshmen pages
1 parent 39afd79 commit 8411b1a

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

packet/routes/freshmen.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,51 @@
1-
from flask import redirect, render_template, request
1+
"""
2+
Routes available to freshmen only
3+
"""
24

3-
from packet import auth, app
4-
from packet.packet import set_essays, get_current_packet
5+
from flask import redirect, render_template, request, url_for
6+
7+
from packet import auth, app, db
8+
from packet.models import Packet
59
from packet.utils import before_request
610

711

812
@app.route("/")
913
@auth.oidc_auth
1014
@before_request
1115
def index(info=None):
12-
return redirect("/packet/" + info['uid'], 302)
16+
most_recent_packet = Packet.query.filter_by(freshman_username=info['uid']).order_by(Packet.id.desc()).first()
17+
18+
if most_recent_packet is not None:
19+
return redirect(url_for("freshman_packet", freshman_username=most_recent_packet.freshman_username,
20+
packet_id=most_recent_packet.id), 302)
21+
else:
22+
return redirect(url_for("packets"), 302)
1323

1424

15-
@app.route("/essays")
25+
@app.route("/essays/<packet_id>/")
1626
@auth.oidc_auth
1727
@before_request
18-
def essays(info=None):
19-
packet = get_current_packet(info['uid'])
20-
return render_template("essays.html", info=info, packet=packet)
28+
def essays(packet_id, info=None):
29+
packet = Packet.query.filter_by(freshman_username=info['uid'], id=packet_id).first()
30+
31+
if packet is not None:
32+
return render_template("essays.html", info=info, packet=packet)
33+
else:
34+
return redirect(url_for("index"), 302)
2135

2236

23-
@app.route("/essay", methods=["POST"])
37+
@app.route("/essays/<packet_id>/", methods=["POST"])
2438
@auth.oidc_auth
2539
@before_request
26-
def submit_essay(info=None):
27-
formdata = request.form
28-
if set_essays(info['uid'], formdata['info_eboard'], formdata['info_events'], formdata['info_achieve']):
29-
return redirect("/essays", 302)
30-
return redirect("/essays", 500)
40+
def submit_essays(packet_id, info=None):
41+
packet = Packet.query.filter_by(freshman_username=info['uid'], id=packet_id).first()
42+
43+
if packet is not None:
44+
packet.info_eboard = request.form.get("info_eboard", None)
45+
packet.info_events = request.form.get("info_events", None)
46+
packet.info_achieve = request.form.get("info_achieve", None)
47+
48+
db.session.commit()
49+
return redirect(url_for("essays", packet_id=packet_id), 302)
50+
else:
51+
return redirect(url_for("index"), 302)

packet/templates/essays.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ <h3 class="page-title">Essays</h3>
1010
<div id="eval-blocks">
1111
<div id="eval-table">
1212
<div class="card">
13-
14-
<form action="/essay" method="post">
13+
<form action="{{ url_for("submit_essays", packet_id=packet.id) }}" method="post">
1514
<div class="card-body table-fill">
15+
<div class="form-group card-body">
16+
Answer each prompt with a few sentences or a sort list.
17+
</div>
1618
<div class="form-group card-body">
1719
<label for="info_eboard">Name and list all EBoard Members and their positions</label>
1820
<textarea class="form-control"

packet/templates/include/nav.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
<li class="nav-item">
1919
<a class="nav-link" href="{{ url_for("upperclassmen_total") }}">Signatures</a>
2020
</li>
21-
{% else %}
21+
{% elif packet is defined and packet.freshman_username == info.uid %}
2222
<li class="nav-item">
23-
<a class="nav-link" href="{{ url_for("essays") }}">Essays</a>
23+
<a class="nav-link" href="{{ url_for("essays", packet_id=packet.id) }}">Essays</a>
2424
</li>
2525
{% endif %}
2626

0 commit comments

Comments
 (0)