Beispiel #1
0
 def test_change_number_and_address(self):
     new_address = get_or_create_address(street='Wundtstraße',
                                         number='5',
                                         addition='Keller',
                                         zip_code='01217',
                                         city='Dresden')
     edit_room(self.room, 'new number', self.room.inhabitable,
               self.room.swdd_vo_suchname, new_address, self.processor)
Beispiel #2
0
def room_create():
    building_id = request.args.get("building_id")

    building = None

    if building_id:
        building = Building.q.get(building_id)

        if not building:
            flash("Gebäude mit ID {} nicht gefunden!".format(building_id),
                  "error")
            return redirect(url_for('.overview'))

    form = CreateRoomForm(building=building)

    if form.validate_on_submit():
        try:
            address = get_or_create_address(**form.address_kwargs)
            room = create_room(form.building.data,
                               form.level.data,
                               form.number.data,
                               address=address,
                               processor=current_user,
                               inhabitable=form.inhabitable.data)

            session.session.commit()

            flash(
                "Der Raum {} wurde erfolgreich erstellt.".format(
                    room.short_name), "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!")
            session.session.rollback()

    form_args = {'form': form, 'cancel_to': url_for('.overview')}

    suggestion = suggest_room_address_data(building)
    if suggestion and not form.is_submitted():
        form.address_street.data = suggestion.street
        form.address_number.data = suggestion.number
        form.address_zip_code.data = suggestion.zip_code
        form.address_city.data = suggestion.city
        form.address_state.data = suggestion.state
        form.address_country.data = suggestion.country

    return render_template('generic_form.html',
                           page_title="Raum erstellen",
                           form_args=form_args)
Beispiel #3
0
    def test_new_address_gets_created(self):
        old_count = self.count_addrs()
        new_addr = address.get_or_create_address(
            street='Wundtstraße',
            number='3',
            addition=None,
            zip_code='01217',
            city='Dresden',
        )
        self.session.commit()

        assert inspect(
            new_addr).has_identity, "Created address has no db identity"

        assert self.count_addrs() == old_count + 1
Beispiel #4
0
    def test_existing_address_gets_returned(self):
        old_count = self.count_addrs()
        new_addr = address.get_or_create_address(
            **{
                key: val
                for key, val in self.known_address.__dict__.items() if key in {
                    'street', 'number', 'addition', 'zip_code', 'city',
                    'state', 'country'
                }
            })
        self.session.commit()

        assert inspect(
            new_addr).has_identity, "Created address has no db identity"

        assert self.count_addrs() == old_count
Beispiel #5
0
    def test_new_address_gets_server_defaults(self):
        """Test that missing entries get the server default and not the empty string."""
        new_addr = address.get_or_create_address(
            street='Wundtstraße',
            number='3',
            addition=None,
            zip_code='01217',
            city=None,
            state=None,
            country=None,
        )
        self.session.commit()
        self.session.refresh(new_addr)

        assert new_addr.city == 'Dresden', "City not set"
        # state's default actually _is_ ''
        assert new_addr.country == 'Germany', "Country not set"
Beispiel #6
0
def edit_address(
    user: User,
    processor: User,
    street: str,
    number: str,
    addition: Optional[str],
    zip_code: str,
    city: Optional[str],
    state: Optional[str],
    country: Optional[str],
):
    """Changes the address of a user and appends a log entry.

    Should do nothing if the user already has an address.
    """
    address = get_or_create_address(street, number, addition, zip_code, city,
                                    state, country)
    user.address = address
    log_user_event(
        deferred_gettext("Changed address to {address}").format(
            address=str(address)).to_json(), processor, user)
Beispiel #7
0
def room_edit(room_id):
    room = Room.q.get(room_id)

    if not room:
        flash("Raum mit ID {} nicht gefunden!".format(room_id), "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(
                "Der Raum {} wurde erfolgreich bearbeitet.".format(
                    room.short_name), "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)