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 Committee Meetings to Intro Evals Page Pt. 2 #348

Open
wants to merge 3 commits 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
96 changes: 48 additions & 48 deletions conditional/blueprints/attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from flask import Blueprint, jsonify, redirect, request

from conditional import db, start_of_year, auth
from conditional.models.models import CommitteeMeeting
from conditional.models.models import DirectorshipMeeting
from conditional.models.models import CurrentCoops
from conditional.models.models import FreshmanAccount
from conditional.models.models import FreshmanCommitteeAttendance
from conditional.models.models import FreshmanDirectorshipAttendance
from conditional.models.models import FreshmanHouseMeetingAttendance
from conditional.models.models import FreshmanSeminarAttendance
from conditional.models.models import HouseMeeting
from conditional.models.models import MemberCommitteeAttendance
from conditional.models.models import MemberDirectorshipAttendance
from conditional.models.models import MemberHouseMeetingAttendance
from conditional.models.models import MemberSeminarAttendance
from conditional.models.models import TechnicalSeminar
Expand Down Expand Up @@ -106,7 +106,7 @@ def get_non_alumni_non_coop(internal=False, user_dict=None):
@get_user
def get_non_alumni(user_dict=None):
log = logger.new(request=request, auth_dict=user_dict)
log.info('Retrieve Committee Meeting Attendance List')
log.info('Retrieve Directorship Meeting Attendance List')

current_students = ldap_get_current_students()

Expand Down Expand Up @@ -134,7 +134,7 @@ def get_non_alumni(user_dict=None):
@get_user
def display_attendance_cm(user_dict=None):
log = logger.new(request=request, auth_dict=user_dict)
log.info('Display Committee Meeting Attendance Page')
log.info('Display Directorship Meeting Attendance Page')

return render_template('attendance_cm.html',
username=user_dict['username'],
Expand Down Expand Up @@ -172,33 +172,33 @@ def display_attendance_hm(user_dict=None):
@attendance_bp.route('/attendance/submit/cm', methods=['POST'])
@auth.oidc_auth
@get_user
def submit_committee_attendance(user_dict=None):
def submit_directorship_attendance(user_dict=None):
log = logger.new(request=request, auth_dict=user_dict)

approved = ldap_is_eboard(user_dict['account'])
post_data = request.get_json()

committee = post_data['committee']
directorship = post_data['directorship']
m_attendees = post_data['members']
f_attendees = post_data['freshmen']
timestamp = post_data['timestamp']

log.info('Submit {} Meeting Attendance'.format(committee))
log.info('Submit {} Meeting Attendance'.format(directorship))

timestamp = datetime.strptime(timestamp, "%Y-%m-%d")
meeting = CommitteeMeeting(committee, timestamp, approved)
meeting = DirectorshipMeeting(directorship, timestamp, approved)

db.session.add(meeting)
db.session.flush()
db.session.refresh(meeting)

for m in m_attendees:
log.info('Gave Attendance to {} for {}'.format(m, committee))
db.session.add(MemberCommitteeAttendance(m, meeting.id))
log.info('Gave Attendance to {} for {}'.format(m, directorship))
db.session.add(MemberDirectorshipAttendance(m, meeting.id))

for f in f_attendees:
log.info('Gave Attendance to freshman-{} for {}'.format(f, committee))
db.session.add(FreshmanCommitteeAttendance(f, meeting.id))
log.info('Gave Attendance to freshman-{} for {}'.format(f, directorship))
db.session.add(FreshmanDirectorshipAttendance(f, meeting.id))

db.session.commit()
return jsonify({"success": True}), 200
Expand Down Expand Up @@ -363,12 +363,12 @@ def attendance_history(user_dict=None):

def get_meeting_attendees(meeting_id):
attendees = [ldap_get_member(a.uid).displayName for a in
MemberCommitteeAttendance.query.filter(
MemberCommitteeAttendance.meeting_id == meeting_id).all()]
MemberDirectorshipAttendance.query.filter(
MemberDirectorshipAttendance.meeting_id == meeting_id).all()]

