Exemplo n.º 1
0
def building_level_rooms_json(level, building_id=None, building_shortname=None):
    building = facilities.determine_building(id=building_id, shortname=building_shortname)

    if building is None:
        flash(u"Gebäude existiert nicht!", 'error')
        abort(404)

    all_users = bool(request.args.get('all_users', 0, type=int))
    # We need to alias User, otherwise sqlalchemy selects User.id as user_id,
    # which collides with the joined-loaded user.current_properties.user_id.
    user = aliased(User)
    rooms_users_q = (session.session.query(Room, user)
                     .options(joinedload(user.current_properties))
                     .filter(and_(Room.building == building, Room.level == level))
                     .join(user))
    if not all_users:
        rooms_users_q = (
            rooms_users_q.join(user.current_properties_maybe_denied)
            .filter(CurrentProperty.property_name == 'network_access')
        )
    level_inhabitants = defaultdict(lambda: [])
    for room, user in rooms_users_q.all():
        level_inhabitants[room].append(user)

    return jsonify(items=[{
            'room': {
                'href': url_for(".room_show", room_id=room.id),
                'title': "{:02d} - {}".format(level, room.number)
            },
            'inhabitants': [user_button(i) for i in inhabitants]
        } for room, inhabitants in level_inhabitants.items()])
Exemplo n.º 2
0
def building_show(building_id=None, building_shortname=None):
    building = facilities.determine_building(id=building_id, shortname=building_shortname)

    if building is None:
        flash(u"Gebäude existiert nicht!", 'error')
        abort(404)

    rooms_list = building.rooms
    return render_template('facilities/building_show.html',
        page_title=u"Wohnheim " + building.short_name, rooms=rooms_list)
Exemplo n.º 3
0
def building_levels(building_id=None, building_shortname=None):
    building = facilities.determine_building(id=building_id, shortname=building_shortname)

    if building is None:
        flash(u"Gebäude existiert nicht!", 'error')
        abort(404)

    rooms_list = building.rooms
    levels_list = [room.level for room in rooms_list]
    levels_list = list(set(levels_list))

    return render_template('facilities/levels.html',
        levels=levels_list, building=building,
        page_title=u"Etagen Wohnheim {}".format(building.short_name))
Exemplo n.º 4
0
def overcrowded(building_id):
    page_title = "Mehrfachbelegungen"
    if building_id:
        building = facilities.determine_building(id=building_id)
        if building is None:
            flash(u"Gebäude existiert nicht!", 'error')
            abort(404)
        page_title = "Mehrfachbelegungen {}".format(building.short_name)

    return render_template(
        "facilities/room_overcrowded.html",
        page_title=page_title,
        room_table=RoomOvercrowdedTable(
            data_url=url_for('.overcrowded_json', building_id=building_id)),
    )
Exemplo n.º 5
0
def building_level_rooms_json(level,
                              building_id=None,
                              building_shortname=None):
    building = facilities.determine_building(id=building_id,
                                             shortname=building_shortname)

    if building is None:
        flash("Gebäude existiert nicht!", 'error')
        abort(404)

    all_users = bool(request.args.get('all_users', 0, type=int))
    # We need to alias User, otherwise sqlalchemy selects User.id as user_id,
    # which collides with the joined-loaded user.current_properties.user_id.
    user = aliased(User)

    user_join_condition = user.room_id == Room.id
    if not all_users:
        user_join_condition = and_(
            user_join_condition,
            exists(
                select(CurrentProperty).where(
                    and_(CurrentProperty.user_id == user.id,
                         CurrentProperty.property_name == 'network_access'))))

    rooms_users_q = (session.session.query(Room, user).options(
        joinedload(user.current_properties)).filter(
            and_(Room.building == building,
                 Room.level == level)).outerjoin(user, user_join_condition))

    level_inhabitants = defaultdict(lambda: [])
    for room, user in rooms_users_q.all():
        if user is not None:
            level_inhabitants[room].append(user)
        else:
            # Ensure room is in level_inhabitants
            level_inhabitants[room]

    T = BuildingLevelRoomTable
    return jsonify(items=[{
        'room':
        T.room.value(href=url_for(".room_show", room_id=room.id),
                     title=f"{level:02d} - {room.number}"),
        'inhabitants': [user_button(i) for i in inhabitants]
    } for room, inhabitants in level_inhabitants.items()])
Exemplo n.º 6
0
def building_levels(building_id=None, building_shortname=None):
    building = facilities.determine_building(id=building_id,
                                             shortname=building_shortname)

    if building is None:
        flash("Gebäude existiert nicht!", 'error')
        abort(404)

    rooms_list = building.rooms
    levels_list = [room.level for room in rooms_list]
    levels_list = list(set(levels_list))

    return render_template(
        'facilities/levels.html',
        levels=levels_list,
        building=building,
        page_title=f"Etagen Wohnheim {building.short_name}",
        suggested_address=suggest_room_address_data(building),
    )
Exemplo n.º 7
0
def building_level_rooms(level, building_id=None, building_shortname=None):
    building = facilities.determine_building(building_shortname, building_id)

    if building is None:
        flash(u"Gebäude existiert nicht!", 'error')
        abort(404)

    level_l0 = "{:02d}".format(level)

    #TODO depending on, whether a user is living in the room, the room is
    # a link to the user. If there is more then one user, the room is
    # duplicated
    return render_template(
        'facilities/rooms.html',
        level=level_l0,
        building=building,
        page_title=u"Zimmer der Etage {:d} des Wohnheims {}".format(
            level, building.short_name
        )
    )
Exemplo n.º 8
0
def building_level_rooms(level, building_id=None, building_shortname=None):
    building = facilities.determine_building(building_shortname, building_id)

    if building is None:
        flash(u"Gebäude existiert nicht!", 'error')
        abort(404)

    level_l0 = "{:02d}".format(level)

    room_table = BuildingLevelRoomTable(
        data_url=url_for('.building_level_rooms_json',
                         building_shortname=building.short_name,
                         level=level))
    return render_template(
        'facilities/rooms.html',
        level=level_l0,
        building=building,
        page_title=u"Zimmer der Etage {:d} des Wohnheims {}".format(
            level, building.short_name),
        room_table=room_table,
    )