-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.py
More file actions
63 lines (51 loc) · 1.6 KB
/
router.py
File metadata and controls
63 lines (51 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'''
Created on Feb 21, 2017
@author: rinzler
'''
from django.shortcuts import render, redirect
from resumo.services.relatorio import Relatorio
from resumo.config import URL_APP, URL_STATIC
# Create your views here.
class Router(object):
#metodos das actions
def index(self, request, error=None):
return render(request, 'home/index.html', {
'urlLibrary': URL_STATIC +"/LibraryJS",
'URL_STATIC': URL_STATIC,
'URL_APP': URL_APP,
'error': '' if error == None else self.getErrorByCod(error)
})
def relatorio(self, request, protocolo):
dados = Relatorio().getDadosProtocolo(protocolo)
if(dados == False):
return self.redirErro(request, '005')
else:
return render(request, 'relatorio/lista.html', {
'dados': dados,
'URL_STATIC': URL_STATIC,
'URL_APP': URL_APP,
})
def raw(self, request, protocolo):
dados = Relatorio().getDadosRaw(protocolo)
if(dados == False):
return self.redirErro(request, '001')
else:
return render(request, 'relatorio/raw.html', {
'dados': dados[35:(len(dados) - 1)]
}, content_type="application/json; charset=utf-8")
#Redirects
def redirProtocolo(self, request, protocolo):
return redirect('/resumo/relatorio/protocolo/{0}/'.format(protocolo))
def redirErro(self, request, error):
return redirect('/resumo/error/{0}/'.format(error))
#Métodos axiliares
def getErrorByCod(self, code=None):
errors = {
'000': "Não foi possível processar sua solicitação. Tente novamente.",
'001': "Protocolo inválido",
'002': "Informe um protocolo válido",
}
if(code in errors):
return errors[code]
else:
return errors['000']