Esempio n. 1
0
def payment_update(request, pk):
    template_name = 'pagamento/payment_form.html'
    academy_id = request.user.asuser.academy_id

    payment = get_object_or_404(Payment, pk=pk)

    if payment.student.academy_id != academy_id:
        raise Http404()

    if request.method == "POST":
        form = PaymentForm(request.POST, instance=payment, initial={'academy_id':academy_id})
        if form.is_valid():
            form.save(commit=False)
            messages.success(request, UPDATE_MSG)
            return HttpResponseRedirect(r('billing:payment_list'))
    else:
        form = PaymentForm(instance=payment, initial={'academy_id':academy_id})

    context = {'label': 'Editar', 'form': form}
    return render(request, template_name, context)
Esempio n. 2
0
def payment_new(request):
    template_name = 'pagamento/payment_form.html'
    academy_id = request.user.asuser.academy_id

    context = {'label': 'Cadastrar', 'form': PaymentForm(initial={'academy_id':academy_id})}

    if request.method == 'GET':
        return render(request, template_name, context)

    form = PaymentForm(request.POST, initial={'academy_id':academy_id})
    context['form'] = form

    if not form.is_valid():
        return render(request, template_name, context)

    form.instance.academy_id = request.user.asuser.academy_id
    form.save()

    messages.success(request, SUCCESS_MSG)
    return HttpResponseRedirect(r('billing:payment_list'))