aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGalen Guyer <galen@galenguyer.com>2022-10-03 10:41:06 -0400
committerGalen Guyer <galen@galenguyer.com>2022-10-03 10:45:48 -0400
commit9006bb289d481914d85e6c3279036692ca88c28d (patch)
tree8c982162dd23d2d3dc413089c23d98cac044b32b
parente5761dc7d331e0b39ae9bbd6e29acd078438baeb (diff)
Add page for evals with packets opened in the past semesterpast-packets
-rw-r--r--.tool-versions2
-rw-r--r--packet/models.py7
-rw-r--r--packet/routes/admin.py24
-rw-r--r--packet/templates/admin_past_packets.html21
-rw-r--r--packet/templates/include/nav.html3
-rw-r--r--packet/utils.py2
-rw-r--r--requirements.in2
-rw-r--r--requirements.txt6
8 files changed, 62 insertions, 5 deletions
diff --git a/.tool-versions b/.tool-versions
new file mode 100644
index 0000000..11bfbc4
--- /dev/null
+++ b/.tool-versions
@@ -0,0 +1,2 @@
+python 3.9.7
+nodejs 10.24.1
diff --git a/packet/models.py b/packet/models.py
index f22e467..dfb2fe5 100644
--- a/packet/models.py
+++ b/packet/models.py
@@ -130,6 +130,13 @@ class Packet(db.Model):
return cls.query.filter(cls.start < datetime.now(), cls.end > datetime.now()).all()
@classmethod
+ def opened_after(cls, date: datetime) -> list['Packet']:
+ """
+ Helper method for fetching all packets opened after a given date
+ """
+ return cls.query.filter(cls.start > date).all()
+
+ @classmethod
def by_id(cls, packet_id: int) -> 'Packet':
"""
Helper method for fetching 1 packet by its id
diff --git a/packet/routes/admin.py b/packet/routes/admin.py
index 96a877b..f4ae1ca 100644
--- a/packet/routes/admin.py
+++ b/packet/routes/admin.py
@@ -1,3 +1,5 @@
+import datetime
+
from flask import render_template
from packet import app
@@ -29,6 +31,28 @@ def admin_packets(info=None):
info=info)
+@app.route('/admin/past-packets')
+@log_cache
+@packet_auth
+@admin_auth
+@before_request
+@log_time
+def admin_past_packets(info=None):
+ open_packets = Packet.opened_after(datetime.date.today() - datetime.timedelta(days=(30 * 4)))
+
+ # Pre-calculate and store the return values of did_sign(), signatures_received(), and signatures_required()
+ for packet in open_packets:
+ packet.did_sign_result = packet.did_sign(info['uid'], app.config['REALM'] == 'csh')
+ packet.signatures_received_result = packet.signatures_received()
+ packet.signatures_required_result = packet.signatures_required()
+
+ open_packets.sort(key=packet_sort_key, reverse=False)
+
+ return render_template('admin_past_packets.html',
+ open_packets=open_packets,
+ info=info)
+
+
@app.route('/admin/freshmen')
@log_cache
@packet_auth
diff --git a/packet/templates/admin_past_packets.html b/packet/templates/admin_past_packets.html
new file mode 100644
index 0000000..71261c8
--- /dev/null
+++ b/packet/templates/admin_past_packets.html
@@ -0,0 +1,21 @@
+{% extends "extend/base.html" %}
+
+{% block body %}
+ <div class="container main">
+ <div class="ml-4">
+ <div class="row justify-content-between w-100">
+ <div class="col-xs-10">
+ <h4 class="page-title">Past Packets</h4>
+ </div>
+ </div>
+ </div>
+ <div id="eval-blocks">
+ {% include 'include/admin/open_packets.html' %}
+ </div>
+ </div>
+{% endblock %}
+
+{% block scripts %}
+ {{ super() }}
+ <script src="{{ url_for('static', filename='js/admin.min.js') }}"></script>
+{% endblock %}
diff --git a/packet/templates/include/nav.html b/packet/templates/include/nav.html
index 6573b8b..63720dd 100644
--- a/packet/templates/include/nav.html
+++ b/packet/templates/include/nav.html
@@ -26,7 +26,8 @@
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="{{ url_for("admin_freshmen") }}">Freshmen</a>
- <a class="dropdown-item" href="{{ url_for("admin_packets") }}">Packets</a>
+ <a class="dropdown-item" href="{{ url_for("admin_packets") }}">Active Packets</a>
+ <a class="dropdown-item" href="{{ url_for("admin_past_packets") }}">Past Packets</a>
</div>
</li>
{% endif %}
diff --git a/packet/utils.py b/packet/utils.py
index a6e9158..964ac9e 100644
--- a/packet/utils.py
+++ b/packet/utils.py
@@ -70,7 +70,7 @@ def before_reqest_callback() -> Any:
"""
Pre-request function to ensure we're on the right URL before OIDC sees anything
"""
- if urlparse(request.base_url).hostname != app.config['SERVER_NAME']:
+ if urlparse(request.base_url).hostname != app.config['SERVER_NAME'].split(':')[0]:
return redirect(request.base_url.replace(urlparse(request.base_url).hostname,
app.config['SERVER_NAME']), code=302)
return None
diff --git a/requirements.in b/requirements.in
index c0ccec2..c6dab1b 100644
--- a/requirements.in
+++ b/requirements.in
@@ -3,7 +3,7 @@ Flask-Mail==0.9.1
Flask-Migrate~=2.7.0
Flask-pyoidc~=3.7.0
Flask~=1.1.4
-csh_ldap~=2.3.1
+csh_ldap~=2.4.0
ddtrace==1.1.4
flask_sqlalchemy~=2.5.1
gunicorn~=20.0.4
diff --git a/requirements.txt b/requirements.txt
index baff1f9..f76cc2a 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -28,7 +28,7 @@ click==7.1.2
# pip-tools
cryptography==37.0.2
# via oic
-csh-ldap==2.3.1
+csh-ldap==2.4.0
# via -r requirements.in
ddsketch==2.0.3
# via ddtrace
@@ -60,6 +60,8 @@ flask-sqlalchemy==2.5.1
# flask-migrate
future==0.18.2
# via pyjwkest
+greenlet==1.1.3
+ # via sqlalchemy
gunicorn==20.0.4
# via -r requirements.in
idna==3.3
@@ -129,7 +131,7 @@ pylint-quotes==0.2.1
# via -r requirements.in
pyparsing==3.0.9
# via packaging
-python-ldap==3.0.0
+python-ldap==3.4.0
# via csh-ldap
requests==2.27.1
# via