Esempio n. 1
0
def add(request):
    police_form = PoliceForm(data=request.POST or None)
    if police_form.is_valid():
        police_form.save(auth.get_user(request))
        messages.success(request, u"Material salvo com sucesso.")
        return redirect('police_list')

    template_context = {
        'police_form': police_form,
    }
    return render(request=request,
                  template_name='police/add.html',
                  dictionary=template_context)
Esempio n. 2
0
def edit(request, pk):
    police = get_object_or_404(klass=Police, pk=pk)
    police_form = PoliceForm(data=request.POST or None, instance=police)
    if police_form.is_valid():
        police_form.save(auth.get_user(request))
        messages.success(request, u"Material editado com sucesso.")
        return redirect('police_list')

    template_context = {
        'police': police,
        'police_form': police_form,
    }
    return render(request=request,
                  template_name='police/edit.html',
                  dictionary=template_context)
Esempio n. 3
0
def add(request):
    police_form = PoliceForm(
        data=request.POST or None
    )
    if police_form.is_valid():
        police_form.save(auth.get_user(request))
        messages.success(request, u"Material salvo com sucesso.")
        return redirect('police_list')
    
    template_context = {
        'police_form': police_form,
    }
    return render(
        request=request,
        template_name='police/add.html',
        dictionary=template_context
    )
Esempio n. 4
0
def edit(request, pk):
    police = get_object_or_404(
        klass=Police, 
        pk=pk
    )
    police_form = PoliceForm(
        data=request.POST or None,
        instance=police
    )
    if police_form.is_valid():
        police_form.save(auth.get_user(request))
        messages.success(request, u"Material editado com sucesso.")
        return redirect('police_list')

    template_context = {
        'police': police,
        'police_form': police_form,
    }
    return render(
        request=request,
        template_name='police/edit.html',
        dictionary=template_context
    )