Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CreateContaCorrente(LoginRequiredMixin,SuccessMessageMixin,CreateView):
- '''
- Cria uma conta corrente para um projeto
- '''
- model = ContasBancarias
- fields=['Nome','Status','idBanco','Agencia','Numero','DataAbertura',
- 'SaldoInicial']
- template_name = 'sigcaa/subprojetos/form_cadastro_padrao.html'
- botao_submit = ''
- success_message = "%(Nome)s criado com sucesso"
- projeto = -1
- def get(self, request, *args, **kwargs):
- pk_projeto = retornar_inteiro(kwargs.get('pk_projeto',-1),False)
- if pk_projeto > 0:
- self.projeto = get_object_or_404(Projetos,pk=pk_projeto)
- if isinstance(self.projeto.idContaBancaria,ContasBancarias):
- url= reverse('institucional:atualizar_conta_corrente',kwargs={'pk':self.projeto.idContaBancaria.pk})
- return HttpResponseRedirect(url)
- return super(CreateContaCorrente, self).get(request, *args, **kwargs)
- def post(self, request, *args, **kwargs):
- #do something else
- self.usuario = request.user
- pk_projeto = retornar_inteiro(kwargs.get('pk_projeto',-1),False)
- if pk_projeto > 0:
- self.projeto = get_object_or_404(Projetos,pk=pk_projeto)
- if "_add_another" in request.POST:
- self.botao_submit = "_add_another"
- return super(CreateContaCorrente, self).post(request, *args, **kwargs)
- def form_valid(self, form):
- form.instance.usuario_criacao = self.request.user
- form.instance.flags['projeto_institucional'] = self.request.session.get('projeto_institucional',{})
- form.instance.save()
- if self.projeto:
- if not self.projeto.idContaBancaria:
- self.projeto.idContaBancaria = form.instance
- self.projeto.save()
- return super(CreateContaCorrente, self).form_valid(form)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement