Пример #1
0
def submit_co_op_form(user_dict=None):
    log = logger.new(request=request, auth_dict=user_dict)

    valid_semesters = ['Fall', 'Spring']
    post_data = request.get_json()
    semester = post_data['semester']
    if post_data['semester'] not in valid_semesters:
        return "Invalid semester submitted", 400
    if not ldap_is_current_student(user_dict['account']):
        return "Must be current student", 403

    log.info('Submit {} Co-Op'.format(semester))

    if CurrentCoops.query.filter(
            CurrentCoops.uid == user_dict['username'],
            CurrentCoops.date_created > start_of_year()).first():
        return "User has already submitted this form!", 403

    # Add to corresponding co-op ldap group
    ldap_add_member_to_group(user_dict['account'], semester.lower() + '_coop')

    co_op = CurrentCoops(uid=user_dict['username'], semester=semester)
    db.session.add(co_op)
    db.session.flush()
    db.session.commit()
    req_cm.cache_clear()

    return jsonify({"success": True}), 200
Пример #2
0
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
Пример #3
0
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
Пример #4
0
def member_management_make_user_active(user_dict=None):
    log = logger.new(request=request, auth_dict=user_dict)

    if not ldap_is_current_student(user_dict['account']) or ldap_is_active(user_dict['account']):
        return "must be current student and not active", 403

    ldap_set_active(user_dict['account'])
    log.info("Make user {} active".format(user_dict['username']))

    clear_members_cache()
    return jsonify({"success": True}), 200
Пример #5
0
    def wrapped_function(*args, **kwargs):
        username = str(session["userinfo"].get("preferred_username", ""))
        account = ldap_get_member(username)
        current_student = ldap_is_current_student(account)

        user_dict = {
            'username': username,
            'account': account,
            'student': current_student
        }

        kwargs["user_dict"] = user_dict
        return func(*args, **kwargs)
Пример #6
0
def member_management_make_user_active():
    log = logger.new(request=request)

    uid = request.headers.get('x-webauth-user')
    account = ldap_get_member(uid)

    if not ldap_is_current_student(account) or ldap_is_active(account):
        return "must be current student and not active", 403

    ldap_set_active(account)
    log.info("Make user {} active".format(uid))

    clear_members_cache()
    return jsonify({"success": True}), 200
Пример #7
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
Пример #8
0
def display_dashboard(user_dict=None):
    log = logger.new(request=request, auth_dict=user_dict)
    log.info('display dashboard')

    # Get the list of voting members.
    can_vote = get_voting_members()

    data = dict()
    data['username'] = user_dict['account'].uid
    data['name'] = user_dict['account'].cn
    data['active'] = ldap_is_active(user_dict['account'])
    data['onfloor'] = ldap_is_onfloor(user_dict['account'])
    data['voting'] = bool(user_dict['account'].uid in can_vote)
    data['student'] = ldap_is_current_student(user_dict['account'])

    data['voting_count'] = {
        "Voting Members": len(can_vote),
        "Active Members": len(ldap_get_active_members())
    }
    # freshman shit
    if ldap_is_intromember(user_dict['account']):
        data['freshman'] = get_freshman_data(user_dict['account'].uid)
    else:
        data['freshman'] = False

    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'])]
    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(),
        SpringEval.active == True).first()  # pylint: disable=singleton-comparison
    if eval_entry is not None:
        spring['status'] = eval_entry.status
    else:
        spring['status'] = None

    data['spring'] = spring

    # only show housing if member has onfloor status
    if ldap_is_onfloor(user_dict['account']):
        housing = dict()
        housing['points'] = user_dict['account'].housingPoints
        housing['room'] = user_dict['account'].roomNumber
        housing['queue_pos'] = get_queue_position(user_dict['account'].uid)
    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_dict['account'].uid,
        MajorProject.date > start_of_year())]

    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_dict['account'].uid,
        Conditional.date_due > start_of_year())]
    data['conditionals'] = conditionals
    data['conditionals_len'] = len(conditionals)

    hm_attendance = [{
        'reason': m.excuse,
        'datetime': m.date
    } for m in MemberHouseMeetingAttendance.query.outerjoin(
        HouseMeeting, MemberHouseMeetingAttendance.meeting_id ==
        HouseMeeting.id).with_entities(
            MemberHouseMeetingAttendance.excuse, HouseMeeting.date).filter(
                MemberHouseMeetingAttendance.uid == user_dict['account'].uid,
                MemberHouseMeetingAttendance.attendance_status == "Absent",
                HouseMeeting.date > start_of_year())]

    data['cm_attendance'] = c_meetings
    data['cm_attendance_len'] = len(c_meetings)
    data['hm_attendance'] = hm_attendance
    data['hm_attendance_len'] = len(hm_attendance)

    return render_template('dashboard.html', **data)