Пример #1
0
def create_room(request):
    form = RoomForm(request.POST)

    if not form.is_valid():
        return render(request, "reservations/new_room_form.html", {"form": form})
    room = form.save(commit=False)
    room.slug = slugify(room.name)
    room.community = request.user.community
    form.save()

    messages.success(request, "Novo ambiente criado. Confira na lista abaixo.")
    return HttpResponseRedirect(r("reservations:rooms_control"))
Пример #2
0
def room_edit(request, pk):
    try:
        instance = Room.objects.get(pk=pk)
    except Room.DoesNotExist:
        raise Http404

    form = RoomForm(request.POST or None, instance=instance)

    if not form.is_valid():
        return render(request, "reservations/room_edit_form.html", {"form": form, "room": instance})
    form.save()

    messages.success(request, "Ambiente alterado com sucesso.")
    return HttpResponseRedirect(r("reservations:rooms_control"))