Commit 4dbffd6575200896677c1dee865e7a031809ed27
1 parent
a0bd7422
Exists in
master
Criação da base, tela e teste básico de Usuários(User)
Showing
6 changed files
with
405 additions
and
251 deletions
Show diff stats
wscacicneo/__init__.py
@@ -46,6 +46,12 @@ def main(global_config, **settings): | @@ -46,6 +46,12 @@ def main(global_config, **settings): | ||
46 | config.add_route('listorgao', 'orgao/list') | 46 | config.add_route('listorgao', 'orgao/list') |
47 | config.add_route('delete_orgao', 'delete_orgao') | 47 | config.add_route('delete_orgao', 'delete_orgao') |
48 | # | 48 | # |
49 | + | ||
50 | + #Usuários | ||
51 | + config.add_route('users', 'users') | ||
52 | + config.add_route('post_user', 'post_user') | ||
53 | + # | ||
54 | + | ||
49 | config.add_route('list', 'list') | 55 | config.add_route('list', 'list') |
50 | config.add_route('gestao', 'gestao') | 56 | config.add_route('gestao', 'gestao') |
51 | config.add_route('memoria', 'memoria') | 57 | config.add_route('memoria', 'memoria') |
@@ -54,7 +60,6 @@ def main(global_config, **settings): | @@ -54,7 +60,6 @@ def main(global_config, **settings): | ||
54 | config.add_route('escritorio', 'escritorio') | 60 | config.add_route('escritorio', 'escritorio') |
55 | config.add_route('hd', 'hd') | 61 | config.add_route('hd', 'hd') |
56 | config.add_route('config', 'config') | 62 | config.add_route('config', 'config') |
57 | - config.add_route('users', 'users') | ||
58 | config.add_route('bot', 'bot') | 63 | config.add_route('bot', 'bot') |
59 | config.add_route('login', 'login') | 64 | config.add_route('login', 'login') |
60 | config.add_route('reports', 'reports') | 65 | config.add_route('reports', 'reports') |
@@ -0,0 +1,245 @@ | @@ -0,0 +1,245 @@ | ||
1 | +#!/usr/env python | ||
2 | +# -*- coding: utf-8 -*- | ||
3 | +__author__ = 'adley' | ||
4 | + | ||
5 | +from requests.exceptions import HTTPError | ||
6 | +from wscacicneo import WSCacicNeo | ||
7 | +import logging | ||
8 | +from liblightbase.lbbase.struct import Base, BaseMetadata | ||
9 | +from liblightbase.lbbase.lbstruct.group import * | ||
10 | +from liblightbase.lbbase.lbstruct.field import * | ||
11 | +from liblightbase.lbbase.content import Content | ||
12 | +from liblightbase.lbrest.base import BaseREST | ||
13 | +from liblightbase.lbrest.document import DocumentREST | ||
14 | +from liblightbase.lbutils import conv | ||
15 | +from liblightbase.lbsearch.search import Search, OrderBy | ||
16 | + | ||
17 | +log = logging.getLogger() | ||
18 | + | ||
19 | +class UserBase(WSCacicNeo): | ||
20 | + """ | ||
21 | + Classe para a base de usuários | ||
22 | + """ | ||
23 | + def __init__(self): | ||
24 | + """ | ||
25 | + Método construtor | ||
26 | + """ | ||
27 | + WSCacicNeo.__init__(self) | ||
28 | + self.baserest = BaseREST(rest_url=self.rest_url, response_object=True) | ||
29 | + self.documentrest = DocumentREST(rest_url=self.rest_url, | ||
30 | + base=self.lbbase, response_object=False) | ||
31 | + | ||
32 | + @property | ||
33 | + def lbbase(self): | ||
34 | + """ | ||
35 | + LB Base de Users | ||
36 | + """ | ||
37 | + nome = Field(**dict( | ||
38 | + name='nome', | ||
39 | + description='Nome do Usuário', | ||
40 | + alias='nome', | ||
41 | + datatype='Text', | ||
42 | + indices=['Textual'], | ||
43 | + multivalued=False, | ||
44 | + required=True | ||
45 | + )) | ||
46 | + | ||
47 | + matricula = Field(**dict( | ||
48 | + name='matricula', | ||
49 | + alias='matricula', | ||
50 | + description='Matricula do Usuário', | ||
51 | + datatype='Text', | ||
52 | + indices=['Textual'], | ||
53 | + multivalued=False, | ||
54 | + required=True | ||
55 | + )) | ||
56 | + | ||
57 | + email = Field(**dict( | ||
58 | + name='email', | ||
59 | + alias='email', | ||
60 | + description='E-mail do Usuário', | ||
61 | + datatype='Text', | ||
62 | + indices=['Textual'], | ||
63 | + multivalued=False, | ||
64 | + required=True | ||
65 | + )) | ||
66 | + | ||
67 | + telefone = Field(**dict( | ||
68 | + name='telefone', | ||
69 | + alias='telefone', | ||
70 | + description='Telefone do Usuário', | ||
71 | + datatype='Text', | ||
72 | + indices=['Textual'], | ||
73 | + multivalued=False, | ||
74 | + required=True | ||
75 | + )) | ||
76 | + | ||
77 | + orgao = Field(**dict( | ||
78 | + name='orgao', | ||
79 | + alias='orgao', | ||
80 | + description='Orgão do Usuário', | ||
81 | + datatype='Text', | ||
82 | + indices=['Textual'], | ||
83 | + multivalued=False, | ||
84 | + required=True | ||
85 | + )) | ||
86 | + | ||
87 | + | ||
88 | + cargo = Field(**dict( | ||
89 | + name='cargo', | ||
90 | + alias='cargo', | ||
91 | + description='Cargo do Usuário', | ||
92 | + datatype='Text', | ||
93 | + indices=['Textual'], | ||
94 | + multivalued=False, | ||
95 | + required=True | ||
96 | + )) | ||
97 | + | ||
98 | + setor = Field(**dict( | ||
99 | + name='setor', | ||
100 | + alias='setor', | ||
101 | + description='Setor do Usuário', | ||
102 | + datatype='Text', | ||
103 | + indices=['Textual'], | ||
104 | + multivalued=False, | ||
105 | + required=True | ||
106 | + )) | ||
107 | + | ||
108 | + permissao = Field(**dict( | ||
109 | + name='permissao', | ||
110 | + alias='permissao', | ||
111 | + description='Permissão do Usuário', | ||
112 | + datatype='Text', | ||
113 | + indices=['Textual'], | ||
114 | + multivalued=False, | ||
115 | + required=True | ||
116 | + )) | ||
117 | + | ||
118 | + base_metadata = BaseMetadata( | ||
119 | + name='users', | ||
120 | + ) | ||
121 | + | ||
122 | + content_list = Content() | ||
123 | + content_list.append(nome) | ||
124 | + content_list.append(matricula) | ||
125 | + content_list.append(email) | ||
126 | + content_list.append(telefone) | ||
127 | + content_list.append(orgao) | ||
128 | + content_list.append(cargo) | ||
129 | + content_list.append(setor) | ||
130 | + content_list.append(permissao) | ||
131 | + | ||
132 | + lbbase = Base( | ||
133 | + metadata=base_metadata, | ||
134 | + content=content_list | ||
135 | + ) | ||
136 | + | ||
137 | + return lbbase | ||
138 | + | ||
139 | + @property | ||
140 | + def metaclass(self): | ||
141 | + """ | ||
142 | + Retorna metaclass para essa base | ||
143 | + """ | ||
144 | + return self.lbbase.metaclass() | ||
145 | + | ||
146 | + def create_base(self): | ||
147 | + """ | ||
148 | + Cria base no LB | ||
149 | + """ | ||
150 | + response = self.baserest.create(self.lbbase) | ||
151 | + #print(response.status_code) | ||
152 | + if response.status_code == 200: | ||
153 | + return self.lbbase | ||
154 | + else: | ||
155 | + return None | ||
156 | + | ||
157 | + def remove_base(self): | ||
158 | + """ | ||
159 | + Remove base from Lightbase | ||
160 | + :param lbbase: LBBase object instance | ||
161 | + :return: True or Error if base was not excluded | ||
162 | + """ | ||
163 | + response = self.baserest.delete(self.lbbase) | ||
164 | + if response.status_code == 200: | ||
165 | + return True | ||
166 | + else: | ||
167 | + raise IOError('Error excluding base from LB') | ||
168 | + | ||
169 | +user_base = UserBase() | ||
170 | + | ||
171 | +class User(user_base.metaclass): | ||
172 | + """ | ||
173 | + Classe genérica de usuários | ||
174 | + """ | ||
175 | + def __init__(self, **args): | ||
176 | + super(User, self).__init__(**args) | ||
177 | + self.documentrest = user_base.documentrest | ||
178 | + | ||
179 | + def user_to_dict(self): | ||
180 | + """ | ||
181 | + Convert status object to Python dict | ||
182 | + :return: | ||
183 | + """ | ||
184 | + | ||
185 | + return conv.document2dict(user_base.lbbase, self) | ||
186 | + | ||
187 | + def user_to_json(self): | ||
188 | + """ | ||
189 | + Convert object to json | ||
190 | + :return: | ||
191 | + """ | ||
192 | + | ||
193 | + return conv.document2json(user_base.lbbase, self) | ||
194 | + | ||
195 | + def create_user(self): | ||
196 | + """ | ||
197 | + Insert document on base | ||
198 | + | ||
199 | + :return: Document creation ID | ||
200 | + """ | ||
201 | + | ||
202 | + document = self.user_to_json() | ||
203 | + try: | ||
204 | + result = user_base.documentrest.create(document) | ||
205 | + except HTTPError as err: | ||
206 | + log.error(err.strerror) | ||
207 | + return None | ||
208 | + | ||
209 | + return result | ||
210 | + | ||
211 | + def search_user(self, matricula_user): | ||
212 | + """ | ||
213 | + Busca registro completo do usuário pela matricula | ||
214 | + :return: obj collection com os dados da base | ||
215 | + """ | ||
216 | + search = Search( | ||
217 | + literal="document->>'matricula' = '"+matricula_user+"'" | ||
218 | + ) | ||
219 | + results = self.documentrest.get_collection(search_obj=search) | ||
220 | + | ||
221 | + return results | ||
222 | + | ||
223 | + def search_list_users(self): | ||
224 | + """ | ||
225 | + Retorna todos os docs da base | ||
226 | + """ | ||
227 | + results = self.documentrest.get_collection(limit=None) | ||
228 | + | ||
229 | + return results | ||
230 | + | ||
231 | + def edit_user(self, id, doc): | ||
232 | + """ | ||
233 | + altera um doc ou path do doc | ||
234 | + """ | ||
235 | + results = self.documentrest.update(id, doc) | ||
236 | + | ||
237 | + return results | ||
238 | + | ||
239 | + def delete_user(self, id): | ||
240 | + """ | ||
241 | + Deleta o Órgao apartir do ID | ||
242 | + """ | ||
243 | + results = user_base.documentrest.delete(id) | ||
244 | + | ||
245 | + return results | ||
0 | \ No newline at end of file | 246 | \ No newline at end of file |
wscacicneo/model/users.py
@@ -1,245 +0,0 @@ | @@ -1,245 +0,0 @@ | ||
1 | -#!/usr/env python | ||
2 | -# -*- coding: utf-8 -*- | ||
3 | -__author__ = 'adley' | ||
4 | - | ||
5 | -from requests.exceptions import HTTPError | ||
6 | -from wscacicneo import WSCacicNeo | ||
7 | -import logging | ||
8 | -from liblightbase.lbbase.struct import Base, BaseMetadata | ||
9 | -from liblightbase.lbbase.lbstruct.group import * | ||
10 | -from liblightbase.lbbase.lbstruct.field import * | ||
11 | -from liblightbase.lbbase.content import Content | ||
12 | -from liblightbase.lbrest.base import BaseREST | ||
13 | -from liblightbase.lbrest.document import DocumentREST | ||
14 | -from liblightbase.lbutils import conv | ||
15 | -from liblightbase.lbsearch.search import Search, OrderBy | ||
16 | - | ||
17 | -log = logging.getLogger() | ||
18 | - | ||
19 | -class UserBase(WSCacicNeo): | ||
20 | - """ | ||
21 | - Classe para a base de usuários | ||
22 | - """ | ||
23 | - def __init__(self): | ||
24 | - """ | ||
25 | - Método construtor | ||
26 | - """ | ||
27 | - WSCacicNeo.__init__(self) | ||
28 | - self.baserest = BaseREST(rest_url=self.rest_url, response_object=True) | ||
29 | - self.documentrest = DocumentREST(rest_url=self.rest_url, | ||
30 | - base=self.lbbase, response_object=False) | ||
31 | - | ||
32 | - @property | ||
33 | - def lbbase(self): | ||
34 | - """ | ||
35 | - LB Base do Users | ||
36 | - """ | ||
37 | - nome = Field(**dict( | ||
38 | - name='nome', | ||
39 | - description='Nome do Usuário', | ||
40 | - alias='nome', | ||
41 | - datatype='Text', | ||
42 | - indices=['Textual'], | ||
43 | - multivalued=False, | ||
44 | - required=True | ||
45 | - )) | ||
46 | - | ||
47 | - matricula = Field(**dict( | ||
48 | - name='matricula', | ||
49 | - alias='matricula', | ||
50 | - description='Matricula do Usuário', | ||
51 | - datatype='Text', | ||
52 | - indices=['Textual'], | ||
53 | - multivalued=False, | ||
54 | - required=True | ||
55 | - )) | ||
56 | - | ||
57 | - email = Field(**dict( | ||
58 | - name='email', | ||
59 | - alias='email', | ||
60 | - description='E-mail do Usuário', | ||
61 | - datatype='Text', | ||
62 | - indices=['Textual'], | ||
63 | - multivalued=False, | ||
64 | - required=True | ||
65 | - )) | ||
66 | - | ||
67 | - telefone = Field(**dict( | ||
68 | - name='telefone', | ||
69 | - alias='telefone', | ||
70 | - description='Telefone do Usuário', | ||
71 | - datatype='Text', | ||
72 | - indices=['Textual'], | ||
73 | - multivalued=False, | ||
74 | - required=True | ||
75 | - )) | ||
76 | - | ||
77 | - orgao = Field(**dict( | ||
78 | - name='orgao', | ||
79 | - alias='orgao', | ||
80 | - description='Orgão do Usuário', | ||
81 | - datatype='Text', | ||
82 | - indices=['Textual'], | ||
83 | - multivalued=False, | ||
84 | - required=True | ||
85 | - )) | ||
86 | - | ||
87 | - | ||
88 | - cargo = Field(**dict( | ||
89 | - name='cargo', | ||
90 | - alias='cargo', | ||
91 | - description='Cargo do Usuário', | ||
92 | - datatype='Text', | ||
93 | - indices=['Textual'], | ||
94 | - multivalued=False, | ||
95 | - required=True | ||
96 | - )) | ||
97 | - | ||
98 | - setor = Field(**dict( | ||
99 | - name='setor', | ||
100 | - alias='setor', | ||
101 | - description='Setor do Usuário', | ||
102 | - datatype='Text', | ||
103 | - indices=['Textual'], | ||
104 | - multivalued=False, | ||
105 | - required=True | ||
106 | - )) | ||
107 | - | ||
108 | - permissao = Field(**dict( | ||
109 | - name='permissao', | ||
110 | - alias='permissao', | ||
111 | - description='Permissão do Usuário', | ||
112 | - datatype='Text', | ||
113 | - indices=['Textual'], | ||
114 | - multivalued=False, | ||
115 | - required=True | ||
116 | - )) | ||
117 | - | ||
118 | - base_metadata = BaseMetadata( | ||
119 | - name='users', | ||
120 | - ) | ||
121 | - | ||
122 | - content_list = Content() | ||
123 | - content_list.append(nome) | ||
124 | - content_list.append(matricula) | ||
125 | - content_list.append(email) | ||
126 | - content_list.append(telefone) | ||
127 | - content_list.append(orgao) | ||
128 | - content_list.append(cargo) | ||
129 | - content_list.append(setor) | ||
130 | - content_list.append(permissao) | ||
131 | - | ||
132 | - lbbase = Base( | ||
133 | - metadata=base_metadata, | ||
134 | - content=content_list | ||
135 | - ) | ||
136 | - | ||
137 | - return lbbase | ||
138 | - | ||
139 | - @property | ||
140 | - def metaclass(self): | ||
141 | - """ | ||
142 | - Retorna metaclass para essa base | ||
143 | - """ | ||
144 | - return self.lbbase.metaclass() | ||
145 | - | ||
146 | - def create_base(self): | ||
147 | - """ | ||
148 | - Cria base no LB | ||
149 | - """ | ||
150 | - response = self.baserest.create(self.lbbase) | ||
151 | - #print(response.status_code) | ||
152 | - if response.status_code == 200: | ||
153 | - return self.lbbase | ||
154 | - else: | ||
155 | - return None | ||
156 | - | ||
157 | - def remove_base(self): | ||
158 | - """ | ||
159 | - Remove base from Lightbase | ||
160 | - :param lbbase: LBBase object instance | ||
161 | - :return: True or Error if base was not excluded | ||
162 | - """ | ||
163 | - response = self.baserest.delete(self.lbbase) | ||
164 | - if response.status_code == 200: | ||
165 | - return True | ||
166 | - else: | ||
167 | - raise IOError('Error excluding base from LB') | ||
168 | - | ||
169 | -user_base = UserBase() | ||
170 | - | ||
171 | -class User(user.base.metaclass): | ||
172 | - """ | ||
173 | - Classe genérica de usuários | ||
174 | - """ | ||
175 | - def __init__(self, **args): | ||
176 | - super(Orgao, self).__init__(**args) | ||
177 | - self.documentrest = user_base.documentrest | ||
178 | - | ||
179 | - def user_to_dict(self): | ||
180 | - """ | ||
181 | - Convert status object to Python dict | ||
182 | - :return: | ||
183 | - """ | ||
184 | - | ||
185 | - return conv.document2dict(user_base.lbbase, self) | ||
186 | - | ||
187 | - def user_to_json(self): | ||
188 | - """ | ||
189 | - Convert object to json | ||
190 | - :return: | ||
191 | - """ | ||
192 | - | ||
193 | - return conv.document2json(user_base.lbbase, self) | ||
194 | - | ||
195 | - def create_user(self): | ||
196 | - """ | ||
197 | - Insert document on base | ||
198 | - | ||
199 | - :return: Document creation ID | ||
200 | - """ | ||
201 | - | ||
202 | - document = self.orgao_to_json() | ||
203 | - try: | ||
204 | - result = user_base.documentrest.create(document) | ||
205 | - except HTTPError as err: | ||
206 | - log.error(err.strerror) | ||
207 | - return None | ||
208 | - | ||
209 | - return result | ||
210 | - | ||
211 | - def search_user(self, matricula_user): | ||
212 | - """ | ||
213 | - Busca registro completo do usuário pela matricula | ||
214 | - :return: obj collection com os dados da base | ||
215 | - """ | ||
216 | - search = Search( | ||
217 | - literal="document->>'matricula' = '"+matricula_user+"'" | ||
218 | - ) | ||
219 | - results = self.documentrest.get_collection(search_obj=search) | ||
220 | - | ||
221 | - return results | ||
222 | - | ||
223 | - def search_list_users(self): | ||
224 | - """ | ||
225 | - Retorna todos os docs da base | ||
226 | - """ | ||
227 | - results = self.documentrest.get_collection(limit=None) | ||
228 | - | ||
229 | - return results | ||
230 | - | ||
231 | - def edit_user(self, id, doc): | ||
232 | - """ | ||
233 | - altera um doc ou path do doc | ||
234 | - """ | ||
235 | - results = self.documentrest.update(id, doc) | ||
236 | - | ||
237 | - return results | ||
238 | - | ||
239 | - def delete_user(self, id): | ||
240 | - """ | ||
241 | - Deleta o Órgao apartir do ID | ||
242 | - """ | ||
243 | - results = user_base.documentrest.delete(id) | ||
244 | - | ||
245 | - return results | ||
246 | \ No newline at end of file | 0 | \ No newline at end of file |
wscacicneo/templates/users.pt
1 | <metal:main use-macro="load: master.pt"> | 1 | <metal:main use-macro="load: master.pt"> |
2 | - <!-- Insere JavaScript --> | ||
3 | - <script metal:fill-slot="javascript" type="text/javascript" src="static/users.js"></script> | ||
4 | - | ||
5 | - <div metal:fill-slot="conteudo" id="widgets"></div> | 2 | + <metal:content fill-slot="conteudo"> |
3 | + <div class="padd"> | ||
4 | + <br /> | ||
5 | + <!-- Form starts. --> | ||
6 | + <form class="form-horizontal" role="form"> | ||
7 | + <div class="form-group"> | ||
8 | + <label class="col-lg-2 control-label">Nome</label> | ||
9 | + <div class="col-lg-5"> | ||
10 | + <input type="text" id="nome" class="form-control" placeholder="Nome do Usuário"> | ||
11 | + </div> | ||
12 | + </div> | ||
13 | + <div class="form-group"> | ||
14 | + <label class="col-lg-2 control-label">Matricula</label> | ||
15 | + <div class="col-lg-5"> | ||
16 | + <input type="text" id="matricula" class="form-control" placeholder="Matricula"> | ||
17 | + </div> | ||
18 | + </div> | ||
19 | + <div class="form-group"> | ||
20 | + <label class="col-lg-2 control-label">E-Mail</label> | ||
21 | + <div class="col-lg-5"> | ||
22 | + <input type="text" id="email" class="form-control" placeholder="E-Mail"> | ||
23 | + </div> | ||
24 | + </div> | ||
25 | + <div class="form-group"> | ||
26 | + <label class="col-lg-2 control-label">Telefone</label> | ||
27 | + <div class="col-lg-5"> | ||
28 | + <input type="text" id="telefone" class="form-control" placeholder="E-Mail"> | ||
29 | + </div> | ||
30 | + </div> | ||
31 | + <div class="form-group"> | ||
32 | + <label class="col-lg-2 control-label">Orgão</label> | ||
33 | + <div class="col-lg-5"> | ||
34 | + <input type="text" id="orgao" class="form-control" placeholder="Orgão"> | ||
35 | + </div> | ||
36 | + </div> | ||
37 | + <div class="form-group"> | ||
38 | + <label class="col-lg-2 control-label">Cargo</label> | ||
39 | + <div class="col-lg-5"> | ||
40 | + <input type="text" id="cargo" class="form-control" placeholder="Cargo"> | ||
41 | + </div> | ||
42 | + </div> | ||
43 | + <div class="form-group"> | ||
44 | + <label class="col-lg-2 control-label">Setor</label> | ||
45 | + <div class="col-lg-5"> | ||
46 | + <input type="text" id="setor" class="form-control" placeholder="Setor"> | ||
47 | + </div> | ||
48 | + </div> | ||
49 | + <div class="form-group"> | ||
50 | + <label class="col-lg-2 control-label">Permissão</label> | ||
51 | + <div class="col-lg-2"> | ||
52 | + <select id="permissao" class="form-control"> | ||
53 | + <option selected disabled>Permissões</option> | ||
54 | + <option>Administrador</option> | ||
55 | + <option>Gestor</option> | ||
56 | + </select> | ||
57 | + </div> | ||
58 | + </div> | ||
59 | + <div class="form-group"> | ||
60 | + <div class="col-lg-offset-2 col-lg-6"> | ||
61 | + <button type="button" id="enviar" class="btn btn-sm" style="margin-left: 315px;" >Enviar</button> | ||
62 | + <button type="button" id="limpar" class="btn btn-sm">Limpar</button> | ||
63 | + </div> | ||
64 | + </div> | ||
65 | + </form> | ||
66 | + </div> | ||
67 | + </metal:content> | ||
68 | + <metal:content fill-slot="javascript"> | ||
69 | + <script type="text/javascript"> | ||
70 | + $('#enviar').click(function(){ | ||
71 | + var data = { | ||
72 | + 'nome' : $('#nome').val(), | ||
73 | + 'matricula' : $('#matricula').val(), | ||
74 | + 'email' : $('#email').val(), | ||
75 | + 'telefone' : $('#telefone').val(), | ||
76 | + 'orgao' : $('#orgao').val(), | ||
77 | + 'cargo' : $('#cargo').val(), | ||
78 | + 'setor' : $('#setor').val(), | ||
79 | + 'permissao' : $('#permissao').val(), | ||
80 | + } | ||
81 | + $.ajax({ | ||
82 | + type: "POST", | ||
83 | + url: "post_user", | ||
84 | + data: data, | ||
85 | + success: function(){ alert('sucesso') }, | ||
86 | + error: function(){ alert('erro') }, | ||
87 | + }); | ||
88 | + }); | ||
89 | + </script> | ||
90 | + </metal:content> | ||
6 | </metal:main> | 91 | </metal:main> |
7 | - |
@@ -0,0 +1,38 @@ | @@ -0,0 +1,38 @@ | ||
1 | +#!/usr/env python | ||
2 | +# -*- coding: utf-8 -*- | ||
3 | +__author__ = 'adley' | ||
4 | + | ||
5 | +import unittest | ||
6 | +from wscacicneo.model import user | ||
7 | +from liblightbase.lbbase.struct import Base | ||
8 | +from liblightbase.lbutils import conv | ||
9 | + | ||
10 | +class TestUserBase(unittest.TestCase): | ||
11 | + """ | ||
12 | + Testa base do órgão no LB | ||
13 | + """ | ||
14 | + def setUp(self): | ||
15 | + """ | ||
16 | + Carregando atributos genéricos do teste | ||
17 | + """ | ||
18 | + pass | ||
19 | + | ||
20 | + def test_create_base(self): | ||
21 | + """ | ||
22 | + Testa criação da base no LB | ||
23 | + """ | ||
24 | + user_base = user.UserBase() | ||
25 | + lbbase = user_base.lbbase | ||
26 | + self.assertIsInstance(lbbase, Base) | ||
27 | + | ||
28 | + retorno = user_base.create_base() | ||
29 | + self.assertIsInstance(retorno, Base) | ||
30 | + | ||
31 | + #retorno = user_base.remove_base() | ||
32 | + #self.assertTrue(retorno) | ||
33 | + | ||
34 | + def tearDown(self): | ||
35 | + """ | ||
36 | + Apaga dados do teste | ||
37 | + """ | ||
38 | + pass |
wscacicneo/views.py
@@ -11,6 +11,8 @@ from .models import ( | @@ -11,6 +11,8 @@ from .models import ( | ||
11 | ) | 11 | ) |
12 | from wscacicneo.model.orgao import Orgao | 12 | from wscacicneo.model.orgao import Orgao |
13 | from wscacicneo.model.orgao import OrgaoBase | 13 | from wscacicneo.model.orgao import OrgaoBase |
14 | +from wscacicneo.model.user import User | ||
15 | +from wscacicneo.model.user import UserBase | ||
14 | from liblightbase.lbbase.struct import Base | 16 | from liblightbase.lbbase.struct import Base |
15 | from liblightbase.lbutils import conv | 17 | from liblightbase.lbutils import conv |
16 | from liblightbase.lbrest.document import DocumentREST | 18 | from liblightbase.lbrest.document import DocumentREST |
@@ -275,3 +277,28 @@ def delete_orgao(request): | @@ -275,3 +277,28 @@ def delete_orgao(request): | ||
275 | 277 | ||
276 | return Response(str(delete)) | 278 | return Response(str(delete)) |
277 | 279 | ||
280 | +#URL Users | ||
281 | + | ||
282 | +@view_config(route_name='post_user') | ||
283 | +def post_user(request): | ||
284 | + """ | ||
285 | + Post doc users | ||
286 | + """ | ||
287 | + rest_url = REST_URL | ||
288 | + userbase = UserBase().lbbase | ||
289 | + doc = request.params | ||
290 | + user_obj = User( | ||
291 | + nome = doc['nome'], | ||
292 | + matricula = doc['matricula'], | ||
293 | + email = doc['email'], | ||
294 | + orgao = doc['orgao'], | ||
295 | + telefone = doc['telefone'], | ||
296 | + cargo = doc['cargo'], | ||
297 | + setor = doc['setor'], | ||
298 | + permissao = doc['permissao'] | ||
299 | + ) | ||
300 | + | ||
301 | + id_doc = user_obj.create_user() | ||
302 | + print(id_doc) | ||
303 | + | ||
304 | + return Response(str(id_doc)) | ||
278 | \ No newline at end of file | 305 | \ No newline at end of file |