Skip to content

Commit 810e928

Browse files
committed
Pulling packet data Frontend
1 parent 69097d5 commit 810e928

File tree

11 files changed

+217
-96
lines changed

11 files changed

+217
-96
lines changed

frontend/scss/packet.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ $csh-pink: #b0197e;
44

55
@import "components/switches";
66
@import "components/datatables";
7-
@import "components/buttons";
7+
@import "components/buttons";

packet/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import os
66

77
import csh_ldap
8+
import flask_saml
89
from flask import Flask
10+
from flask_migrate import Migrate
911
from flask_pyoidc.flask_pyoidc import OIDCAuthentication
1012
from flask_sqlalchemy import SQLAlchemy
11-
from flask_migrate import Migrate
12-
import flask_saml
1313

1414
app = Flask(__name__)
1515

@@ -39,7 +39,7 @@
3939
from .routes import upperclassmen
4040
else:
4141
from .routes import freshmen
42-
from .routes import api
42+
from .routes import api, shared
4343

4444
from . import commands
4545
from . import models

packet/ldap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _ldap_is_member_of_directorship(account, directorship):
2828

2929
# Getters
3030

31-
31+
@lru_cache(maxsize=4096)
3232
def ldap_get_member(username):
3333
return _ldap.get_member(username, uid=True)
3434

packet/routes/freshmen.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
from flask import render_template, redirect
1+
from flask import redirect
22

33
from packet import auth, app
4-
from packet.ldap import ldap_get_live_onfloor, ldap_get_eboard
54
from packet.utils import before_request
65

76

@@ -10,31 +9,3 @@
109
@before_request
1110
def index(info=None):
1211
return redirect("/packet/" + info['uid'], 302)
13-
14-
15-
@app.route("/packet/<uid>")
16-
@auth.oidc_auth
17-
@before_request
18-
def freshman_packet(uid, info=None):
19-
onfloor = ldap_get_live_onfloor()
20-
eboard = ldap_get_eboard()
21-
return render_template("packet.html", info=info, eboard=eboard, onfloor=onfloor, uid=uid)
22-
23-
24-
@app.route("/packets")
25-
@auth.oidc_auth
26-
@before_request
27-
def packets(info=None):
28-
freshmen = [
29-
{
30-
"name": "Testiboi",
31-
"signatures": 12,
32-
"uid": 111
33-
},
34-
{
35-
"name": "Ram Zallllllan",
36-
"signatures": 69,
37-
"uid": 420
38-
}
39-
]
40-
return render_template("active_packets.html", info=info, freshmen=freshmen)

packet/routes/shared.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from flask import render_template
2+
3+
from packet import auth, app
4+
from packet.models import Freshman, Packet
5+
from packet.packet import get_signatures, get_number_required, get_number_signed
6+
from packet.utils import before_request
7+
8+
9+
@app.route("/packet/<uid>")
10+
@auth.oidc_auth
11+
@before_request
12+
def freshman_packet(uid, info=None):
13+
freshman = Freshman.query.filter_by(rit_username=uid)[0]
14+
signatures = get_signatures(uid)
15+
required = get_number_required(uid)
16+
signed = get_number_signed(uid)
17+
return render_template("packet.html", info=info, signatures=signatures, uid=uid, required=required, signed=signed,
18+
freshman=freshman)
19+
20+
21+
@app.route("/packets")
22+
@auth.oidc_auth
23+
@before_request
24+
def packets(info=None):
25+
packets = Packet.query.all()
26+
return render_template("active_packets.html", info=info, packets=packets)

packet/routes/upperclassmen.py

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from flask import render_template, redirect
1+
from flask import redirect, render_template
22

33
from packet import auth, app
4-
from packet.ldap import ldap_get_live_onfloor, ldap_get_eboard
4+
from packet.models import UpperSignature
55
from packet.utils import before_request
66

77

@@ -11,29 +11,9 @@ def index():
1111
return redirect("/packets", 302)
1212

1313

14-
@app.route("/packet/<uid>")
14+
@app.route("/member/<uid>")
1515
@auth.oidc_auth
1616
@before_request
17-
def freshman_packet(uid, info=None):
18-
onfloor = ldap_get_live_onfloor()
19-
eboard = ldap_get_eboard()
20-
return render_template("packet.html", info=info, eboard=eboard, onfloor=onfloor, uid=uid)
21-
22-
23-
@app.route("/packets")
24-
@auth.oidc_auth
25-
@before_request
26-
def packets(info=None):
27-
freshmen = [
28-
{
29-
"name": "Testiboi",
30-
"signatures": 12,
31-
"uid": 111
32-
},
33-
{
34-
"name": "Ram Zallllllan",
35-
"signatures": 69,
36-
"uid": 420
37-
}
38-
]
39-
return render_template("active_packets.html", info=info, freshmen=freshmen)
17+
def upperclassman(uid, info=None):
18+
signatures = UpperSignature.query.filter_by(member=uid).order_by(UpperSignature.signed.desc())
19+
return render_template("upperclassman.html", info=info, signatures=signatures, member=uid)

