Skip to content

Commit 87d6fb3

Browse files
authored
Merge pull request #99 from ComputerScienceHouse/develop
Packet version 3.1.0
2 parents 3f89cc8 + 6a7b50c commit 87d6fb3

25 files changed

+435
-687
lines changed

.pylintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ disable =
1414
global-statement,
1515
cyclic-import,
1616
locally-disabled,
17-
file-ignored
17+
file-ignored,
18+
no-else-return
1819

1920
[REPORTS]
2021
output-format = text

config.env.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@
88
SECRET_KEY = environ.get("PACKET_SECRET_KEY", "PLEASE_REPLACE_ME")
99

1010
# OpenID Connect SSO config
11-
REALM = environ.get("PACKET_REALM", "intro")
11+
REALM = environ.get("PACKET_REALM", "csh")
1212

1313
OIDC_ISSUER = environ.get("PACKET_OIDC_ISSUER", "https://sso.csh.rit.edu/auth/realms/csh")
1414
OIDC_CLIENT_ID = environ.get("PACKET_OIDC_CLIENT_ID", "packet")
1515
OIDC_CLIENT_SECRET = environ.get("PACKET_OIDC_CLIENT_SECRET", "PLEASE_REPLACE_ME")
1616

17-
# SAML config
18-
SAML_METADATA_URL = environ.get("PACKET_SAML_METADATA_URL", "https://shibboleth.main.ad.rit.edu/rit-metadata.xml")
19-
2017
# SQLAlchemy config
2118
SQLALCHEMY_DATABASE_URI = environ.get("PACKET_DATABASE_URI", None)
2219
SQLALCHEMY_TRACK_MODIFICATIONS = False

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"title": "CSH Packet",
33
"name": "csh-packet",
4-
"version": "3.0.5",
4+
"version": "3.1.0",
55
"description": "A webpacket for CSH",
66
"bugs": {
77
"url": "https://github.com/ComputerScienceHouse/packet/issues",

packet/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,20 @@
2929

3030
auth = OIDCAuthentication(app, issuer=app.config["OIDC_ISSUER"], client_registration_info={
3131
"client_id": app.config["OIDC_CLIENT_ID"],
32-
"client_secret": app.config["OIDC_CLIENT_SECRET"]
32+
"client_secret": app.config["OIDC_CLIENT_SECRET"],
33+
"post_logout_redirect_uris": "/logout/"
3334
})
3435

3536
# LDAP
36-
_ldap = csh_ldap.CSHLDAP(app.config['LDAP_BIND_DN'], app.config['LDAP_BIND_PASS'])
37+
_ldap = csh_ldap.CSHLDAP(app.config["LDAP_BIND_DN"], app.config["LDAP_BIND_PASS"])
3738

3839
# pylint: disable=wrong-import-position
40+
from . import models
41+
from . import context_processors
42+
from . import commands
43+
from .routes import api, shared
44+
3945
if app.config["REALM"] == "csh":
4046
from .routes import upperclassmen
4147
else:
4248
from .routes import freshmen
43-
44-
from .routes import api, shared
45-
from . import commands
46-
from . import models

packet/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.0.6"
1+
__version__ = "3.1.0"

packet/commands.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .models import Freshman, Packet, FreshSignature, UpperSignature, MiscSignature
1212
from .ldap import ldap_get_eboard, ldap_get_live_onfloor
1313

14+
1415
@app.cli.command("create-secret")
1516
def create_secret():
1617
"""
@@ -19,15 +20,18 @@ def create_secret():
1920
print("Here's your random secure token:")
2021
print(token_hex())
2122

23+
2224
packet_start_time = time(hour=19)
2325
packet_end_time = time(hour=21)
2426

27+
2528
class CSVFreshman:
2629
def __init__(self, row):
2730
self.name = row[0]
2831
self.rit_username = row[3]
2932
self.onfloor = row[1] == "TRUE"
3033

34+
3135
def parse_csv(freshmen_csv):
3236
print("Parsing file...")
3337
try:
@@ -37,6 +41,7 @@ def parse_csv(freshmen_csv):
3741
print("Failure while parsing CSV")
3842
raise e
3943

44+
4045
@app.cli.command("sync-freshmen")
4146
@click.argument("freshmen_csv")
4247
def sync_freshmen(freshmen_csv):
@@ -82,6 +87,7 @@ def sync_freshmen(freshmen_csv):
8287
db.session.commit()
8388
print("Done!")
8489

90+
8591
@app.cli.command("create-packets")
8692
@click.argument("freshmen_csv")
8793
def create_packets(freshmen_csv):
@@ -126,6 +132,7 @@ def create_packets(freshmen_csv):
126132
db.session.commit()
127133
print("Done!")
128134

135+
129136
@app.cli.command("ldap-sync")
130137
def ldap_sync():
131138
"""
@@ -162,6 +169,7 @@ def ldap_sync():
162169
db.session.commit()
163170
print("Done!")
164171

172+
165173
@app.cli.command("fetch-results")
166174
def fetch_results():
167175
"""
@@ -186,20 +194,14 @@ def fetch_results():
186194
received = packet.signatures_received()
187195
required = packet.signatures_required()
188196

189-
upper_ratio = sum((received["eboard"], received["upperclassmen"], received["miscellaneous"])) / \
190-
sum((required["eboard"], required["upperclassmen"], required["miscellaneous"]))
191-
print("\tUpperclassmen score: {}%".format(round(upper_ratio * 100, 2)))
192-
193-
total_ratio = sum(received.values()) / sum(required.values())
194-
print("\tTotal score: {}%".format(round(total_ratio * 100, 2)))
195-
197+
print("\tUpperclassmen score: {:0.2f}%".format(received.member_total / required.member_total * 100))
198+
print("\tTotal score: {:0.2f}%".format(received.total / required.total * 100))
196199
print()
197200

198-
print("\tEboard: {}/{}".format(received["eboard"], required["eboard"]))
199-
print("\tUpperclassmen: {}/{}".format(received["upperclassmen"], required["upperclassmen"]))
200-
print("\tFreshmen: {}/{}".format(received["freshmen"], required["freshmen"]))
201-
print("\tMiscellaneous: {}/{}".format(len(packet.misc_signatures), required["miscellaneous"]))
202-
201+
print("\tEboard: {}/{}".format(received.eboard, required.eboard))
202+
print("\tUpperclassmen: {}/{}".format(received.upper, required.upper))
203+
print("\tFreshmen: {}/{}".format(received.fresh, required.fresh))
204+
print("\tMiscellaneous: {}/{}".format(received.misc, required.misc))
203205
print()
204206

205-
print("\tTotal missed:", sum(required.values()) - sum(received.values()))
207+
print("\tTotal missed:", required.total - received.total)

packet/context_processors.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Context processors used by the jinja templates
3+
"""
4+
5+
from functools import lru_cache
6+
from datetime import datetime
7+
8+
from packet.ldap import ldap_get_member
9+
from packet.models import Freshman
10+
from packet import app
11+
12+
13+
# pylint: disable=bare-except
14+
@lru_cache(maxsize=128)
15+
def get_csh_name(username):
16+
try:
17+
member = ldap_get_member(username)
18+
return member.cn + " (" + member.uid + ")"
19+
except:
20+
return username
21+
22+
23+
# pylint: disable=bare-except
24+
@lru_cache(maxsize=128)
25+
def get_rit_name(username):
26+
try:
27+
freshman = Freshman.query.filter_by(rit_username=username).first()
28+
return freshman.name + " (" + username + ")"
29+
except:
30+
return username
31+
32+
33+
def log_time(label):
34+
"""
35+
Used during debugging to log timestamps while rendering templates
36+
"""
37+
print(label, datetime.now())
38+
39+
40+
@app.context_processor
41+
def utility_processor():
42+
return dict(get_csh_name=get_csh_name, get_rit_name=get_rit_name, log_time=log_time)

packet/debug_utils.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
General utilities for use when debugging
3+
"""
4+
5+
from functools import wraps
6+
from datetime import datetime
7+
8+
from packet import context_processors
9+
10+
11+
def log_time(func):
12+
"""
13+
Decorator for logging the execution time of a function
14+
"""
15+
@wraps(func)
16+
def wrapped_function(*args, **kwargs):
17+
start = datetime.now()
18+
19+
result = func(*args, **kwargs)
20+
21+
seconds = (datetime.now() - start).total_seconds()
22+
print("{}.{}() returned after {} seconds".format(func.__module__, func.__name__, seconds))
23+
24+
return result
25+
26+
return wrapped_function
27+
28+
29+
def log_cache():
30+
"""
31+
Utility call for logging cache info
32+
"""
33+
print("get_csh_name():", context_processors.get_csh_name.cache_info())
34+
print("get_rit_name():", context_processors.get_rit_name.cache_info())

packet/member.py

Lines changed: 0 additions & 161 deletions
This file was deleted.

0 commit comments

Comments
 (0)