Skip to content
Merged
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
13 changes: 10 additions & 3 deletions packet/routes/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,28 @@ def freshman_packet(packet_id, info=None):
if info['uid'] not in map(lambda sig: sig.freshman_username, packet.fresh_signatures):
can_sign = False

# The current user's freshman signature on this packet
fresh_sig = list(filter(
lambda sig: sig.freshman_username == info['ritdn'] if info else '',
packet.fresh_signatures
))

return render_template('packet.html',
info=info,
packet=packet,
can_sign=can_sign,
did_sign=packet.did_sign(info['uid'], app.config['REALM'] == 'csh'),
required=packet.signatures_required(),
received=packet.signatures_received(),
upper=packet.upper_signatures)
upper=packet.upper_signatures,
fresh_sig=fresh_sig)


def packet_sort_key(packet):
"""
Utility function for generating keys for sorting packets
"""
return packet.signatures_received_result.total, packet.did_sign_result
return packet.freshman.name, -packet.signatures_received_result.total, not packet.did_sign_result


@app.route('/packets/')
Expand All @@ -65,7 +72,7 @@ def packets(info=None):
packet.signatures_received_result = packet.signatures_received()
packet.signatures_required_result = packet.signatures_required()

open_packets.sort(key=packet_sort_key, reverse=True)
open_packets.sort(key=packet_sort_key)

return render_template('active_packets.html', info=info, packets=open_packets)

Expand Down
10 changes: 8 additions & 2 deletions packet/templates/active_packets.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
<div class="col-xs-10">
<h4 class="page-title">Active Packets</h4>
</div>
{% if info.is_upper %}
<div class="col-xs-2">
<select id="sig-filter" class="form-control">
<option>Total</option>
<option>Upperclassmen</option>
<option>Freshmen</option>
</select>
</div>
{% endif %}
</div>
</div>
<div id="eval-blocks">
Expand All @@ -27,9 +29,11 @@ <h4 class="page-title">Active Packets</h4>
<thead>
<tr>
<th>Name</th>
{% if info.is_upper %}
<th>Signatures</th>
<th>Signatures</th>
<th>Signatures</th>
{% endif %}
{% if can_sign %}
<th>Sign</th>
{% endif %}
Expand All @@ -47,6 +51,7 @@ <h4 class="page-title">Active Packets</h4>
height="25"/> {{ get_rit_name(packet.freshman_username) }}
</a>
</td>
{% if info.is_upper %}
<td data-sort="{{ packet.signatures_received_result.member_total }}">
{% if packet.signatures_received_result.member_total == packet.signatures_required_result.member_total %}
💯 {# 100% emoji #}
Expand All @@ -71,15 +76,16 @@ <h4 class="page-title">Active Packets</h4>
{{ packet.signatures_required_result.total }}
{% endif %}
</td>
{% endif %}
{% if can_sign %}
<td class="sign-packet" align="right" data-priority="1">
{% if not packet.did_sign_result and info.uid != packet.freshman_username %}
{% if not packet.did_sign_result and info.ritdn != packet.freshman_username %}
<button class="btn btn-sm btn-primary sign-button"
data-packet_id="{{ packet.id }}"
data-freshman_name="{{ get_rit_name(packet.freshman_username) }}">
Sign
</button>
{% elif info.uid != packet.freshman_username %}
{% elif info.ritdn != packet.freshman_username %}
<button class="btn btn-sm btn-primary signed-button"
disabled="disabled"><i
class="fa fa-check"></i>&nbsp;Signed
Expand Down
14 changes: 12 additions & 2 deletions packet/templates/packet.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h3>{{ get_rit_name(packet.freshman_username) }}</h3>
class="fa fa-check"></i>&nbsp;Signed
</button>
{% endif %}
{% if info.realm == "csh" %}
{% if info.realm == "csh" and info.is_upper %}
<a class="btn btn-primary"
style="float: right; margin-right: 5px"
href="{{ url_for('packet_graphs', packet_id=packet.id) }}">
Expand All @@ -29,6 +29,7 @@ <h3>{{ get_rit_name(packet.freshman_username) }}</h3>
{% endif %}
</div>
</div>
{% if info.is_upper or packet.freshman_username == info.ritdn %}
<div class="row">
<div class="col ml-1 mb-1">
<h6>Signatures: <span class="badge badge-secondary">{{ received.total }}/{{ required.total }}</span>
Expand Down Expand Up @@ -103,18 +104,24 @@ <h5>Upperclassmen Score - {{ '%0.2f' % upper_score }}%</h5>
</div>
</div>
</div>
{% endif %}
{% if info.is_upper or packet.freshman_username == info.ritdn or can_sign %}
<div class="card mb-2">
<div class="card-header">
<b>On-Floor Freshmen Signatures</b>
{% if info.is_upper or packet.freshman_username == info.ritdn %}
<b class="signature-count">{{ received.fresh }}/{{ required.fresh }}</b>
{% else %}
<b>Signed</b>
{% endif %}
</div>
<div class="card-body table-fill">
<div class="table-responsive">
<table class="table table-striped no-bottom-margin" data-module="table"
data-searchable="true" data-sort-column="3" data-sort-order="asc"
data-length-changable="true" data-paginated="false">
<tbody>
{% for sig in packet.fresh_signatures %}
{% for sig in (packet.fresh_signatures if info.is_upper or packet.freshman_username == info.ritdn else fresh_sig) %}
<tr {% if sig.signed %}style="background-color: #4caf505e" {% endif %}>
<td>
<img class="eval-user-img" alt="{{ sig.freshman_username }}"
Expand All @@ -136,6 +143,8 @@ <h5>Upperclassmen Score - {{ '%0.2f' % upper_score }}%</h5>
</div>
</div>
</div>
{% endif %}
{% if info.is_upper or packet.freshman_username == info.ritdn %}
<div class="card mb-2">
<div class="card-header">
<b>Alumni & Advisor Signatures</b>
Expand Down Expand Up @@ -178,6 +187,7 @@ <h5>Upperclassmen Score - {{ '%0.2f' % upper_score }}%</h5>
</div>
</div>
</div>
{% endif %}
</div>
</div>
</div>
Expand Down
18 changes: 17 additions & 1 deletion packet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def wrapped_function(*args: list, **kwargs: dict) -> Any:
'realm': 'intro',
'uid': uid,
'onfloor': is_freshman_on_floor(uid),
'admin': False # It's always false if frosh
'admin': False, # It's always false if frosh
'ritdn': uid,
'is_upper': False, # Always fals in intro realm
}
else:
member = ldap.get_member(uid)
Expand All @@ -40,6 +42,8 @@ def wrapped_function(*args: list, **kwargs: dict) -> Any:
'uid': uid,
'admin': ldap.is_evals(member),
'groups': ldap.get_groups(member),
'ritdn': member.ritdn,
'is_upper': not is_frosh(),
}

kwargs['info'] = info
Expand Down Expand Up @@ -258,3 +262,15 @@ def sync_with_ldap() -> None:
db.session.add(sig)

db.session.commit()


@auth.oidc_auth('app')
def is_frosh() -> bool:
"""
Check if the current user is a freshman.
"""
if app.config['REALM'] == 'csh':
username = str(session['userinfo'].get('preferred_username', ''))
return ldap.is_intromember(ldap.get_member(username))
# Always true for the intro realm
return True