def get_members_info(): members = [m['uid'] for m in ldap_get_current_students()] member_list = [] number_onfloor = 0 for member_uid in members: uid = member_uid[0].decode('utf-8') name = ldap_get_name(uid) active = ldap_is_active(uid) onfloor = ldap_is_onfloor(uid) room_number = ldap_get_room_number(uid) room = room_number if room_number != "N/A" else "" hp = ldap_get_housing_points(uid) member_list.append({ "uid": uid, "name": name, "active": active, "onfloor": onfloor, "room": room, "hp": hp }) if onfloor: number_onfloor += 1 return member_list, number_onfloor
def get_housing_queue(): ofm = __get_ofm__() queue = [ m['uid'] for m in ofm if ldap_get_room_number(m['uid']) == "N/A" and ldap_is_current_student(m['uid']) ] return queue
def get_queue_with_points(): ofm = __get_ofm__() queue = [{ 'name': ldap_get_name(m['uid']), 'points': m['points'] } for m in ofm if ldap_get_room_number(m['uid']) == "N/A" and ldap_is_current_student(m['uid'])] return queue
def get_housing_queue(): ofm = [ { 'uid': m.uid, 'time': m.onfloor_granted, 'points': ldap_get_housing_points(m.uid) } for m in models.OnFloorStatusAssigned.query.all() if ldap_is_active(m.uid)] # sort by housing points then by time in queue ofm.sort(key=lambda m: m['time']) ofm.sort(key=lambda m: m['points'], reverse=True) queue = [m['uid'] for m in ofm if ldap_get_room_number(m['uid']) == "N/A" and ldap_is_current_student(m['uid'])] return queue
def display_housing(): log = logger.new(user_name=request.headers.get("x-webauth-user"), request_id=str(uuid.uuid4())) log.info('frontend', action='display housing') # get user data user_name = request.headers.get('x-webauth-user') housing = {} onfloors = [ uids['uid'][0].decode('utf-8') for uids in ldap_get_onfloor_members() ] onfloor_freshmen = FreshmanAccount.query.filter( FreshmanAccount.room_number is not None) room_list = set() for m in onfloors: room = ldap_get_room_number(m) if room in housing: housing[room].append(ldap_get_name(m)) else: housing[room] = [ldap_get_name(m)] room_list.add(room) for f in onfloor_freshmen: name = f.name room = str(f.room_number) if room in housing and room != "None": housing[room].append(name) room_list.add(room) elif room != "None": housing[room] = [name] room_list.add(room) # return names in 'first last (username)' format return render_template(request, 'housing.html', username=user_name, queue=get_queue_with_points(), housing=housing, room_list=sorted(list(room_list)))
def member_management_getuserinfo(uid): log = logger.new(user_name=request.headers.get("x-webauth-user"), request_id=str(uuid.uuid4())) log.info('api', action='retrieve user info') user_name = request.headers.get('x-webauth-user') if not ldap_is_eval_director(user_name) and not ldap_is_financial_director( user_name): return "must be eval or financial director", 403 acct = None if uid.isnumeric(): acct = FreshmanAccount.query.filter(FreshmanAccount.id == uid).first() # missed hm def get_hm_date(hm_id): return HouseMeeting.query.filter( HouseMeeting.id == hm_id). \ first().date.strftime("%Y-%m-%d") # if fid if acct: missed_hm = [{ 'date': get_hm_date(hma.meeting_id), 'id': hma.meeting_id, 'excuse': hma.excuse, 'status': hma.attendance_status } for hma in FreshmanHouseMeetingAttendance.query.filter( FreshmanHouseMeetingAttendance.fid == acct.id and ( FreshmanHouseMeetingAttendance.attendance_status != attendance_enum.Attended))] hms_missed = [] for hm in missed_hm: if hm['status'] != "Attended": hms_missed.append(hm) return jsonify({ 'id': acct.id, 'name': acct.name, 'eval_date': acct.eval_date.strftime("%Y-%m-%d"), 'missed_hm': hms_missed, 'onfloor_status': acct.onfloor_status, 'room_number': acct.room_number, 'sig_missed': acct.signatures_missed }), 200 if ldap_is_eval_director(user_name): missed_hm = [{ 'date': get_hm_date(hma.meeting_id), 'id': hma.meeting_id, 'excuse': hma.excuse, 'status': hma.attendance_status } for hma in MemberHouseMeetingAttendance.query.filter( MemberHouseMeetingAttendance.uid == uid and ( MemberHouseMeetingAttendance.attendance_status != attendance_enum.Attended))] hms_missed = [] for hm in missed_hm: if hm['status'] != "Attended": hms_missed.append(hm) return jsonify({ 'name': ldap_get_name(uid), 'room_number': ldap_get_room_number(uid), 'onfloor_status': ldap_is_onfloor(uid), 'housing_points': ldap_get_housing_points(uid), 'active_member': ldap_is_active(uid), 'missed_hm': hms_missed, 'user': '******' }), 200 else: return jsonify({ 'name': ldap_get_name(uid), 'active_member': ldap_is_active(uid), 'user': '******' }), 200
def display_dashboard(): log = logger.new(user_name=request.headers.get("x-webauth-user"), request_id=str(uuid.uuid4())) log.info('frontend', action='display dashboard') # get user data user_name = request.headers.get('x-webauth-user') can_vote = get_voting_members() data = dict() data['username'] = user_name data['name'] = ldap_get_name(user_name) # Member Status data['active'] = ldap_is_active(user_name) # On-Floor Status data['onfloor'] = ldap_is_onfloor(user_name) # Voting Status data['voting'] = bool(user_name in can_vote) # freshman shit if ldap_is_intromember(user_name): data['freshman'] = get_freshman_data(user_name) else: data['freshman'] = False spring = {} c_meetings = [ m.meeting_id for m in MemberCommitteeAttendance.query.filter( MemberCommitteeAttendance.uid == user_name) ] spring['committee_meetings'] = len(c_meetings) h_meetings = [(m.meeting_id, m.attendance_status) for m in MemberHouseMeetingAttendance.query.filter( MemberHouseMeetingAttendance.uid == user_name)] spring['hm_missed'] = len([h for h in h_meetings if h[1] == "Absent"]) data['spring'] = spring # only show housing if member has onfloor status if ldap_is_onfloor(user_name): housing = dict() housing['points'] = ldap_get_housing_points(user_name) housing['room'] = ldap_get_room_number(user_name) if housing['room'] == "N/A": housing['queue_pos'] = "%s / %s" % (get_queue_position(user_name), get_queue_length()) else: housing['queue_pos'] = "N/A" else: housing = None data['housing'] = housing data['major_projects'] = [{ 'id': p.id, 'name': p.name, 'status': p.status, 'description': p.description } for p in MajorProject.query.filter(MajorProject.uid == user_name)] data['major_projects_count'] = len(data['major_projects']) spring['mp_status'] = "Failed" for mp in data['major_projects']: if mp['status'] == "Pending": spring['mp_status'] = 'Pending' continue if mp['status'] == "Passed": spring['mp_status'] = 'Passed' break conditionals = [{ 'date_created': c.date_created, 'date_due': c.date_due, 'description': c.description, 'status': c.status } for c in Conditional.query.filter(Conditional.uid == user_name)] data['conditionals'] = conditionals data['conditionals_len'] = len(conditionals) cm_attendance = [{ 'type': m.committee, 'datetime': m.timestamp.date() } for m in CommitteeMeeting.query.filter( CommitteeMeeting.id.in_(c_meetings))] hm_attendance = [{ 'reason': m.excuse, 'datetime': HouseMeeting.query.filter(HouseMeeting.id == m.meeting_id).first().date } for m in MemberHouseMeetingAttendance.query.filter( MemberHouseMeetingAttendance.uid == user_name).filter( MemberHouseMeetingAttendance.attendance_status == "Absent")] data['cm_attendance'] = cm_attendance data['cm_attendance_len'] = len(cm_attendance) data['hm_attendance'] = hm_attendance data['hm_attendance_len'] = len(hm_attendance) return render_template(request, 'dashboard.html', **data)