packet/templates/active_packets.html

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ <h3 class="page-title">Active Packets</h3>
88
</div>
99
</div>
1010
<div id="eval-blocks">
11-
{% if freshmen|length > 0 %}
11+
{% if packets|length > 0 %}
1212
<div id="eval-table">
1313
<div class="card">
1414
<div class="card-body table-fill">
@@ -21,31 +21,30 @@ <h3 class="page-title">Active Packets</h3>
2121
<tr>
2222
<th>Name</th>
2323
<th>Signatures</th>
24-
<th>Percentage</th>
2524
</tr>
2625
</thead>
2726
<tbody>
28-
{% for m in freshmen %}
29-
<tr>
30-
<td>
31-
{{ m['name'] }}
32-
</td>
33-
<td>
34-
<span class="glyphicon glyphicon-ok-sign green eval-info-status"></span>
35-
{{ m['signatures'] }}
36-
</td>
37-
<td>
38-
<span class="glyphicon glyphicon-ok-sign green eval-info-status"></span>
39-
{{ m['total_percent'] }}
40-
</td>
41-
<td class="sign-packet" align="right">
42-
{# if not signed #}
43-
<button class="btn btn-primary">Sign</button>
44-
{# else if signed #}
45-
<button class="btn btn-primary" disabled="disabled"><i class="fa fa-check"></i>&nbsp;Signed</button>
46-
{# endif #}
47-
</td>
48-
</tr>
27+
{% for packet in packets %}
28+
{% if packet.is_open() %}
29+
<tr>
30+
<td>
31+
{{ packet.freshman.name }}
32+
</td>
33+
<td>
34+
<span class="glyphicon glyphicon-ok-sign green eval-info-status"></span>
35+
{{ packet.signatures_received() }}
36+
</td>
37+
<td class="sign-packet" align="right">
38+
{# if not signed #}
39+
<button class="btn btn-primary">Sign</button>
40+
{# else if signed #}
41+
<button class="btn btn-primary" disabled="disabled"><i
42+
class="fa fa-check"></i>&nbsp;Signed
43+
</button>
44+
{# endif #}
45+
</td>
46+
</tr>
47+
{% endif %}
4948
{% endfor %}
5049
</tbody>
5150
</table>

packet/templates/include/head.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet"/>
2424

25-
<link rel="stylesheet" href="/static/css/packet.css">
25+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
2626

27-
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">
27+
<link rel="stylesheet" href="/static/css/packet.css">
2828

2929
</head>

packet/templates/packet.html

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
<div class="container main">
55
<div class="row mobile-hide">
66
<div class="col-sm-10">
7-
<h3 class="page-title">Packet Name</h3>
7+
<h3 class="page-title">{{ freshman.name }}</h3>
88
</div>
99
</div>
10+
<div>
11+
Signatures: {{ signed }}/{{ required }}
12+
</div>
1013
<div id="eval-blocks">
1114
<div id="eval-table">
1215
<div class="card mb-3">
@@ -23,13 +26,81 @@ <h3 class="page-title">Packet Name</h3>
2326
</tr>
2427
</thead>
2528
<tbody>
26-
{% for m in eboard %}
29+
{% for m in signatures.eboard %}
30+
<tr>
31+
<td>
32+
<img class="eval-user-img" alt="{{ m['member'] }}"
33+
src="https://profiles.csh.rit.edu/image/{{ m['member'] }}"
34+
width="30"
35+
height="30"/> {{ get_display_name(m.member) }}
36+
</td>
37+
<td>
38+
<span class="glyphicon glyphicon-ok-sign green eval-info-status"></span>
39+
{{ m['signed'] }}
40+
</td>
41+
</tr>
42+
{% endfor %}
43+
</tbody>
44+
</table>
45+
</div>
46+
</div>
47+
</div>
48+
</div>
49+
<div class="card mb-3">
50+
<div class="card-body table-fill">
51+
<div class="card-body table-fill">
52+
<div class="table-responsive">
53+
<table class="table table-striped no-bottom-margin" data-module="table"
54+
data-searchable="true" data-sort-column="3" data-sort-order="asc"
55+
data-length-changable="true" data-paginated="false">
56+
<thead>
57+
<tr>
58+
<th>Name</th>
59+
<th>Signature</th>
60+
</tr>
61+
</thead>
62+
<tbody>
63+
{% for m in signatures.upperclassmen %}
64+
<tr>
65+
<td>
66+
<img class="eval-user-img" alt="{{ m['member'] }}"
67+
src="https://profiles.csh.rit.edu/image/{{ m['member'] }}"
68+
width="30"
69+
height="30"/> {{ get_display_name(m.member) }}
70+
</td>
71+
<td>
72+
<span class="glyphicon glyphicon-ok-sign green eval-info-status"></span>
73+
{{ m['signed'] }}
74+
</td>
75+
</tr>
76+
{% endfor %}
77+
</tbody>
78+
</table>
79+
</div>
80+
</div>
81+
</div>
82+
</div>
83+
<div class="card mb-3">
84+
<div class="card-body table-fill">
85+
<div class="card-body table-fill">
86+
<div class="table-responsive">
87+
<table class="table table-striped no-bottom-margin" data-module="table"
88+
data-searchable="true" data-sort-column="3" data-sort-order="asc"
89+
data-length-changable="true" data-paginated="false">
90+
<thead>
91+
<tr>
92+
<th>Name</th>
93+
<th>Signature</th>
94+
</tr>
95+
</thead>
96+
<tbody>
97+
{% for m in signatures.freshmen %}
2798
<tr>
2899
<td>
29-
<img class="eval-user-img" alt="{{ m['uid'] }}"
30-
src="https://profiles.csh.rit.edu/image/{{ m['uid'] }}"
100+
<img class="eval-user-img" alt="{{ m.freshman }}"
101+
src="https://profiles.csh.rit.edu/image/{{ m.freshman }}"
31102
width="30"
32-
height="30"/> {{ m['name'] }}
103+
height="30"/> {{ get_freshman_name(m.freshman) }}
33104
</td>
34105
<td>
35106
<span class="glyphicon glyphicon-ok-sign green eval-info-status"></span>
@@ -57,13 +128,13 @@ <h3 class="page-title">Packet Name</h3>
57128
</tr>
58129
</thead>
59130
<tbody>
60-
{% for m in onfloor %}
131+
{% for m in signatures.misc %}
61132
<tr>
62133
<td>
63-
<img class="eval-user-img" alt="{{ m['uid'] }}"
64-
src="https://profiles.csh.rit.edu/image/{{ m['uid'] }}"
134+
<img class="eval-user-img" alt="{{ m['member'] }}"
135+
src="https://profiles.csh.rit.edu/image/{{ m['member'] }}"
65136
width="30"
66-
height="30"/> {{ m['name'] }}
137+
height="30"/> {{ get_display_name(m.member) }}
67138
</td>
68139
<td>
69140
<span class="glyphicon glyphicon-ok-sign green eval-info-status"></span>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{% extends "extend/base.html" %}
2+
3+
{% block body %}
4+
<div class="container main">
5+
<div class="row mobile-hide">
6+
<div class="col-sm-10">
7+
<h3 class="page-title">{{ get_display_name(member) }}</h3>
8+
</div>
9+
</div>
10+
<div id="eval-blocks">
11+
<div id="eval-table">
12+
<div class="card mb-3">
13+
<div class="card-body table-fill">
14+
<div class="card-body table-fill">
15+
<div class="table-responsive">
16+
<table class="table table-striped no-bottom-margin" data-module="table"
17+
data-searchable="true" data-sort-column="3" data-sort-order="asc"
18+
data-length-changable="true" data-paginated="false">
19+
<thead>
20+
<tr>
21+
<th>Name</th>
22+
<th>Signature</th>
23+
</tr>
24+
</thead>
25+
<tbody>
26+
{% for m in signatures %}
27+
{# Using inline style because of how themeswitcher loads the css theme :( #}
28+
<tr {% if m.signed %}style="background-color: #4caf505e" {% endif %}>
29+
<td>
30+
<img class="eval-user-img" alt="{{ m.packet.freshman.rit_username }}"
31+
src="https://profiles.csh.rit.edu/image/{{ m.packet.freshman.rit_username }}"
32+
width="30"
33+
height="30"/> {{ get_freshman_name(m.packet.freshman.name) }}
34+
</td>
35+
<td>
36+
{% if m.signed %}
37+
<i class="fas fa-check"></i>
38+
{% else %}
39+
<i class="fas fa-times"></i>
40+
{% endif %}
41+
</td>
42+
</tr>
43+
{% endfor %}
44+
</tbody>
45+
</table>
46+
</div>
47+
</div>
48+
</div>
49+
</div>
50+
</div>
51+
</div>
52+
</div>
53+
{% endblock %}

0 commit comments

Comments
 (0)