diff --git a/conditional/blueprints/attendance.py b/conditional/blueprints/attendance.py index 6ebb4d6c..41f65972 100644 --- a/conditional/blueprints/attendance.py +++ b/conditional/blueprints/attendance.py @@ -40,7 +40,7 @@ def get_all_members(user_dict=None): named_members = [ { - 'display': f.name, + 'label': f.name, 'value': f.id, 'freshman': True } for f in FreshmanAccount.query.filter( @@ -49,7 +49,7 @@ def get_all_members(user_dict=None): for account in members: named_members.append( { - 'display': account['displayName'], + 'label': account['displayName'], 'value': account['uid'], 'freshman': False }) @@ -79,7 +79,7 @@ def get_non_alumni_non_coop(internal=False, user_dict=None): eligible_members = [ { - 'display': f.name, + 'label': f.name, 'value': f.id, 'freshman': True } for f in FreshmanAccount.query.filter( @@ -92,7 +92,7 @@ def get_non_alumni_non_coop(internal=False, user_dict=None): eligible_members.append( { - 'display': account['displayName'], + 'label': account['displayName'], 'value': account['uid'], 'freshman': False }) @@ -115,7 +115,7 @@ def get_non_alumni(user_dict=None): eligible_members = [ { - 'display': f.name, + 'label': f.name, 'value': f.id, 'freshman': True } for f in FreshmanAccount.query.filter( @@ -124,7 +124,7 @@ def get_non_alumni(user_dict=None): for account in current_students: eligible_members.append( { - 'display': account['displayName'], + 'label': account['displayName'], 'value': account['uid'], 'freshman': False }) @@ -166,10 +166,14 @@ def display_attendance_hm(user_dict=None): if not user_dict_is_eval_director(user_dict): return redirect("/dashboard") + members = get_non_alumni_non_coop(internal=True) + + print(members) + return render_template('attendance_hm.html', username=user_dict['username'], date=datetime.now().strftime("%Y-%m-%d"), - members=get_non_alumni_non_coop(internal=True)) + members=members) @attendance_bp.route('/attendance/submit/cm', methods=['POST']) @@ -371,41 +375,60 @@ def alter_house_excuse(uid, hid, user_dict=None): @auth.oidc_auth("default") @get_user def attendance_history(user_dict=None): + member_names = { member['uid']: member['displayName'] + for member in ldap.get_group_member_attributes(groups=['current_student'], + attributes=['uid', 'displayName']) } + + def get_member_name(uid): + if uid in member_names: + return member_names[uid] + + name = ldap_get_member(uid).displayName + member_names[uid] = name + return name def get_meeting_attendees(meeting_id): - attendees = [ldap_get_member(a.uid).displayName for a in + attendees = [get_member_name(a.uid) for a in MemberCommitteeAttendance.query.filter( MemberCommitteeAttendance.meeting_id == meeting_id).all()] - for freshman in [a.fid for a in + freshmen_attendees = [a.fid for a in FreshmanCommitteeAttendance.query.filter( - FreshmanCommitteeAttendance.meeting_id == meeting_id).all()]: + FreshmanCommitteeAttendance.meeting_id == meeting_id).all()] + + for freshman in freshmen_attendees: attendees.append(FreshmanAccount.query.filter( FreshmanAccount.id == freshman).first().name) + return attendees def get_seminar_attendees(meeting_id): - attendees = [ldap_get_member(a.uid).displayName for a in + attendees = [get_member_name(a.uid) for a in MemberSeminarAttendance.query.filter( MemberSeminarAttendance.seminar_id == meeting_id).all()] - - for freshman in [a.fid for a in + freshmen_attendees = [a.fid for a in FreshmanSeminarAttendance.query.filter( - FreshmanSeminarAttendance.seminar_id == meeting_id).all()]: + FreshmanSeminarAttendance.seminar_id == meeting_id).all()] + + for freshman in freshmen_attendees: attendees.append(FreshmanAccount.query.filter( FreshmanAccount.id == freshman).first().name) + return attendees def get_seminar_hosts(meeting_id): - hosts = [ldap_get_member(a.uid).displayName for a in + hosts = [get_member_name(a.uid) for a in MemberSeminarHost.query.filter( MemberSeminarHost.seminar_id == meeting_id).all()] - for freshman in [a.fid for a in + freshmen_hosts = [a.fid for a in FreshmanSeminarHost.query.filter( - FreshmanSeminarHost.seminar_id == meeting_id).all()]: + FreshmanSeminarHost.seminar_id == meeting_id).all()] + + for freshman in freshmen_hosts: hosts.append(FreshmanAccount.query.filter( FreshmanAccount.id == freshman).first().name) + return hosts log = logger.new(request=request, auth_dict=user_dict) @@ -413,11 +436,12 @@ def get_seminar_hosts(meeting_id): if not user_dict_is_eboard(user_dict): return jsonify({"success": False, "error": "Not EBoard"}), 403 - page = request.args.get('page', 1) + page_size = int(request.args.get('size', 10)) + log.info('View Past Attendance Submitions') - offset = 0 if int(page) == 1 else ((int(page)-1)*10) - limit = int(page)*10 + offset = 0 if int(page) == 1 else ((int(page) - 1) * 10) + limit = int(page) * page_size all_cm = [{"id": m.id, "name": m.committee, "dt_obj": m.timestamp, @@ -427,6 +451,7 @@ def get_seminar_hosts(meeting_id): } for m in CommitteeMeeting.query.filter( CommitteeMeeting.timestamp > start_of_year(), CommitteeMeeting.approved).all()] + all_ts = [{"id": m.id, "name": m.name, "dt_obj": m.timestamp, @@ -437,6 +462,7 @@ def get_seminar_hosts(meeting_id): } for m in TechnicalSeminar.query.filter( TechnicalSeminar.timestamp > start_of_year(), TechnicalSeminar.approved).all()] + pend_cm = [{"id": m.id, "name": m.committee, "dt_obj": m.timestamp, @@ -445,6 +471,7 @@ def get_seminar_hosts(meeting_id): } for m in CommitteeMeeting.query.filter( CommitteeMeeting.timestamp > start_of_year(), CommitteeMeeting.approved == False).all()] # pylint: disable=singleton-comparison + pend_ts = [{"id": m.id, "name": m.name, "dt_obj": m.timestamp, @@ -454,20 +481,47 @@ def get_seminar_hosts(meeting_id): } for m in TechnicalSeminar.query.filter( TechnicalSeminar.timestamp > start_of_year(), TechnicalSeminar.approved == False).all()] # pylint: disable=singleton-comparison + all_meetings = sorted((all_cm + all_ts), key=lambda k: k['dt_obj'], reverse=True)[offset:limit] - if len(all_cm) % 10 != 0: - total_pages = int(len(all_cm) / 10) + 1 + if len(all_cm) % page_size != 0: + total_pages = int(len(all_cm) / page_size) + 1 else: - total_pages = int(len(all_cm) / 10) + total_pages = int(len(all_cm) / page_size) + + page_size_options = [ + { + 'value': 10, + 'label': '10' + }, + { + 'value': 25, + 'label': '25' + }, + { + 'value': 50, + 'label': '50' + }, + { + 'value': 100, + 'label': '100' + }, + { + 'value': -1, + 'label': 'all' + } + ] + + selected_page_size = list(filter(lambda opt: opt['value'] == page_size, page_size_options))[0] + return render_template('attendance_history.html', username=user_dict['username'], history=all_meetings, pending_cm=pend_cm, pending_ts=pend_ts, - all_ts=all_ts, num_pages=total_pages, - current_page=int(page)) - + page_size=selected_page_size, + current_page=int(page), + page_sizes=page_size_options) @attendance_bp.route('/attendance/alter/cm/', methods=['POST']) @auth.oidc_auth("default") diff --git a/conditional/blueprints/co_op.py b/conditional/blueprints/co_op.py index 84207422..2c8a7b77 100644 --- a/conditional/blueprints/co_op.py +++ b/conditional/blueprints/co_op.py @@ -58,7 +58,6 @@ def submit_co_op_form(user_dict=None): db.session.add(co_op) db.session.flush() db.session.commit() - req_cm.cache_clear() return jsonify({"success": True}), 200 @@ -84,7 +83,6 @@ def delete_co_op(uid, user_dict=None): db.session.flush() db.session.commit() - req_cm.cache_clear() return jsonify({"success": True}), 200 @@ -99,7 +97,7 @@ def display_co_op_management(user_dict=None): if not user_dict_is_eval_director(user_dict): return "must be eval director", 403 - co_op_list = [(member.semester, member.uid) + co_op_list = [{ 'semester': member.semester, 'uid': member.uid} for member in CurrentCoops.query.filter( CurrentCoops.date_created > start_of_year(), CurrentCoops.semester != "Neither")] diff --git a/conditional/blueprints/dashboard.py b/conditional/blueprints/dashboard.py index 67b2db7b..b2791290 100644 --- a/conditional/blueprints/dashboard.py +++ b/conditional/blueprints/dashboard.py @@ -53,9 +53,9 @@ def display_dashboard(user_dict=None): "Active Members": len(ldap_get_active_member_uids())} # freshman shit if user_dict_is_intromember(user_dict): - data['freshman'] = get_freshman_data(uid) + data['intro'] = get_freshman_data(uid) else: - data['freshman'] = None + data['intro'] = None spring = {} c_meetings = get_cm(user_dict['account']) @@ -162,8 +162,9 @@ def display_dashboard(user_dict=None): data['cm_attendance'] = c_meetings data['cm_attendance_len'] = len(c_meetings) - data['hm_attendance'] = hm_attendance - data['hm_attendance_len'] = len(hm_attendance) + + data['missed_hm'] = hm_attendance + data['missed_hm_len'] = len(hm_attendance) gatekeep_info = gatekeep_values(uid) gatekeep_result = 'disenfranchised' diff --git a/conditional/blueprints/gatekeep.py b/conditional/blueprints/gatekeep.py index 4b799588..0bb2caba 100644 --- a/conditional/blueprints/gatekeep.py +++ b/conditional/blueprints/gatekeep.py @@ -118,10 +118,16 @@ def display_spring_evals(internal=False, user_dict=None): if passing: status = 'passed' + status_int = 0 + + if passing: + status_int = 1 + member = { 'name': name, 'uid': uid, 'status': status, + 'status_int': status_int, 'committee_meetings': cm_attended_count, 'technical_seminars': ts_attended_count, 'technical_seminars_hosted': ts_hosted_count, @@ -136,6 +142,7 @@ def display_spring_evals(internal=False, user_dict=None): gk_members.sort(key=lambda x: x['committee_meetings'], reverse=True) gk_members.sort(key=lambda x: x['technical_seminars'], reverse=True) gk_members.sort(key=lambda x: len(x['house_meetings_missed'])) + gk_members.sort(key=lambda x: x['status_int'], reverse=True) # return names in 'first last (username)' format if internal: return gk_members diff --git a/conditional/blueprints/housing.py b/conditional/blueprints/housing.py index 0cbc9cdd..6642162a 100644 --- a/conditional/blueprints/housing.py +++ b/conditional/blueprints/housing.py @@ -1,6 +1,8 @@ import structlog from flask import Blueprint, request, jsonify +import ldap as python_ldap + from conditional import db, auth, ldap from conditional.models.models import FreshmanAccount from conditional.models.models import InHousingQueue @@ -102,11 +104,23 @@ def change_room_numbers(rmnumber, user_dict=None): if not user_dict_is_eval_director(user_dict): return "must be eval director", 403 - # Get the current list of people living on-floor. - current_students = ldap_get_current_students() + # Get the current list of people living in the room + # I'm sorry for the raw ldap + current_occupants_result = ldap.__con__.search_s( + "dc=csh,dc=rit,dc=edu", + python_ldap.SCOPE_SUBTREE, + f'roomNumber={rmnumber}', + ['uid'] + ) - # Set the new room number for each person in the list. + current_occupants = [member[1]['uid'][0].decode('utf-8') for member in current_occupants_result] + + # Remove all old occupants + for occupant in current_occupants: + if occupant not in update["occupants"]: + ldap_get_member(occupant).roomNumber = None + # Set the new room number for each person in the list. for occupant in update["occupants"]: if occupant != "": account = ldap_get_member(occupant) @@ -114,12 +128,6 @@ def change_room_numbers(rmnumber, user_dict=None): log.info(f'{occupant} assigned to room {rmnumber}') ldap_set_active(account) log.info(f'{occupant} marked as active because of room assignment') - # Delete any old occupants that are no longer in room. - for old_occupant in [account for account in current_students - if ldap_get_roomnumber(account) == str(rmnumber) - and account.uid not in update["occupants"]]: - log.info(f'{old_occupant.uid} removed from room {old_occupant.roomNumber}') - old_occupant.roomNumber = None return jsonify({"success": True}), 200 @@ -129,11 +137,11 @@ def change_room_numbers(rmnumber, user_dict=None): def get_occupants(rmnumber): # Get the current list of people living on-floor. - current_students = ldap_get_current_students() + current_students = ldap.get_group_member_attributes(groups=['current_student'], attributes=['uid', 'roomNumber', 'cn']) # Find the current occupants of the specified room. - occupants = [account.uid for account in current_students - if ldap_get_roomnumber(account) == str(rmnumber)] + occupants = [account['uid'] for account in current_students + if 'roomNumber' in account and account['roomNumber'] == str(rmnumber)] return jsonify({"room": rmnumber, "occupants": occupants}), 200 diff --git a/conditional/blueprints/intro_evals.py b/conditional/blueprints/intro_evals.py index a41b23e6..dcbd009b 100644 --- a/conditional/blueprints/intro_evals.py +++ b/conditional/blueprints/intro_evals.py @@ -145,8 +145,6 @@ def get_intro_members_without_accounts(): } ie_members.append(freshman) - print(ie_members) - return ie_members @intro_evals_bp.route('/intro_evals/') diff --git a/conditional/blueprints/member_management.py b/conditional/blueprints/member_management.py index 7af8d02b..3d1809e3 100644 --- a/conditional/blueprints/member_management.py +++ b/conditional/blueprints/member_management.py @@ -66,10 +66,10 @@ def display_member_management(user_dict=None): onfloor_members = set(ldap_get_onfloor_member_uids()) member_list = ldap.get_group_member_attributes(groups=["current_student"], - excluded_groups=[], attributes=['uid', 'housingPoints', 'roomNumber', 'cn']) + excluded_groups=[], attributes=['uid', 'housingPoints', 'roomNumber', 'displayName']) for member in member_list: - member['name'] = member['cn'] + member['name'] = member['displayName'] member['active'] = member['uid'] in active_members member['onfloor'] = member['uid'] in onfloor_members @@ -89,6 +89,8 @@ def display_member_management(user_dict=None): "eval_date": freshman_user.eval_date }) + print(freshmen_list) + settings = EvalSettings.query.first() if settings: lockdown = settings.site_lockdown @@ -397,7 +399,7 @@ def get_hm_date(hm_id): hms_missed.append(hm) return jsonify( { - 'name': account.cn, + 'name': account.displayName, 'room_number': account.roomNumber, 'onfloor_status': ldap_is_onfloor(account), 'housing_points': account.housingPoints, @@ -408,7 +410,7 @@ def get_hm_date(hm_id): return jsonify( { - 'name': account.cn, + 'name': account.displayName, 'active_member': ldap_is_active(account), 'user': 'financial' }), 200 diff --git a/conditional/templates/attendance_cm.html b/conditional/templates/attendance_cm.html index 80c26ea1..96475d3e 100644 --- a/conditional/templates/attendance_cm.html +++ b/conditional/templates/attendance_cm.html @@ -1,61 +1,38 @@ -{% extends "nav.html" %} +{% extends "base.html" %} {% block title %} Directorship Meeting Attendance {% endblock %} {% block body %} -
-

Meeting Attendance

+
+

Directorship Meeting Attendance

-
-
-
-
-
- - -
-
-
-
+
+ +
-
-
-
-
-
- - -
-
-
-
+
+ +
-
-
-
-
-
- - -
-
-
-
+
+ +
+
diff --git a/conditional/templates/attendance_history.html b/conditional/templates/attendance_history.html index 0b534f1f..997a4eec 100644 --- a/conditional/templates/attendance_history.html +++ b/conditional/templates/attendance_history.html @@ -1,4 +1,4 @@ -{% extends "nav_protected.html" %} +{% extends "base_protected.html" %} {% block title %} Attendance History {% endblock %} @@ -6,177 +6,228 @@
{% if pending_cm|length != 0 and current_page == 1 %}

Pending Submissions

- {% for meeting in pending_cm %} -
-
-
-
-
{{meeting["name"]}}
-

{{meeting["date"]}}

-

-

- {% for name in meeting["attendees"] %} - {{name}}{% if not loop.last %}, {% endif %} - {% endfor %} -

-
- -
+
+ {% for meeting in pending_cm %} +
+
+
+
+ {{ meeting["name"] }} +
+

+ {{ meeting["date"] }} +

+
+
+

+ {% for name in meeting["attendees"] %} + {{ name }}{% if not loop.last %}, {% endif %} + {% endfor %} +

+
+
+ +
+ {% endfor %}
- {% endfor %} {% endif %} - {% if pending_ts|length != 0 and current_page == 1 %} + {% if pending_ts | length != 0 and current_page == 1 %}

Pending Seminars

- {% for seminar in pending_ts %} -
-
-
-
-
{{seminar["name"]}}
-

{{seminar["date"]}}

-

-

Host: +

+ {% for seminar in pending_ts %} +
+
+
+
+ {{ seminar["name"] }} +
+

+ {{ seminar["date"] }} +

+
+
+

+ Host: {% for name in seminar["hosts"] %} - {{name}}{% if not loop.last %}, {% endif %} + {{ name }}{% if not loop.last %}, {% endif %} + {% endfor %} +

+

+ Attendees: + {% for name in seminar["attendees"] %} + {{ name }}{% if not loop.last %}, {% endif %} {% endfor %}

-

Attendees: - {% for name in seminar["attendees"] %} - {{name}}{% if not loop.last %}, {% endif %} - {% endfor %} -

-
- -
+
+
+ +
+ {% endfor %}
- {% endfor %} {% endif %}

Attendance History

- {% for meeting in history %} -
-
-
-
-
{{meeting["name"]}}
-

{{meeting["date"]}}

-

- {% if meeting in all_ts %} -

Host: +

+ {% for meeting in history %} +
+
+
+
+ {{ meeting["name"] }} +
+

+ {{ meeting["date"] }} +

+
+
+ {% if meeting["type"] == "ts" %} +

+ Host: {% for name in meeting["hosts"] %} - {{name}}{% if not loop.last %}, {% endif %} + {{ name }}{% if not loop.last %}, {% endif %} {% endfor %}

{% endif %} -

Attendees: - {% for name in meeting["attendees"] %} - {{name}}{% if not loop.last %}, {% endif %} - {% endfor %} -

-
- -
+

+ Attendees: + {% for name in meeting["attendees"] %} + {{ name }}{% if not loop.last %}, {% endif %} + {% endfor %} +

+
+
+ +
+ {% endfor %}
- {% endfor %} - {% if num_pages > 1 or current_page > 1%} -