~homeworkprod/byceps-bungalows

50079d16328f7b42b4e02668fecbdd53b8dfce61 — Jochen Kupperschmidt 2 months ago 4bf50e0
Add admin UI to appoint bungalow manager
M byceps/blueprints/admin/bungalow/forms.py => byceps/blueprints/admin/bungalow/forms.py +5 -0
@@ 22,6 22,7 @@ from byceps.services.party.models import PartyID
from byceps.services.shop.article import article_service
from byceps.services.shop.shop.models import ShopID
from byceps.services.ticketing import ticket_category_service
from byceps.util.forms import UserScreenNameField
from byceps.util.l10n import LocalizedForm




@@ 116,6 117,10 @@ class InternalRemarkUpdateForm(LocalizedForm):
    internal_remark = StringField('Anmerkung', [Optional(), Length(max=200)])


class AppointManagerForm(LocalizedForm):
    manager = UserScreenNameField(lazy_gettext('Username'), [InputRequired()])


class OccupancyMoveForm(LocalizedForm):
    target_bungalow_id = RadioField(
        lazy_gettext('Ziel-Bungalow'), validators=[InputRequired()]

M byceps/blueprints/admin/bungalow/templates/admin/bungalow/index_for_party.html => byceps/blueprints/admin/bungalow/templates/admin/bungalow/index_for_party.html +1 -0
@@ 120,6 120,7 @@
            {%- endif %}
            {%- if bungalow.reserved_or_occupied %}
              <li><a class="dropdown-item" href="{{ url_for('.internal_remark_update_form', occupancy_id=bungalow.occupancy.id) }}">{{ render_icon('note') }} Anmerkung bearbeiten</a></li>
              <li><a class="dropdown-item" href="{{ url_for('.appoint_manager_form', occupancy_id=bungalow.occupancy.id) }}">{{ render_icon('arrow-right') }} Verwaltung ├╝bertragen</a></li>
              <li><a class="dropdown-item" href="{{ url_for('.occupancy_move_form', occupancy_id=bungalow.occupancy.id) }}">{{ render_icon('arrow-right') }} Belegung verschieben</a></li>
            {%- else %}
              <li class="dropdown-divider"></li>

M byceps/blueprints/admin/bungalow/views.py => byceps/blueprints/admin/bungalow/views.py +49 -0
@@ 57,6 57,7 @@ from byceps.util.framework.blueprint import create_blueprint
from byceps.util.framework.flash import flash_error, flash_notice, flash_success
from byceps.util.framework.templating import templated
from byceps.util.iterables import find
from byceps.util.result import Err, Ok
from byceps.util.views import (
    permission_required,
    redirect_to,


@@ 67,6 68,7 @@ from byceps.util.views import (

from . import service
from .forms import (
    AppointManagerForm,
    BuildingCreateForm,
    CategoryCreateForm,
    CategoryUpdateForm,


@@ 554,6 556,53 @@ def internal_remark_update(occupancy_id):
    return redirect_to('.index_for_party', party_id=bungalow.party_id)


@blueprint.get('/occupancies/<occupancy_id>/manager/update')
@permission_required('bungalow.update')
@templated
def appoint_manager_form(occupancy_id, erroneous_form=None):
    """Show form to appoint a user as occupancy manager."""
    occupancy = _get_occupancy_or_404(occupancy_id)

    bungalow = bungalow_service.get_db_bungalow(occupancy.bungalow_id)
    party = party_service.find_party(bungalow.party_id)

    form = erroneous_form if erroneous_form else AppointManagerForm()

    return {
        'party': party,
        'occupancy': occupancy,
        'form': form,
    }


@blueprint.post('/occupancies/<occupancy_id>/manager')
@permission_required('bungalow.update')
def appoint_manager(occupancy_id):
    """Appoint a user as occupancy manager."""
    occupancy = _get_occupancy_or_404(occupancy_id)

    bungalow = bungalow_service.get_db_bungalow(occupancy.bungalow_id)
    party = party_service.find_party(bungalow.party_id)

    form = AppointManagerForm(request.form)

    if not form.validate():
        return appoint_manager_form(occupancy_id, form)

    manager = form.manager.data
    initiator = g.user

    match bungalow_occupancy_service.appoint_bungalow_manager(
        occupancy_id, manager, initiator
    ):
        case Ok(_):
            flash_success('Die Verwaltung wurde ├╝bertragen.')
        case Err(_):
            flash_error('Die Verwaltung konnte nicht ├╝bertragen werden.')

    return redirect_to('.index_for_party', party_id=party.id)


@blueprint.get('/occupancies/<occupancy_id>/move')
@permission_required('bungalow.update')
@templated