예제 #1
0
def change_room_numbers(rmnumber):
    log = logger.new(request=request)

    username = request.headers.get('x-webauth-user')
    account = ldap_get_member(username)
    update = request.get_json()

    if not ldap_is_eval_director(account):
        return "must be eval director", 403

    # Get the current list of people living on-floor.
    current_students = ldap_get_current_students()

    # Set the new room number for each person in the list.

    for occupant in update["occupants"]:
        if occupant != "":
            account = ldap_get_member(occupant)
            account.roomNumber = rmnumber
            log.info('{} assigned to room {}'.format(occupant, rmnumber))
            ldap_set_active(account)
            log.info('{} marked as active because of room assignment'.format(
                occupant))
    # 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('{} removed from room {}'.format(old_occupant.uid,
                                                      old_occupant.roomNumber))
            old_occupant.roomNumber = None

    return jsonify({"success": True}), 200
예제 #2
0
def get_occupants(rmnumber):

    # Get the current list of people living on-floor.
    current_students = ldap_get_current_students()

    # Find the current occupants of the specified room.
    occupants = [account.uid for account in current_students
                 if ldap_get_roomnumber(account) == str(rmnumber)]
    return jsonify({"room": rmnumber, "occupants": occupants}), 200
예제 #3
0
def display_housing():
    log = logger.new(request=request)
    log.info('Display Housing Board')

    # get user data
    user_name = request.headers.get('x-webauth-user')
    account = ldap_get_member(user_name)

    housing = {}
    onfloors = [account for account in ldap_get_onfloor_members()]
    onfloor_freshmen = FreshmanAccount.query.filter(
        FreshmanAccount.room_number is not None)

    room_list = set()

    for member in onfloors:
        room = ldap_get_roomnumber(member)
        if room in housing and room is not None:
            housing[room].append(member.cn)
            room_list.add(room)
        elif room is not None:
            housing[room] = [member.cn]
            room_list.add(room)

    for f in onfloor_freshmen:
        name = f.name
        room = f.room_number
        if room in housing and room is not None:
            housing[room].append(name)
            room_list.add(room)
        elif room is not 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_housing_queue(
                               ldap_is_eval_director(account)),
                           housing=housing,
                           room_list=sorted(list(room_list)))
예제 #4
0
def get_members_info():
    members = [account for account in ldap_get_current_students()]
    member_list = []

    for account in members:
        uid = account.uid
        name = account.cn
        active = ldap_is_active(account)
        onfloor = ldap_is_onfloor(account)
        room = ldap_get_roomnumber(account)
        hp = account.housingPoints
        member_list.append({
            "uid": uid,
            "name": name,
            "active": active,
            "onfloor": onfloor,
            "room": room,
            "hp": hp
        })

    return member_list
예제 #5
0
def display_housing(user_dict=None):
    log = logger.new(request=request, auth_dict=user_dict)
    log.info('Display Housing Board')

    housing = {}
    onfloors = ldap_get_onfloor_members()
    onfloor_freshmen = FreshmanAccount.query.filter(
        FreshmanAccount.room_number is not None)

    room_list = set()

    for member in onfloors:
        room = ldap_get_roomnumber(member)
        if room in housing and room is not None:
            housing[room].append(member.cn)
            room_list.add(room)
        elif room is not None:
            housing[room] = [member.cn]
            room_list.add(room)

    for f in onfloor_freshmen:
        name = f.name
        room = f.room_number
        if room in housing and room is not None:
            housing[room].append(name)
            room_list.add(room)
        elif room is not None:
            housing[room] = [name]
            room_list.add(room)

    # return names in 'first last (username)' format
    return render_template('housing.html',
                           username=user_dict['username'],
                           queue=get_housing_queue(
                               ldap_is_eval_director(user_dict['account'])),
                           housing=housing,
                           room_list=sorted(list(room_list)))