コード例 #1
0
ファイル: __init__.py プロジェクト: agdsn/pycroft
def room_show(room_id):
    room = Room.get(room_id)

    if room is None:
        flash("Zimmer existiert nicht!", 'error')
        abort(404)

    form = RoomLogEntry()

    if form.validate_on_submit():
        lib.logging.log_room_event(form.message.data, current_user, room)
        flash('Kommentar hinzugefügt', 'success')
        session.session.commit()

    room_log_table = RoomLogTable(
        data_url=url_for(".room_logs_json", room_id=room.id))

    patch_port_table = PatchPortTable(data_url=url_for(".room_patchpanel_json",
                                                       room_id=room.id),
                                      room_id=room_id)

    return render_template(
        'facilities/room_show.html',
        page_title=f"Raum {room.short_name}",
        room=room,
        ports=room.patch_ports,
        user_buttons=list(map(user_button, room.users)),
        user_histories=[(user_button(room_history_entry.user),
                         room_history_entry.active_during.begin,
                         room_history_entry.active_during.end)
                        for room_history_entry in room.room_history_entries],
        room_log_table=room_log_table,
        patch_port_table=patch_port_table,
        form=form,
    )
コード例 #2
0
ファイル: facilities.py プロジェクト: agdsn/pycroft
def create_room(building,
                level,
                number,
                processor,
                address,
                inhabitable=True,
                vo_suchname: str | None = None):
    if Room.q.filter_by(number=number, level=level,
                        building=building).first() is not None:
        raise RoomAlreadyExistsException

    if vo_suchname and Room.q.filter_by(
            swdd_vo_suchname=vo_suchname).first() is not None:
        raise RoomAlreadyExistsException

    room = Room(number=number,
                level=level,
                inhabitable=inhabitable,
                building=building,
                address=address,
                swdd_vo_suchname=vo_suchname)

    log_room_event("Room created.", processor, room)

    return room
コード例 #3
0
ファイル: __init__.py プロジェクト: agdsn/pycroft
def patch_port_edit(switch_room_id, patch_port_id):
    switch_room = Room.get(switch_room_id)
    patch_port = PatchPort.get(patch_port_id)

    if not switch_room:
        flash(f"Raum mit ID {switch_room_id} nicht gefunden!", "error")
        return redirect(url_for('.overview'))

    if not switch_room.is_switch_room:
        flash("Dieser Raum ist kein Switchraum!", "error")
        return redirect(url_for('.room_show', room_id=switch_room_id))

    if not patch_port:
        flash(f"Patch-Port mit ID {patch_port_id} nicht gefunden!", "error")
        return redirect(url_for('.room_show', room_id=switch_room_id))

    if not patch_port.switch_room == switch_room:
        flash(f"Patch-Port ist nicht im Switchraum!", "error")
        return redirect(url_for('.room_show', room_id=switch_room_id))

    form = PatchPortForm(switch_room=switch_room.short_name,
                         name=patch_port.name,
                         building=patch_port.room.building,
                         level=patch_port.room.level,
                         room_number=patch_port.room.number)

    if form.validate_on_submit():
        room = Room.q.filter_by(building=form.building.data,
                                level=form.level.data,
                                number=form.room_number.data).one()

        try:
            edit_patch_port(patch_port, form.name.data, room, current_user)

            session.session.commit()

            flash("Der Patch-Port wurde erfolgreich bearbeitet.", "success")

            return redirect(
                url_for('.room_show',
                        room_id=switch_room_id,
                        _anchor="patchpanel"))
        except PatchPortAlreadyExistsException:
            session.session.rollback()

            form.name.errors.append(
                "Ein Patch-Port mit dieser Bezeichnung existiert bereits in diesem Switchraum."
            )

    form_args = {
        'form':
        form,
        'cancel_to':
        url_for('.room_show', room_id=switch_room_id, _anchor="patchpanel")
    }

    return render_template('generic_form.html',
                           page_title="Patch-Port bearbeiten",
                           form_args=form_args)