for freshman in [a.fid for a in
FreshmanCommitteeAttendance.query.filter(
FreshmanCommitteeAttendance.meeting_id == meeting_id).all()]:
FreshmanDirectorshipAttendance.query.filter(
FreshmanDirectorshipAttendance.meeting_id == meeting_id).all()]:
attendees.append(FreshmanAccount.query.filter(
FreshmanAccount.id == freshman).first().name)
return attendees
Expand Down Expand Up @@ -396,14 +396,14 @@ def get_seminar_attendees(meeting_id):
offset = 0 if int(page) == 1 else ((int(page)-1)*10)
limit = int(page)*10
all_cm = [{"id": m.id,
"name": m.committee,
"name": m.directorship,
"dt_obj": m.timestamp,
"date": m.timestamp.strftime("%a %m/%d/%Y"),
"attendees": get_meeting_attendees(m.id),
"type": "cm"
Comment on lines 398 to 403
Copy link
Contributor

Choose a reason for hiding this comment

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

any plan to update all_cm or "type": "cm"?

} for m in CommitteeMeeting.query.filter(
CommitteeMeeting.timestamp > start_of_year(),
CommitteeMeeting.approved).all()]
} for m in DirectorshipMeeting.query.filter(
DirectorshipMeeting.timestamp > start_of_year(),
DirectorshipMeeting.approved).all()]
all_ts = [{"id": m.id,
"name": m.name,
"dt_obj": m.timestamp,
Expand All @@ -414,13 +414,13 @@ def get_seminar_attendees(meeting_id):
TechnicalSeminar.timestamp > start_of_year(),
TechnicalSeminar.approved).all()]
pend_cm = [{"id": m.id,
Copy link
Contributor

Choose a reason for hiding this comment

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

this too?

"name": m.committee,
"name": m.directorship,
"dt_obj": m.timestamp,
"date": m.timestamp.strftime("%a %m/%d/%Y"),
"attendees": get_meeting_attendees(m.id)
} for m in CommitteeMeeting.query.filter(
CommitteeMeeting.timestamp > start_of_year(),
CommitteeMeeting.approved == False).all()] # pylint: disable=singleton-comparison
} for m in DirectorshipMeeting.query.filter(
DirectorshipMeeting.timestamp > start_of_year(),
DirectorshipMeeting.approved == False).all()] # pylint: disable=singleton-comparison
pend_ts = [{"id": m.id,
"name": m.name,
"dt_obj": m.timestamp,
Expand All @@ -446,9 +446,9 @@ def get_seminar_attendees(meeting_id):
@attendance_bp.route('/attendance/alter/cm/<cid>', methods=['POST'])
@auth.oidc_auth
@get_user
def alter_committee_attendance(cid, user_dict=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

cid as in committee [meeting] id?

def alter_directorship_attendance(cid, user_dict=None):
log = logger.new(request=request, auth_dict=user_dict)
log.info('Edit Committee Meeting Attendance')
log.info('Edit Directorship Meeting Attendance')

if not ldap_is_eboard(user_dict['account']):
return jsonify({"success": False, "error": "Not EBoard"}), 403
Expand All @@ -458,17 +458,17 @@ def alter_committee_attendance(cid, user_dict=None):
m_attendees = post_data['members']
f_attendees = post_data['freshmen']

FreshmanCommitteeAttendance.query.filter(
FreshmanCommitteeAttendance.meeting_id == meeting_id).delete()
FreshmanDirectorshipAttendance.query.filter(
FreshmanDirectorshipAttendance.meeting_id == meeting_id).delete()

MemberCommitteeAttendance.query.filter(
MemberCommitteeAttendance.meeting_id == meeting_id).delete()
MemberDirectorshipAttendance.query.filter(
MemberDirectorshipAttendance.meeting_id == meeting_id).delete()

for m in m_attendees:
db.session.add(MemberCommitteeAttendance(m, meeting_id))
db.session.add(MemberDirectorshipAttendance(m, meeting_id))

for f in f_attendees:
db.session.add(FreshmanCommitteeAttendance(f, meeting_id))
db.session.add(FreshmanDirectorshipAttendance(f, meeting_id))

db.session.flush()
db.session.commit()
Expand Down Expand Up @@ -510,7 +510,7 @@ def alter_seminar_attendance(sid, user_dict=None):
@attendance_bp.route('/attendance/ts/<sid>', methods=['GET', 'DELETE'])
@auth.oidc_auth
@get_user
def get_cm_attendees(sid, user_dict=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

this is technical seminar attendance?

def get_directorship_meetings_attendees(sid, user_dict=None):
if request.method == 'GET':
attendees = [{"value": a.uid,
"display": ldap_get_member(a.uid).displayName
Expand Down Expand Up @@ -552,28 +552,28 @@ def get_ts_attendees(cid, user_dict=None):
attendees = [{"value": a.uid,
Copy link
Contributor

Choose a reason for hiding this comment

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

and this is cm attendance, (and you didn't change the route name), they're reversed

"display": ldap_get_member(a.uid).displayName
} for a in
MemberCommitteeAttendance.query.filter(
MemberCommitteeAttendance.meeting_id == cid).all()]
MemberDirectorshipAttendance.query.filter(
MemberDirectorshipAttendance.meeting_id == cid).all()]

for freshman in [{"value": a.fid,
"display": FreshmanAccount.query.filter(FreshmanAccount.id == a.fid).first().name
} for a in FreshmanCommitteeAttendance.query.filter(
FreshmanCommitteeAttendance.meeting_id == cid).all()]:
} for a in FreshmanDirectorshipAttendance.query.filter(
FreshmanDirectorshipAttendance.meeting_id == cid).all()]:
attendees.append(freshman)
return jsonify({"attendees": attendees}), 200

log = logger.new(request=request, auth_dict=user_dict)
log.info('Delete Committee Meeting {}'.format(cid))
log.info('Delete Directorship Meeting {}'.format(cid))

if not ldap_is_eboard(user_dict['account']):
return jsonify({"success": False, "error": "Not EBoard"}), 403

FreshmanCommitteeAttendance.query.filter(
FreshmanCommitteeAttendance.meeting_id == cid).delete()
MemberCommitteeAttendance.query.filter(
MemberCommitteeAttendance.meeting_id == cid).delete()
CommitteeMeeting.query.filter(
CommitteeMeeting.id == cid).delete()
FreshmanDirectorshipAttendance.query.filter(
FreshmanDirectorshipAttendance.meeting_id == cid).delete()
MemberDirectorshipAttendance.query.filter(
MemberDirectorshipAttendance.meeting_id == cid).delete()
DirectorshipMeeting.query.filter(
DirectorshipMeeting.id == cid).delete()

db.session.flush()
db.session.commit()
Expand All @@ -586,13 +586,13 @@ def get_ts_attendees(cid, user_dict=None):
@get_user
def approve_cm(cid, user_dict=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

this too

log = logger.new(request=request, auth_dict=user_dict)
log.info('Approve Committee Meeting {} Attendance'.format(cid))
log.info('Approve Directorship Meeting {} Attendance'.format(cid))

if not ldap_is_eboard(user_dict['account']):
return jsonify({"success": False, "error": "Not EBoard"}), 403

CommitteeMeeting.query.filter(
CommitteeMeeting.id == cid).first().approved = True
DirectorshipMeeting.query.filter(
DirectorshipMeeting.id == cid).first().approved = True
db.session.flush()
db.session.commit()

Expand Down
2 changes: 1 addition & 1 deletion conditional/blueprints/cache_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ def clear_members_cache():
ldap_get_onfloor_members.cache_clear()


def clear_committee_cache():
def clear_directorship_cache():
_ldap_is_member_of_directorship.clear_cache()
6 changes: 3 additions & 3 deletions conditional/blueprints/co_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from conditional import db, start_of_year, auth
from conditional.models.models import CurrentCoops
from conditional.util.member import req_cm
from conditional.util.member import get_required_directorship_meetings
from conditional.util.auth import get_user
from conditional.util.flask import render_template
from conditional.util.ldap import ldap_is_eval_director, ldap_is_current_student
Expand Down Expand Up @@ -59,7 +59,7 @@ def submit_co_op_form(user_dict=None):
db.session.add(co_op)
db.session.flush()
db.session.commit()
req_cm.cache_clear()
get_required_directorship_meetings.cache_clear()

return jsonify({"success": True}), 200

Expand All @@ -85,7 +85,7 @@ def delete_co_op(uid, user_dict=None):

db.session.flush()
db.session.commit()
req_cm.cache_clear()
get_required_directorship_meetings.cache_clear()

return jsonify({"success": True}), 200

Expand Down
11 changes: 6 additions & 5 deletions conditional/blueprints/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from conditional.util.ldap import ldap_is_active
from conditional.util.ldap import ldap_is_intromember
from conditional.util.ldap import ldap_is_onfloor
from conditional.util.member import get_freshman_data, get_voting_members, get_cm, get_hm, req_cm
from conditional.util.member import get_freshman_data, get_voting_members, get_directorship_meetings, \
get_house_meetings, get_required_directorship_meetings

logger = structlog.get_logger()

Expand Down Expand Up @@ -47,10 +48,10 @@ def display_dashboard(user_dict=None):
data['freshman'] = None

spring = {}
c_meetings = get_cm(user_dict['account'])
spring['committee_meetings'] = len(c_meetings)
spring['req_meetings'] = req_cm(user_dict['account'])
h_meetings = [(m.meeting_id, m.attendance_status) for m in get_hm(user_dict['account'])]
c_meetings = get_directorship_meetings(user_dict['account'])
Copy link
Contributor

Choose a reason for hiding this comment

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

c_meetings?

spring['directorship_meetings'] = len(c_meetings)
spring['req_meetings'] = get_required_directorship_meetings(user_dict['account'])
h_meetings = [(m.meeting_id, m.attendance_status) for m in get_house_meetings(user_dict['account'])]
spring['hm_missed'] = len([h for h in h_meetings if h[1] == "Absent"])
eval_entry = SpringEval.query.filter(SpringEval.uid == user_dict['account'].uid,
SpringEval.date_created > start_of_year(),
Expand Down
52 changes: 38 additions & 14 deletions conditional/blueprints/intro_evals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from flask import Blueprint, request

from conditional import start_of_year, auth
from conditional.models.models import CommitteeMeeting
from conditional.models.models import DirectorshipMeeting
from conditional.models.models import FreshmanAccount
from conditional.models.models import FreshmanCommitteeAttendance
from conditional.models.models import FreshmanDirectorshipAttendance
from conditional.models.models import FreshmanEvalData
from conditional.models.models import FreshmanHouseMeetingAttendance
from conditional.models.models import FreshmanSeminarAttendance
Expand All @@ -17,7 +17,7 @@
from conditional.util.auth import get_user
from conditional.util.flask import render_template
from conditional.util.ldap import ldap_get_intro_members
from conditional.util.member import get_cm, get_hm
from conditional.util.member import get_directorship_meetings, get_house_meetings

intro_evals_bp = Blueprint('intro_evals_bp', __name__)

Expand All @@ -31,11 +31,27 @@ def display_intro_evals(internal=False, user_dict=None):
log = logger.new(request=request, auth_dict=user_dict)
log.info('Display Intro Evals Listing')

# get user data
jabbate19 marked this conversation as resolved.
Show resolved Hide resolved
def get_fid_cm_count(member_id):
return len([a for a in FreshmanCommitteeAttendance.query.filter(
FreshmanCommitteeAttendance.fid == member_id)
if CommitteeMeeting.query.filter(CommitteeMeeting.id == a.meeting_id).first().approved])
def get_frosh_directorship_meetings(fid):
"""
Get all directorship meetings from a given frosh account id
"""
c_meetings = [{
Copy link
Contributor

Choose a reason for hiding this comment

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

c_meetings?

"uid": cm[0],
jabbate19 marked this conversation as resolved.
Show resolved Hide resolved
"timestamp": cm[1],
"directorship": cm[2]
} for cm in DirectorshipMeeting.query.join(
FreshmanDirectorshipAttendance,
FreshmanDirectorshipAttendance.meeting_id == DirectorshipMeeting.id
).with_entities(
FreshmanDirectorshipAttendance.fid,
DirectorshipMeeting.timestamp,
DirectorshipMeeting.directorship
).filter(
DirectorshipMeeting.timestamp > start_of_year(),
FreshmanDirectorshipAttendance.fid == fid,
DirectorshipMeeting.approved == True # pylint: disable=singleton-comparison
).all()]
return c_meetings

members = ldap_get_intro_members()

Expand Down Expand Up @@ -64,8 +80,12 @@ def get_fid_cm_count(member_id):
'uid': fid.id,
'eval_date': fid.eval_date.strftime("%Y-%m-%d"),
'signatures_missed': signatures_missed,
'committee_meetings': get_fid_cm_count(fid.id),
'committee_meetings_passed': get_fid_cm_count(fid.id) >= 6,
'directorship_meetings': [{
"uid": cm['uid'],
"timestamp": cm['timestamp'].strftime("%Y-%m-%d"),
"directorship": cm['directorship']
} for cm in get_frosh_directorship_meetings(fid.id)],
'directorship_meetings_passed': len(get_frosh_directorship_meetings(fid.id)) >= 6,
'house_meetings_missed':
[
{
Expand Down Expand Up @@ -107,14 +127,18 @@ def get_fid_cm_count(member_id):
if freshman_data.freshman_eval_result != "Pending" and internal:
continue

h_meetings = [m.meeting_id for m in get_hm(member, only_absent=True)]
h_meetings = [m.meeting_id for m in get_house_meetings(member, only_absent=True)]
member_info = {
'name': name,
'uid': uid,
'eval_date': freshman_data.eval_date.strftime("%Y-%m-%d"),
'signatures_missed': freshman_data.signatures_missed,
'committee_meetings': len(get_cm(member)),
'committee_meetings_passed': len(get_cm(member)) >= 6,
'directorship_meetings': [{
"uid": cm['uid'],
"timestamp": cm['timestamp'].strftime("%Y-%m-%d"),
"directorship": cm['directorship']
} for cm in get_directorship_meetings(member)],
'directorship_meetings_passed': len(get_directorship_meetings(member)) >= 6,
'house_meetings_missed':
[
{
Expand Down Expand Up @@ -147,7 +171,7 @@ def get_fid_cm_count(member_id):
ie_members.append(member_info)

ie_members.sort(key=lambda x: len(x['house_meetings_missed']))
ie_members.sort(key=lambda x: x['committee_meetings'], reverse=True)
ie_members.sort(key=lambda x: x['directorship_meetings_passed'], reverse=True)
ie_members.sort(key=lambda x: x['signatures_missed'])
ie_members.sort(key=lambda x: x['status'] == "Passed")

Expand Down
Loading