Commit c6edf9f52e30f520022c748fba6680ee1d27f85f
1 parent
dbbaeb5d
Exists in
master
busca de órgãos
Showing
4 changed files
with
29 additions
and
4 deletions
Show diff stats
wscacicneo/__init__.py
... | ... | @@ -40,6 +40,7 @@ def main(global_config, **settings): |
40 | 40 | #Órgão |
41 | 41 | config.add_route('orgao', 'orgao') |
42 | 42 | config.add_route('post_orgao', 'post_orgao') |
43 | + config.add_route('list/orgao', 'list_orgao') | |
43 | 44 | config.add_route('delete_orgao', 'delete_orgao') |
44 | 45 | # |
45 | 46 | config.add_route('list', 'list') | ... | ... |
wscacicneo/model/orgao.py
1 | 1 | #!/usr/env python |
2 | 2 | # -*- coding: utf-8 -*- |
3 | -__author__ = 'eduardo' | |
3 | +__author__ = 'macieski' | |
4 | 4 | |
5 | 5 | from requests.exceptions import HTTPError |
6 | 6 | from wscacicneo import WSCacicNeo |
... | ... | @@ -199,6 +199,7 @@ class Orgao(orgao_base.metaclass): |
199 | 199 | def search_orgao(self, nm_orgao): |
200 | 200 | """ |
201 | 201 | Busca registro completo do órgao pelo nome |
202 | + :return: obj collection com os dados da base | |
202 | 203 | """ |
203 | 204 | search = Search( |
204 | 205 | literal="document->>'nome' = '"+nm_orgao+"'" |
... | ... | @@ -207,6 +208,14 @@ class Orgao(orgao_base.metaclass): |
207 | 208 | |
208 | 209 | return results |
209 | 210 | |
211 | + def search_list_orgaos(self): | |
212 | + """ | |
213 | + Retorna todos os docs da base | |
214 | + """ | |
215 | + results = self.documentrest.get_collection(limit=None) | |
216 | + | |
217 | + return results | |
218 | + | |
210 | 219 | def delete_orgao(self, id): |
211 | 220 | """ |
212 | 221 | Deleta o Órgao apartir do ID | ... | ... |
wscacicneo/test/test_orgao_attributes.py
1 | 1 | #!/usr/env python |
2 | 2 | # -*- coding: utf-8 -*- |
3 | -__author__ = 'eduardo' | |
3 | +__author__ = 'macieski' | |
4 | 4 | |
5 | 5 | import unittest |
6 | 6 | from wscacicneo.model.orgao import Orgao |
7 | 7 | from wscacicneo.model.orgao import OrgaoBase |
8 | -from liblightbase.lbbase.struct import Base | |
9 | -from liblightbase.lbutils import conv | |
10 | 8 | |
11 | 9 | class TestOrgaoBase(unittest.TestCase): |
12 | 10 | """ |
... | ... | @@ -58,6 +56,11 @@ class TestOrgaoBase(unittest.TestCase): |
58 | 56 | |
59 | 57 | assert(delete == 'DELETED') |
60 | 58 | |
59 | + def test_get_attributes(self): | |
60 | + """ | |
61 | + Retorna todos os doc da base | |
62 | + """ | |
63 | + search = Orgao.search_list_orgaos | |
61 | 64 | |
62 | 65 | def tearDown(self): |
63 | 66 | """ | ... | ... |
wscacicneo/views.py
... | ... | @@ -82,6 +82,15 @@ def login(request): |
82 | 82 | def orgao(request): |
83 | 83 | return {'project': 'WSCacicNeo'} |
84 | 84 | |
85 | +@view_config(route_name='list/orgao', renderer='templates/list_orgao.pt') | |
86 | +def list_orgao(request): | |
87 | + """ | |
88 | + Retorna todos os docs da base | |
89 | + """ | |
90 | + search = Orgao.search_list_orgaos | |
91 | + | |
92 | + return Response(search) | |
93 | + | |
85 | 94 | @view_config(route_name='config', renderer='templates/config.pt') |
86 | 95 | def config(request): |
87 | 96 | return {'project': 'WSCacicNeo'} |
... | ... | @@ -196,6 +205,9 @@ def post_orgao(request): |
196 | 205 | |
197 | 206 | @view_config(route_name='delete_orgao') |
198 | 207 | def delete_orgao(request): |
208 | + """ | |
209 | + Deleta doc apartir do id | |
210 | + """ | |
199 | 211 | doc = request.params |
200 | 212 | nm_orgao = doc['nome'] |
201 | 213 | orgao_obj = Orgao( | ... | ... |