コード例 #4
0
ファイル: facilities.py プロジェクト: FriwiDev/pycroft
def create_room(building, level, number, processor, inhabitable=True):
    if Room.q.filter_by(number=number, level=level,
                        building=building).first() is not None:
        raise RoomAlreadyExistsException()

    room = Room(number=number,
                level=level,
                inhabitable=inhabitable,
                building=building)

    log_room_event("Room created.", processor, room)

    return room
コード例 #5
0
ファイル: __init__.py プロジェクト: agdsn/pycroft
def patch_port_delete(switch_room_id, patch_port_id):
    switch_room = Room.get(switch_room_id)
    patch_port = PatchPort.get(patch_port_id)

    if not switch_room:
        flash(f"Raum mit ID {switch_room_id} nicht gefunden!", "error")
        return redirect(url_for('.overview'))

    if not switch_room.is_switch_room:
        flash("Dieser Raum ist kein Switchraum!", "error")
        return redirect(url_for('.room_show', room_id=switch_room_id))

    if not patch_port:
        flash(f"Patch-Port mit ID {patch_port_id} nicht gefunden!", "error")
        return redirect(url_for('.room_show', room_id=switch_room_id))

    if not patch_port.switch_room == switch_room:
        flash(f"Patch-Port ist nicht im Switchraum!", "error")
        return redirect(url_for('.room_show', room_id=switch_room_id))

    form = Form()

    if form.validate_on_submit():
        delete_patch_port(patch_port, current_user)

        session.session.commit()

        flash("Der Patch-Port wurde erfolgreich gelöscht.", "success")

        return redirect(
            url_for('.room_show', room_id=switch_room_id,
                    _anchor="patchpanel"))

    form_args = {
        'form':
        form,
        'cancel_to':
        url_for('.room_show', room_id=switch_room_id, _anchor="patchpanel"),
        'submit_text':
        'Löschen',
        'actions_offset':
        0
    }

    return render_template('generic_form.html',
                           page_title="Patch-Port löschen",
                           form_args=form_args)
コード例 #6
0
ファイル: __init__.py プロジェクト: agdsn/pycroft
def room_patchpanel_json(room_id):
    room = Room.get(room_id)

    if not room:
        abort(404)

    if not room.is_switch_room:
        abort(400)

    patch_ports = PatchPort.q.filter_by(switch_room=room).all()
    patch_ports = sort_ports(patch_ports)
    T = PatchPortTable

    return jsonify(items=[
        {
            "name":
            port.name,
            "room":
            T.room.value(href=url_for(".room_show", room_id=port.room.id),
                         title=port.room.short_name),
            "switch_port":
            T.switch_port.value(
                href=url_for("infrastructure.switch_show",
                             switch_id=port.switch_port.switch.host_id),
                title=
                f"{port.switch_port.switch.host.name}/{port.switch_port.name}"
            ) if port.switch_port else None,
            'edit_link':
            T.edit_link.value(
                hef=url_for(".patch_port_edit",
                            switch_room_id=room.id,
                            patch_port_id=port.id),
                title="Bearbeiten",
                icon='fa-edit',
                # TODO decide on a convention here
                btn_class='btn-link',
            ),
            'delete_link':
            T.delete_link.value(href=url_for(".patch_port_delete",
                                             switch_room_id=room.id,
                                             patch_port_id=port.id),
                                title="Löschen",
                                icon='fa-trash',
                                btn_class='btn-link'),
        } for port in patch_ports
    ])
