Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add page for evals with packets opened in the past semester #350

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python 3.9.7
nodejs 10.24.1
7 changes: 7 additions & 0 deletions packet/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ def open_packets(cls) -> list['Packet']:
"""
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':
"""
Expand Down
24 changes: 24 additions & 0 deletions packet/routes/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime

from flask import render_template

from packet import app
Expand Down Expand Up @@ -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)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30*4? does conditional do any awareness of what the current semester is that we could throw a rough start date here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or is this intended to be "recent"?
future: wonder if evals would like a date selector


# 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
Expand Down
21 changes: 21 additions & 0 deletions packet/templates/admin_past_packets.html
Original file line number Diff line number Diff line change
@@ -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 %}
3 changes: 2 additions & 1 deletion packet/templates/include/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should this be Recent Packets?

</div>
</li>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion packet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down