Пример #1
0
def eleicao_urna_nova(request,eleicao_id):
    '''
      @eleicao_urna_nova: Metodo de criação de uma nova Urna 
    '''
    eleicao = Eleicao.objects.get(id=eleicao_id)
    
    if request.method == 'POST':
        formUrna = UrnaForm(request.POST)
            
        if formUrna.is_valid():
            urna = formUrna.save(commit=False)
            urna.eleicao = eleicao
            urna.save()

            return HttpResponseRedirect( r('urna:eleicao_urnas', kwargs={'eleicao_id':eleicao.id}))
        else:
            formUrna.fields['distrito'].queryset = DistritoEleitoral.objects.filter(eleicao=eleicao).order_by('nome')         
            return render(request,'urna_nova.html',{'form': formUrna,'status':'Nova','eleicao':eleicao})
    else:
        formUrna = UrnaForm()
        formUrna.fields['distrito'].queryset = DistritoEleitoral.objects.filter(eleicao=eleicao).order_by('nome')         
        return render(request,'urna_nova.html',{'form': formUrna,'status':'Nova','eleicao':eleicao})
Пример #2
0
def eleicao_urna_editar(request,id_urna,eleicao_id):
    '''
      @eleicao_candidato_editar: Metodo de edição de um candidato cadastrado na base
    '''

    urna = Urna.objects.get(id=id_urna)
    eleicao = Eleicao.objects.get(id=eleicao_id)
    
    if request.method == 'POST':

        formUrna= UrnaForm(request.POST,instance=urna)      
        
        if formUrna.is_valid():            
            urna = formUrna.save(commit=False)
            urna.save()
            
            return HttpResponseRedirect( r('urna:eleicao_urnas', kwargs={'eleicao_id':eleicao.id}))
        else:
            formUrna.fields['distrito'].queryset = DistritoEleitoral.objects.filter(eleicao=eleicao).order_by('nome')
            return render(request, 'urna_nova.html', { 'form':formUrna,'id_urna':id_urna,'status':'Editar','eleicao':eleicao})
    else:  
        formUrna = UrnaForm(instance=urna)
        formUrna.fields['distrito'].queryset = DistritoEleitoral.objects.filter(eleicao=eleicao).order_by('nome')         
        return render(request,'urna_nova.html',{'form':formUrna,'id_urna':id_urna,'status':'Editar','eleicao':eleicao})