示例#1
0
def modalitiesprice_new(request):
    template_name = 'modalidade_preco/modalitiesprice_form.html'
    academy_id = request.user.asuser.academy_id

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

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

    form = ModalitiesPriceForm(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:modalitiesprice_list'))
示例#2
0
def modalitiesprice_update(request, pk):
    template_name = 'modalidade_preco/modalitiesprice_form.html'
    academy_id = request.user.asuser.academy_id

    modalitiesprice = get_object_or_404(ModalitiesPrice, pk=pk)

    if modalitiesprice.academy_id != academy_id:
        raise Http404()

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

    context = {'label': 'Editar', 'form': form}
    return render(request, template_name, context)