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
Beispiel #2
0
def __get_ofm__():

    # check that everyone in onfloor has onfloorstatus
    onfloors = [
        uids['uid'][0].decode('utf-8') for uids in ldap_get_onfloor_members()
    ]

    ofm = [{
        'uid': m.uid,
        'time': m.onfloor_granted,
        'points': ldap_get_housing_points(m.uid)
    } for m in OnFloorStatusAssigned.query.all(
    ) if ldap_is_active(m.uid) or CurrentCoops.query.filter(
        CurrentCoops.uid == m.uid and CurrentCoops.active).first() is not None]

    # Add everyone who has a discrepancy in LDAP and OnFloorStatusAssigned
    for member in onfloors:
        if OnFloorStatusAssigned.query.filter(
                OnFloorStatusAssigned.uid == member).first() is None:
            ofsa = OnFloorStatusAssigned(member, datetime.min)
            active = ldap_is_active(ofsa.uid)
            coop = CurrentCoops.query.filter(
                CurrentCoops.uid == ofsa.uid).first()
            coop = coop != None and coop.active

            if active or coop:
                ofm.append({
                    'uid': ofsa.uid,
                    'time': ofsa.onfloor_granted,
                    'points': ldap_get_housing_points(ofsa.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)

    return ofm
Beispiel #3
0
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 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
Beispiel #5
0
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)