Ejemplo n.º 1
0
def add(request, room=None):
    add_form = MemberInfoForm(request.POST or None)
    add_form.fields['room'].choices = free_rooms_choices()
    
    if room:
        try:
            room = Room.objects.get(Q(name=room)&Q(member=None))
            add_form.fields['room'].initial = room
            messages.info(request, u"La chambre {} a été présélectionnée".format(room))
        except Room.DoesNotExist:
            pass
    
    if request.method == 'POST':
        if add_form.is_valid():
            member = add_form.save(commit=False)
            member.save()
            return redirect("ogre_member_show", uuid=member.uuid)
    
    return render(request, "ogre/member/add.html", {
        'form': add_form,
    })
Ejemplo n.º 2
0
def edit(request, uuid):
    try:
        member = Member.objects.get(uuid=uuid)
        
        edit_form = MemberInfoForm(
            request.POST or None,
            instance=member,
            current_room=member.room or None
        )
        
        if request.method == 'POST':
            if edit_form.is_valid():
                member = edit_form.save(commit=False)
                member.save()
                return redirect("ogre_member_show", uuid=member.uuid)
        
        return render(request, "ogre/member/edit.html", {
            'form': edit_form,
            'member': member,
        })
    except Member.DoesNotExist:
        messages.warning(request, u"Impossible de trouver la personne demandée")
        return redirect("ogre_member")