Beispiel #1
0
def transfer_add(request):
    """
    View for handling the creation/modify of the Transfer objects.
    """
    latest = Transfer.objects.select_related().order_by('-created_on')[:10] 

    if request.method == 'POST':
        form = TransferForm(request.POST)
        if form.is_valid():
            form.save()
            _update_balance([form.instance.source, form.instance.destination])
            #request.user.message_set.create(message="%s" % form['notify_recipients'].field)
            return HttpResponseRedirect(reverse('transfer-add')) # redirect after post
    else:
        form = TransferForm() # an unbound form

    return render_to_response('cash/transfer_add.html', {'form': form, 'latest': latest}, context_instance=RequestContext(request))
Beispiel #2
0
def transfer(request, object_id):

    latest = Transfer.objects.select_related().order_by('-created_on')[:10] 

    transfer = get_object_or_404(Transfer, pk=object_id)

    if request.method == 'POST':
        form = TransferForm(request.POST, instance=transfer)   
        if form.is_valid():
            form.save()
            #request.user.message_set.create(message="Transfer aggiornato con successo")
            messages.success(request, 'Transfer updated successfully.')
            _update_balance([form.instance.source, form.instance.destination])
            return HttpResponseRedirect(reverse('transfer-detail', kwargs=dict(object_id=transfer.id))) # redirect after post

    else:
        form = TransferForm(instance=transfer)

    return render_to_response('cash/transfer_add.html', {'form': form, 'latest': latest}, context_instance=RequestContext(request))