Commit 30e191f6b09366b498688228f72831e7956faf8b
Exists in
master
merge
Showing
6 changed files
with
130 additions
and
8 deletions
Show diff stats
wscacicneo/__init__.py
... | ... | @@ -28,6 +28,7 @@ def main(global_config, **settings): |
28 | 28 | cfg.add_route('root', '/') |
29 | 29 | |
30 | 30 | cfg.add_route('home', 'home') |
31 | + cfg.add_route('error', 'error') | |
31 | 32 | cfg.add_route('graficop', 'graficop') |
32 | 33 | cfg.add_route('notifications', 'notifications') |
33 | 34 | cfg.add_route('admin', 'admin') |
... | ... | @@ -92,4 +93,4 @@ def main(global_config, **settings): |
92 | 93 | cfg.add_route('confighome','confighome') |
93 | 94 | cfg.add_route('db','db') |
94 | 95 | cfg.scan() |
95 | - return cfg.make_wsgi_app() | |
96 | 96 | \ No newline at end of file |
97 | + return cfg.make_wsgi_app() | ... | ... |
wscacicneo/model/reports.py
... | ... | @@ -25,15 +25,18 @@ class Reports(): |
25 | 25 | self.rest_url = config.REST_URL |
26 | 26 | else: |
27 | 27 | self.rest_url = rest_url |
28 | - self.base = coleta_manual.ColetaManualBase(nm_base, self.rest_url).lbbase | |
28 | + self.coleta_manual_base = coleta_manual.ColetaManualBase(nm_base, self.rest_url) | |
29 | + self.base = self.coleta_manual_base.lbbase | |
29 | 30 | print(type(self.base)) |
30 | 31 | self.documentrest = DocumentREST(self.rest_url, self.base, response_object=True) |
31 | 32 | |
32 | 33 | |
33 | 34 | def get_base_orgao(self): |
34 | 35 | """ |
35 | - retorna todos os documentos da base | |
36 | + Retorna todos os documentos da base | |
36 | 37 | """ |
38 | + # A resposta nao pode ser object aqui | |
39 | + self.documentrest.response_object = False | |
37 | 40 | search = Search( |
38 | 41 | limit=None |
39 | 42 | ) |
... | ... | @@ -82,4 +85,44 @@ class Reports(): |
82 | 85 | Apaga os dados de coleta |
83 | 86 | """ |
84 | 87 | coleta = self.documentrest.update(id) |
85 | - return coleta | |
86 | 88 | \ No newline at end of file |
89 | + return coleta | |
90 | + def get_attribute(self, attr): | |
91 | + """ | |
92 | + Testa recuperar atributo do Documento | |
93 | + """ | |
94 | + # A resposta nao pode ser object aqui | |
95 | + self.documentrest.response_object = False | |
96 | + | |
97 | + # FIXME: Adicionar lista de atributos obrigatórios nos campos que vao retornar na busca | |
98 | + # Referência: http://dev.lightbase.cc/projects/liblightbase/repository/revisions/master/entry/liblightbase/lbbase/content.py#L34 | |
99 | + | |
100 | + # A busca deve obrigatoriamente retornar todos os atributos obrigatórios | |
101 | + search = Search( | |
102 | + limit=None, | |
103 | + select=[attr, "data_coleta"] | |
104 | + ) | |
105 | + get = self.documentrest.get_collection(search_obj=search) | |
106 | + | |
107 | + return get | |
108 | + | |
109 | + def count_attribute(self, attr, child=None): | |
110 | + """ | |
111 | + retorna dicionário de atributos agrupados por contador | |
112 | + """ | |
113 | + attr_dict = self.get_attribute(attr) | |
114 | + results = attr_dict.results | |
115 | + | |
116 | + saida = dict() | |
117 | + for elm in results: | |
118 | + if child: | |
119 | + parent = getattr(elm, attr) | |
120 | + attribute = getattr(parent, child) | |
121 | + else: | |
122 | + attribute = getattr(elm, attr) | |
123 | + | |
124 | + if saida.get(attribute): | |
125 | + saida[attribute] = saida.get(attribute) + 1 | |
126 | + else: | |
127 | + saida[attribute] = 1 | |
128 | + | |
129 | + return saida | ... | ... |
... | ... | @@ -0,0 +1,45 @@ |
1 | +<metal:main use-macro="load: master.pt"> | |
2 | + <metal:content fill-slot="conteudo"> | |
3 | +<div class="container"> | |
4 | + | |
5 | + <div class="row"> | |
6 | + <div class="col-md-12"> | |
7 | + <!-- Widget starts --> | |
8 | + <div class="widget"> | |
9 | + <!-- Widget head --> | |
10 | + <div class="widget-head"> | |
11 | + <i class="fa fa-question-circle"></i> Error | |
12 | + </div> | |
13 | + | |
14 | + <div class="widget-content"> | |
15 | + <div class="padd error"> | |
16 | + | |
17 | + <h1>Opps!!! It's 404</h1> | |
18 | + <p>Aliquam consequat, purus vitae auctor ullamcorper, sem velit convallis quam, a pharetra justo nunc et mauris. </p> | |
19 | + <br> | |
20 | + | |
21 | + <div class="input-group input-group-width"> | |
22 | + <input type="text" class="form-control"> | |
23 | + <span class="input-group-btn"> | |
24 | + <button class="btn btn-default" type="button">Search</button> | |
25 | + </span> | |
26 | + </div> | |
27 | + | |
28 | + <br> | |
29 | + <div class="horizontal-links"> | |
30 | + <a href="index.html">Home</a></div> | |
31 | + </div> | |
32 | + <div class="widget-foot"> | |
33 | + <!-- Footer goes here --> | |
34 | + </div> | |
35 | + </div> | |
36 | + </div> | |
37 | + </div> | |
38 | + </div> | |
39 | + </div> | |
40 | + </metal:content> | |
41 | + <metal:content fill-slot="javascript"> | |
42 | + <script type="text/javascript"> | |
43 | + </script> | |
44 | + </metal:content> | |
45 | +</metal:main> | ... | ... |
wscacicneo/test/test_reports.py
... | ... | @@ -3,11 +3,12 @@ |
3 | 3 | __author__ = 'eduardo' |
4 | 4 | |
5 | 5 | import unittest |
6 | +import json | |
6 | 7 | from wscacicneo.model import reports |
7 | 8 | from liblightbase.lbbase.struct import Base |
8 | 9 | from liblightbase.lbutils import conv |
9 | 10 | |
10 | -class TestOrgaoBase(unittest.TestCase): | |
11 | +class TestRelatorio(unittest.TestCase): | |
11 | 12 | """ |
12 | 13 | Testa base do órgão no LB |
13 | 14 | """ |
... | ... | @@ -22,8 +23,34 @@ class TestOrgaoBase(unittest.TestCase): |
22 | 23 | """ |
23 | 24 | Testa busca o documento completo da base |
24 | 25 | """ |
25 | - get_doc = reports.Reports(self.rest_url, self.nm_base) | |
26 | - lbbase = get_doc.get_base_orgao | |
26 | + get_doc = reports.Reports(self.nm_base, self.rest_url) | |
27 | + lbbase = get_doc.get_base_orgao() | |
28 | + self.assertGreater(len(lbbase.results), 0) | |
29 | + | |
30 | + def test_get_attribute(self): | |
31 | + """ | |
32 | + Teste recuperar um atributo específico da base | |
33 | + """ | |
34 | + get_doc = reports.Reports(self.nm_base, self.rest_url) | |
35 | + coleta = get_doc.get_base_orgao() | |
36 | + hd = get_doc.get_attribute('hd') | |
37 | + self.assertGreater(len(hd.results), 0) | |
38 | + | |
39 | + def test_count_attribute(self): | |
40 | + """ | |
41 | + Método que retora um dicionário de atributos agrupados com o valor | |
42 | + de ocorrência de cada um deles | |
43 | + """ | |
44 | + get_doc = reports.Reports(self.nm_base, self.rest_url) | |
45 | + coleta = get_doc.get_base_orgao() | |
46 | + hd = get_doc.get_attribute('hd') | |
47 | + self.assertGreater(len(hd.results), 0) | |
48 | + | |
49 | + hd_count = get_doc.count_attribute('hd', 'tipo_hd') | |
50 | + fd = open('/tmp/teste.json', 'w+') | |
51 | + fd.write(json.dumps(hd_count)) | |
52 | + fd.close() | |
53 | + self.assertGreater(len(hd_count.keys()), 0) | |
27 | 54 | |
28 | 55 | def tearDown(self): |
29 | 56 | """ | ... | ... |
wscacicneo/utils/utils.py
wscacicneo/views.py
... | ... | @@ -191,6 +191,10 @@ def editorgao(request): |
191 | 191 | def configcoleta(request): |
192 | 192 | return {'project': 'WSCacicNeo'} |
193 | 193 | |
194 | +@view_config(route_name='error', renderer='templates/error.pt') | |
195 | +def error(request): | |
196 | + return {'project': 'WSCacicNeo'} | |
197 | + | |
194 | 198 | @view_config(route_name='configfav', renderer='templates/configfav.pt') |
195 | 199 | def configfav(request): |
196 | 200 | return {'project': 'WSCacicNeo'} |
... | ... | @@ -579,6 +583,7 @@ def cadastro_coleta(request): |
579 | 583 | search = orgao_obj.search_list_orgaos() |
580 | 584 | return {'orgao_doc': search.results} |
581 | 585 | |
586 | + | |
582 | 587 | @view_config(route_name='post_coleta_manual') |
583 | 588 | def post_coleta_manual(request): |
584 | 589 | """ |
... | ... | @@ -615,4 +620,4 @@ def post_coleta_manual(request): |
615 | 620 | }, |
616 | 621 | } |
617 | 622 | id_doc = coleta_obj.create_coleta(orgao,coleta_dict) |
618 | - return Response(str(id_doc)) | |
619 | 623 | \ No newline at end of file |
624 | + return Response(str(id_doc)) | ... | ... |