Skip to content

Commit

Permalink
Merge pull request #376 from ComputerScienceHouse/develop
Browse files Browse the repository at this point in the history
constitution
  • Loading branch information
Sam-Cordry authored Jan 26, 2025
2 parents 5e67335 + 1456759 commit 7c56051
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 31 deletions.
2 changes: 1 addition & 1 deletion packet/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def remove_sig(packet_id: int, username: str, is_member: bool) -> None:
db.session.commit()
print('Successfully unsigned packet')
else:
print('Failed to unsign packet; {} is not an onfloor'.format(username))
print('Failed to unsign packet; could not find signature')


@app.cli.command('remove-member-sig')
Expand Down
7 changes: 0 additions & 7 deletions packet/routes/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ def freshman_packet(packet_id, info=None):
if packet is None:
return 'Invalid packet or freshman', 404
else:
can_sign = packet.is_open()

# If the packet is open and the user is an off-floor freshman set can_sign to False
if packet.is_open() and app.config['REALM'] != 'csh':
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(
Expand All @@ -43,7 +37,6 @@ def freshman_packet(packet_id, info=None):
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(),
Expand Down
11 changes: 5 additions & 6 deletions packet/templates/active_packets.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ <h4 class="page-title">Active Packets</h4>
</div>
<div id="eval-blocks">
{% if packets|length > 0 %}
{% set can_sign = info.onfloor or info.realm == "csh" %}
<div id="eval-table">
<div class="card">
<div class="card-body table-fill">
Expand All @@ -34,22 +33,24 @@ <h4 class="page-title">Active Packets</h4>
<th>Signatures</th>
<th>Signatures</th>
{% endif %}
{% if can_sign %}
<th>Sign</th>
{% endif %}
<th>Sign</th>
</tr>
</thead>
<tbody>
{% for packet in packets %}
<tr {% if packet.did_sign_result %}style="background-color: #4caf505e" {% endif %}>
<td data-priority="1">
{% if info.is_upper %}
<a href="{{ url_for('freshman_packet', packet_id=packet.id) }}">
{% endif %}
<img class="eval-user-img"
alt="{{ get_rit_name(packet.freshman_username) }}"
src="{{ get_rit_image(packet.freshman_username) }}"
width="25"
height="25"/> {{ get_rit_name(packet.freshman_username) }}
{% if info.is_upper %}
</a>
{% endif %}
</td>
{% if info.is_upper %}
<td data-sort="{{ packet.signatures_received_result.member_total }}">
Expand Down Expand Up @@ -77,7 +78,6 @@ <h4 class="page-title">Active Packets</h4>
{% endif %}
</td>
{% endif %}
{% if can_sign %}
<td class="sign-packet" align="right" data-priority="1">
{% if not packet.did_sign_result and info.ritdn != packet.freshman_username %}
<button class="btn btn-sm btn-primary sign-button"
Expand All @@ -92,7 +92,6 @@ <h4 class="page-title">Active Packets</h4>
</button>
{% endif %}
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
Expand Down
6 changes: 3 additions & 3 deletions packet/templates/packet.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<h3>{{ get_rit_name(packet.freshman_username) }}</h3>
</div>
<div class="col">
{% if can_sign and not did_sign %}
{% if not did_sign and info.ritdn != packet.freshman_username %}
<button class="btn btn-primary sign-button"
data-packet_id="{{ packet.id }}"
data-freshman_name="{{ get_rit_name(packet.freshman_username) }}">Sign
Expand Down Expand Up @@ -105,10 +105,10 @@ <h5>Upperclassmen Score - {{ '%0.2f' % upper_score }}%</h5>
</div>
</div>
{% endif %}
{% if info.is_upper or packet.freshman_username == info.ritdn or can_sign %}
{% if info.is_upper or packet.freshman_username == info.ritdn %}
<div class="card mb-2">
<div class="card-header">
<b>On-Floor Freshmen Signatures</b>
<b>Freshmen Signatures</b>
{% if info.is_upper or packet.freshman_username == info.ritdn %}
<b class="signature-count">{{ received.fresh }}/{{ required.fresh }}</b>
{% else %}
Expand Down
20 changes: 6 additions & 14 deletions packet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,9 @@ def sync_freshman(freshmen_list: dict) -> None:

# Update the freshmen signatures of each open or future packet
for packet in Packet.query.filter(Packet.end > datetime.now()).all():
# Handle the freshmen that are no longer onfloor
for fresh_sig in filter(lambda fresh_sig: not fresh_sig.freshman.onfloor, packet.fresh_signatures):
FreshSignature.query.filter_by(packet_id=fresh_sig.packet_id,
freshman_username=fresh_sig.freshman_username).delete()

# Add any new onfloor freshmen
# pylint: disable=cell-var-from-loop
current_fresh_sigs = set(map(lambda fresh_sig: fresh_sig.freshman_username, packet.fresh_signatures))
for list_freshman in filter(lambda list_freshman: list_freshman.rit_username not in current_fresh_sigs and
list_freshman.onfloor and
list_freshman.rit_username != packet.freshman_username,
freshmen_list.values()):
db.session.add(FreshSignature(packet=packet, freshman=freshmen_in_db[list_freshman.rit_username]))
Expand All @@ -173,7 +166,7 @@ def create_new_packets(base_date: date, freshmen_list: dict) -> None:
start = datetime.combine(base_date, packet_start_time)
end = datetime.combine(base_date, packet_end_time) + timedelta(days=14)

print('Fetching data from LDAP...')
app.logger.info('Fetching data from LDAP...')
all_upper = list(filter(
lambda member: not ldap.is_intromember(member) and not ldap.is_on_coop(member), ldap.get_active_members()))

Expand All @@ -189,7 +182,7 @@ def create_new_packets(base_date: date, freshmen_list: dict) -> None:
packets_starting_notification(start)

# Create the new packets and the signatures for each freshman in the given CSV
print('Creating DB entries and sending emails...')
app.logger.info('Creating DB entries and sending emails...')
for freshman in Freshman.query.filter(cast(Any, Freshman.rit_username).in_(freshmen_list)).all():
packet = Packet(freshman=freshman, start=start, end=end)
db.session.add(packet)
Expand All @@ -207,15 +200,14 @@ def create_new_packets(base_date: date, freshmen_list: dict) -> None:
sig.drink_admin = member.uid in drink
db.session.add(sig)

for onfloor_freshman in Freshman.query.filter_by(onfloor=True).filter(Freshman.rit_username !=
freshman.rit_username).all():
db.session.add(FreshSignature(packet=packet, freshman=onfloor_freshman))
for frosh in Freshman.query.filter(Freshman.rit_username != freshman.rit_username).all():
db.session.add(FreshSignature(packet=packet, freshman=frosh))

db.session.commit()


def sync_with_ldap() -> None:
print('Fetching data from LDAP...')
app.logger.info('Fetching data from LDAP...')
all_upper = {member.uid: member for member in filter(
lambda member: not ldap.is_intromember(member) and not ldap.is_on_coop(member), ldap.get_active_members())}

Expand All @@ -226,7 +218,7 @@ def sync_with_ldap() -> None:
w_m = ldap.get_wiki_maintainers()
drink = ldap.get_drink_admins()

print('Applying updates to the DB...')
app.logger.info('Applying updates to the DB...')
for packet in Packet.query.filter(Packet.end > datetime.now()).all():
# Update the role state of all UpperSignatures
for sig in filter(lambda sig: sig.member in all_upper, packet.upper_signatures):
Expand Down

0 comments on commit 7c56051

Please sign in to comment.