コード例 #7
0
ファイル: __init__.py プロジェクト: agdsn/pycroft
    def post(self):
        """
        Create a member request
        """

        parser = reqparse.RequestParser()
        parser.add_argument('first_name', required=True, type=str)
        parser.add_argument('last_name', required=False, type=str)
        parser.add_argument('birthdate', required=True, type=parse_iso_date)
        parser.add_argument('email', required=True, type=str)
        parser.add_argument('password', required=True, type=str)
        parser.add_argument('login', required=True, type=str)
        parser.add_argument('person_id', required=False, type=int)
        parser.add_argument('room_id', required=False, type=int)
        parser.add_argument('move_in_date', required=False, type=parse_iso_date)
        parser.add_argument('previous_dorm', required=False, type=str)
        args = parser.parse_args()

        room = None
        swdd_person_id = None

        if args.room_id is not None:
            room = Room.get(args.room_id)

            if room is None:
                abort(404, message="Invalid room", code="invalid_room")

        if args.person_id is not None:
            swdd_person_id = get_swdd_person_id(args.first_name, args.last_name, args.birthdate)

            # some tenants have an additional semicolon added to their last names
            if swdd_person_id is None:
                swdd_person_id = get_swdd_person_id(
                    args.first_name, args.last_name + ";", args.birthdate
                )

            if swdd_person_id != args.person_id:
                abort(400, message="Person id does not match", code="person_id_mismatch")

        name = get_name_from_first_last(args.first_name, args.last_name)

        try:
            mr = create_member_request(name, args.email, args.password, args.login, args.birthdate,
                                       swdd_person_id, room, args.move_in_date, args.previous_dorm)
        except UserExistsException:
            abort(400, message="User already exists", code="user_exists")
        except UserExistsInRoomException:
            abort(400, message="A user with a similar name already lives in this room",
                  code="similar_user_exists")
        except EmailTakenException:
            abort(400, message="E-Mail address already in use", code="email_taken")
        except LoginTakenException:
            abort(400, message="Login already in use", code="login_taken")
        except IllegalEmailError:
            abort(400, message="Illegal E-Mail address", code="email_illegal")
        except IllegalLoginError:
            abort(400, message="Illegal login", code="login_illegal")
        except NoTenancyForRoomException:
            abort(400, message="The given person has no tenancy for the room",
                  code="no_tenancy_in_room")
        except MoveInDateInvalidException:
            abort(400, message="The move-in date is invalid", code="move_in_date_invalid")
        else:
            session.session.commit()

            return mr.id
コード例 #8
0
ファイル: __init__.py プロジェクト: agdsn/pycroft
def room_logs_json(room_id):
    return jsonify(items=[
        format_room_log_entry(entry)
        for entry in reversed(Room.get(room_id).log_entries)
    ])
コード例 #9
0
ファイル: __init__.py プロジェクト: agdsn/pycroft
def room_edit(room_id):
    room = Room.get(room_id)

    if not room:
        flash(f"Raum mit ID {room_id} nicht gefunden!", "error")
        return redirect(url_for('.overview'))

    form = EditRoomForm(building=room.building.short_name,
                        level=room.level,
                        number=room.number,
                        inhabitable=room.inhabitable,
                        vo_suchname=room.swdd_vo_suchname)

    if form.validate_on_submit():
        try:
            with session.session.no_autoflush:
                address = get_or_create_address(**form.address_kwargs)
                edit_room(room,
                          form.number.data,
                          form.inhabitable.data,
                          form.vo_suchname.data,
                          address=address,
                          processor=current_user)

            session.session.commit()

            flash(f"Der Raum {room.short_name} wurde erfolgreich bearbeitet.",
                  "success")

            return redirect(url_for('.room_show', room_id=room.id))
        except RoomAlreadyExistsException:
            form.number.errors.append(
                "Ein Raum mit diesem Namen existiert bereits in dieser Etage!")

    old_addr = room.address
    if not form.is_submitted():
        form.address_street.data = old_addr.street
        form.address_number.data = old_addr.number
        form.address_addition.data = old_addr.addition
        form.address_zip_code.data = old_addr.zip_code
        form.address_city.data = old_addr.city
        form.address_state.data = old_addr.state
        form.address_country.data = old_addr.country

    if room.users_sharing_address:
        flash(
            gettext(
                "Dieser Raum hat {} bewohner ({}), die die Adresse des Raums teilen."
                " Ihre Adresse wird beim Ändern automatisch angepasst.").
            format(len(room.users_sharing_address),
                   ', '.join(u.name for u in room.users_sharing_address)),
            'info')

    form_args = {
        'form': form,
        'cancel_to': url_for('.room_show', room_id=room.id)
    }

    return render_template('generic_form.html',
                           page_title="Raum bearbeiten",
                           form_args=form_args)