def obter_arquivo_contrato(self, request): try: m_contrato = self.apropriar_dados_http(request.data) retorno_contrato = m_contrato.gerar_contrato_pdf() if not retorno_contrato.estado.ok: return retorno_contrato.gerar_resposta_http() dados_arquivo = retorno_contrato.dados arquivo = open(dados_arquivo['caminho_arquivo'], 'rb') mime_type, _ = mimetypes.guess_type( dados_arquivo['caminho_arquivo']) http_response = HttpResponse(arquivo, content_type=mime_type) http_response[ 'Content-Disposition'] = "attachment; filename=%s" % dados_arquivo[ 'nome_arquivo'] return http_response except Exception as e: retorno = Retorno(False, self, 'A consulta do arquivo pdf do contrato falhou.', None, None, e) return retorno.gerar_resposta_http()
def aceitar(self, request): try: m_contrato = self.apropriar_dados_http(request.data) retorno_contrato = m_contrato.obter() if not retorno_contrato.estado.ok: return retorno_contrato.gerar_resposta_http() m_contrato = retorno_contrato.dados # m_contrato.credencial = ContratoViewSet.apropriar_credenciais_clicksign_http(request) if not m_contrato.aceito: retorno = m_contrato.aceitar() else: m_boleto = self.definir_contexto(BoletoGerenciaNet()) retorno = m_boleto.obter(m_contrato) return retorno.gerar_resposta_http() except Exception as e: retorno = Retorno(False, self, 'A aceitação do contrato falhou.', None, None, e) return retorno.gerar_resposta_http()
def registrar_do_cliente(self, request): try: retorno = Retorno(True, self) if 'registros_log' in request.data: d_registros_log = request.data['registros_log'] m_gerenciador_log = self.definir_contexto(GerenciadorLog()) retorno = m_gerenciador_log.registrar_do_cliente(d_registros_log) return retorno.gerar_resposta_http() except Exception as e: retorno = Retorno(False, self, 'O registro de log do cliente falhou.', None, None, e) return retorno.gerar_resposta_http()
def handle_exception(self, exc): mensagem = '' if exc and len(exc.args) > 0: mensagem = exc.args[0] response = super().handle_exception(exc) retorno = Retorno(False, self, mensagem, '', response.status_code, exc) return retorno.gerar_resposta_http()
def listar(self, request): try: m_produto = self.definir_contexto(Produto()) retorno_produtos = m_produto.listar() return retorno_produtos.gerar_resposta_http() except Exception as e: retorno = Retorno(False, self, 'A consulta a produtos Trisafe falhou.', None, None, e) return retorno.gerar_resposta_http()
def obter_por_cliente(self, request): try: m_contrato = self.apropriar_dados_http(request.data) retorno = m_contrato.obter_por_cliente() return retorno.gerar_resposta_http() except Exception as e: retorno = Retorno(False, self, 'A consulta do contrato falhou.', None, None, e) return retorno.gerar_resposta_http()
def autenticar_cliente(self, request): try: configuracao = AutenticacaoTriSafe(self) return configuracao.retorno_autenticacao.gerar_resposta_http() except Exception as e: retorno = Retorno(False, self, 'Autenticação do aplicativo falhou.', None, None, e) return retorno.gerar_resposta_http()
def obter(self, request): try: self.apropriar_dados_http_chave(request.data) retorno_cliente = self.m_cliente.obter() return retorno_cliente.gerar_resposta_http() except Exception as e: retorno = Retorno(False, self, 'A consulta dos dados cadastrais falhou.', None, None, e) return retorno.gerar_resposta_http()
def excluir_arquivo_contrato(self, request): try: m_contrato = self.apropriar_dados_http(request.data) retorno = m_contrato.excluir_contrato() return retorno.gerar_resposta_http() except Exception as e: retorno = Retorno(False, self, 'A exclusão do arquivo pdf do contrato falhou.', None, None, e) return retorno.gerar_resposta_http()
def salvar_foto_cnh(self, request): try: self.apropriar_dados_http_chave(request.data) foto_cnh_base64 = self.apropriar_dados_http_foto_cnh(request.data) retorno_cliente = self.m_cliente.salvar_foto_cnh(foto_cnh_base64) return retorno_cliente.gerar_resposta_http() except Exception as e: retorno = Retorno(False, self, 'A inclusão da foto CNH falhou.', None, None, e) return retorno.gerar_resposta_http()
def obter(self, request): try: self.apropriar_dados_http(request.data) retorno_veiculo = self.m_veiculo.obter() return retorno_veiculo.gerar_resposta_http() except Exception as e: retorno = Retorno( False, self, 'A consulta dos dados cadastrais do veículo falhou.', None, None, e) return retorno.gerar_resposta_http()
def incluir(self, request): try: self.apropriar_dados_http(request.data) retorno = self.m_cliente.incluir() return retorno.gerar_resposta_http() except Exception as e: retorno = Retorno(False, self, 'A inclusão dos dados cadastrais falhou.', None, None, e) return retorno.gerar_resposta_http()
def enviar_com_anexos(self, request): try: m_email_cliente = self.definir_contexto(EmailCliente()) m_contrato = EmailClienteViewSet.apropriar_dados_http(request) self.definir_contexto(m_contrato) retorno = m_email_cliente.enviar_com_anexos(m_contrato) return retorno.gerar_resposta_http() except Exception as e: retorno = Retorno(False, None, None, None, e) return retorno.gerar_resposta_http()
def alterar(self, request): try: self.apropriar_dados_http(request.data) retorno = self.m_veiculo.alterar() return retorno.gerar_resposta_http() except Exception as e: retorno = Retorno(False, self, 'A atualização dos dados do veículo falhou.', None, None, e) return retorno.gerar_resposta_http()
def incluir_com_signatario(self, request): try: m_contrato = self.apropriar_dados_http(request.data) retorno_contrato = m_contrato.incluir_com_signatario() if not retorno_contrato: return retorno_contrato return retorno_contrato.gerar_resposta_http() except Exception as e: retorno = Retorno(False, self, 'A inclusão do contrato falhou.', None, None, e) return retorno.gerar_resposta_http()
def listar_por_cliente(self, request): try: self.apropriar_dados_http(request.data) retorno = self.m_veiculo.listar_por_cliente() return retorno.gerar_resposta_http() except Exception as e: retorno = Retorno( False, self, 'A consulta a veículos cadastrados do Cliente falhou.', None, None, e) return retorno.gerar_resposta_http()
def salvar_foto_doc(self, request): try: self.apropriar_dados_http(request.data) foto_doc_base64 = self.extrair_dados_http_foto_doc(request.data) retorno = self.m_veiculo.salvar_foto_doc(foto_doc_base64) return retorno.gerar_resposta_http() except Exception as e: retorno = Retorno( False, self, 'A consulta a veículos cadastrados do Cliente falhou.', None, None, e) return retorno.gerar_resposta_http()