예제 #1
0
def get_voting_members():

    if datetime.today() < datetime(start_of_year().year, 12, 31):
        semester = 'Fall'
    else:
        semester = 'Spring'

    active_members = set(member.uid for member in ldap_get_active_members())
    intro_members = set(member.uid for member in ldap_get_intro_members())
    on_coop = set(member.uid for member in CurrentCoops.query.filter(
        CurrentCoops.date_created > start_of_year(),
        CurrentCoops.semester == semester).all())

    voting_list = list(active_members - intro_members - on_coop)

    passed_fall = FreshmanEvalData.query.filter(
        FreshmanEvalData.freshman_eval_result == "Passed",
        FreshmanEvalData.eval_date > start_of_year()
    ).distinct()

    for intro_member in passed_fall:
        if intro_member.uid not in voting_list:
            voting_list.append(intro_member.uid)

    return voting_list
예제 #2
0
def get_voting_members():
    voting_list = []
    active_members = [x['uid'][0].decode('utf-8') for x
                      in ldap_get_active_members()]
    intro_members = [x['uid'][0].decode('utf-8') for x
                     in ldap_get_intro_members()]
    passed_fall = FreshmanEvalData.query.filter(
        FreshmanEvalData.freshman_eval_result == "Passed"
    ).distinct()

    for intro_member in passed_fall:
        voting_list.append(intro_member.uid)

    for active_member in active_members:
        if active_member not in intro_members:
            voting_list.append(active_member)

    return voting_list
예제 #3
0
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
    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
        ])

    members = [account for account in ldap_get_intro_members()]

    ie_members = []

    # freshmen who don't have accounts
    fids = [
        f for f in FreshmanAccount.query.filter(
            FreshmanAccount.eval_date > start_of_year(),
            FreshmanAccount.eval_date > datetime.now())
    ]

    for fid in fids:
        h_meetings = [
            m.meeting_id for m in FreshmanHouseMeetingAttendance.query.
            filter(FreshmanHouseMeetingAttendance.fid == fid.id).filter(
                FreshmanHouseMeetingAttendance.attendance_status == "Absent")
        ]

        if fid.signatures_missed is None:
            signatures_missed = -1
        else:
            signatures_missed = fid.signatures_missed

        freshman = {
            'name':
            fid.name,
            '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) >= 10,
            'house_meetings_missed': [{
                "date":
                m.date.strftime("%Y-%m-%d"),
                "reason":
                FreshmanHouseMeetingAttendance.query.filter(
                    FreshmanHouseMeetingAttendance.fid == fid.id).filter(
                        FreshmanHouseMeetingAttendance.meeting_id ==
                        m.id).first().excuse
            } for m in HouseMeeting.query.filter(
                HouseMeeting.id.in_(h_meetings))],
            'technical_seminars': [
                s.name for s in TechnicalSeminar.query.filter(
                    TechnicalSeminar.id.in_([
                        a.seminar_id
                        for a in FreshmanSeminarAttendance.query.filter(
                            FreshmanSeminarAttendance.fid == fid.id)
                        if TechnicalSeminar.query.filter(
                            TechnicalSeminar.id ==
                            a.seminar_id).first().approved
                    ]))
            ],
            'social_events':
            '',
            'comments':
            "",
            'ldap_account':
            False,
            'status':
            "Pending"
        }
        ie_members.append(freshman)

    # freshmen who have accounts
    for member in members:
        uid = member.uid
        name = member.cn
        freshman_data = FreshmanEvalData.query.filter(
            FreshmanEvalData.eval_date > start_of_year(),
            FreshmanEvalData.uid == uid).first()

        if freshman_data is None:
            continue
        elif freshman_data.freshman_eval_result != "Pending" and internal:
            continue

        h_meetings = [m.meeting_id for m in get_hm(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)) >= 10,
            'house_meetings_missed': [{
                "date":
                m.date.strftime("%Y-%m-%d"),
                "reason":
                MemberHouseMeetingAttendance.query.filter(
                    MemberHouseMeetingAttendance.uid == uid,
                    MemberHouseMeetingAttendance.meeting_id ==
                    m.id).first().excuse
            } for m in HouseMeeting.query.filter(
                HouseMeeting.id.in_(h_meetings))],
            'technical_seminars': [
                seminar.name for seminar in TechnicalSeminar.query.join(
                    MemberSeminarAttendance, MemberSeminarAttendance.seminar_id
                    == TechnicalSeminar.id).with_entities(
                        TechnicalSeminar.name).filter(
                            TechnicalSeminar.timestamp > start_of_year(),
                            MemberSeminarAttendance.uid == member.uid,
                            TechnicalSeminar.approved == True  # pylint: disable=singleton-comparison
                        ).all()
            ],
            'social_events':
            freshman_data.social_events,
            'comments':
            freshman_data.other_notes,
            'ldap_account':
            True,
            'status':
            freshman_data.freshman_eval_result
        }
        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['signatures_missed'])
    ie_members.sort(key=lambda x: x['status'] == "Passed")

    if internal:
        return ie_members

    # return names in 'first last (username)' format
    return render_template('intro_evals.html',
                           username=user_dict['username'],
                           members=ie_members)
예제 #4
0
def display_intro_evals(internal=False):
    log = logger.new(user_name=request.headers.get("x-webauth-user"),
                     request_id=str(uuid.uuid4()))
    log.info('frontend', action='display intro evals listing')

    # get user data
    def get_uid_cm_count(member_id):
        return len([a for a in MemberCommitteeAttendance.query.filter(
            MemberCommitteeAttendance.uid == member_id)])

    def get_fid_cm_count(member_id):
        return len([a for a in FreshmanCommitteeAttendance.query.filter(
            FreshmanCommitteeAttendance.fid == member_id)])

    user_name = None
    if not internal:
        user_name = request.headers.get('x-webauth-user')

    members = [m['uid'] for m in ldap_get_intro_members()]

    ie_members = []

    # freshmen who don't have accounts
    fids = [f for f in FreshmanAccount.query.filter(
        FreshmanAccount.eval_date > datetime.now())]

    for fid in fids:
        h_meetings = [m.meeting_id for m in
                      FreshmanHouseMeetingAttendance.query.filter(
                          FreshmanHouseMeetingAttendance.fid == fid.id
                      ).filter(
                          FreshmanHouseMeetingAttendance.attendance_status == "Absent"
                      )]

        if fid.signatures_missed is None:
            signatures_missed = -1
        else:
            signatures_missed = fid.signatures_missed

        freshman = {
            'name': fid.name,
            '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) >= 10,
            'house_meetings_missed':
                [
                    {
                        "date": m.date.strftime("%Y-%m-%d"),
                        "reason":
                            FreshmanHouseMeetingAttendance.query.filter(
                                FreshmanHouseMeetingAttendance.fid == fid.id).filter(
                                FreshmanHouseMeetingAttendance.meeting_id == m.id).first().excuse
                    }
                    for m in HouseMeeting.query.filter(
                        HouseMeeting.id.in_(h_meetings)
                    )
                ],
            'technical_seminars':
                [s.name for s in TechnicalSeminar.query.filter(
                    TechnicalSeminar.id.in_(
                        [a.seminar_id for a in FreshmanSeminarAttendance.query.filter(
                            FreshmanSeminarAttendance.fid == fid.id)]
                    ))
                 ],
            'social_events': '',
            'freshman_project': "Pending",
            'comments': "",
            'ldap_account': False,
            'status': "Pending"
        }
        ie_members.append(freshman)

    # freshmen who have accounts
    for member_uid in members:
        uid = member_uid[0].decode('utf-8')
        freshman_data = FreshmanEvalData.query.filter(
            FreshmanEvalData.uid == uid).first()

        if freshman_data is None:
            continue

        # Add continue for if freshman_data.status != Pending
        h_meetings = [m.meeting_id for m in
                      MemberHouseMeetingAttendance.query.filter(
                          MemberHouseMeetingAttendance.uid == uid
                      ).filter(
                          MemberHouseMeetingAttendance.attendance_status == "Absent"
                      )]
        member = {
            'name': ldap_get_name(uid),
            'uid': uid,
            'eval_date': freshman_data.eval_date.strftime("%Y-%m-%d"),
            'signatures_missed': freshman_data.signatures_missed,
            'committee_meetings': get_uid_cm_count(uid),
            'committee_meetings_passed': get_uid_cm_count(uid) >= 10,
            'house_meetings_missed':
                [
                    {
                        "date": m.date.strftime("%Y-%m-%d"),
                        "reason":
                            MemberHouseMeetingAttendance.query.filter(
                                MemberHouseMeetingAttendance.uid == uid).filter(
                                MemberHouseMeetingAttendance.meeting_id == m.id).first().excuse
                    }
                    for m in HouseMeeting.query.filter(
                        HouseMeeting.id.in_(h_meetings)
                    )
                ],
            'technical_seminars':
                [s.name for s in TechnicalSeminar.query.filter(
                    TechnicalSeminar.id.in_(
                        [a.seminar_id for a in MemberSeminarAttendance.query.filter(
                            MemberSeminarAttendance.uid == uid)]
                    ))
                 ],
            'social_events': freshman_data.social_events,
            'freshman_project': freshman_data.freshman_project,
            'comments': freshman_data.other_notes,
            'ldap_account': True,
            'status': freshman_data.freshman_eval_result
        }
        ie_members.append(member)

    ie_members.sort(key=lambda x: x['freshman_project'] == "Passed")
    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['signatures_missed'])

    if internal:
        return ie_members
    else:
        # return names in 'first last (username)' format
        return render_template(request,
                               'intro_evals.html',
                               username=user_name,
                               members=ie_members)