Ejemplo n.º 1
0
def reimburse(request):
    
    form = ExpenseCreationForm(data=request.POST or None)

    if form.is_valid():
        form.save(request)
        return redirect(reverse('profile'))

    return render(request, 'index.html', {'form': form})
Ejemplo n.º 2
0
def reimburse(request, id=None):

    form = ExpenseCreationForm(request.user)
    if id:
        e = get_object_or_404(Expense, id=id, usr=request.user)
        if e.status:
            raise Http404
        form = ExpenseCreationForm(request.user, instance=e)


    if request.method == "POST":
        if id:
            form = ExpenseCreationForm(request.user, request.POST, request.FILES,
                                       instance=e)
        else:
            form = ExpenseCreationForm(request.user, request.POST, request.FILES)


        if form.is_valid():
            m = form.save(request)
            return redirect(reverse('profile'))

    data = {'form': form}
    return render_to_response("index.html", data,
                              context_instance=RequestContext(request))