Commit 7105e6ef8cfede5cba33a279f22d00fe5921b6d0
1 parent
9676d27b
Exists in
master
Model dos formulários da coleta manual
Showing
4 changed files
with
353 additions
and
9 deletions
Show diff stats
@@ -0,0 +1,306 @@ | @@ -0,0 +1,306 @@ | ||
1 | +#!/usr/env python | ||
2 | +# -*- coding: utf-8 -*- | ||
3 | +__author__ = 'adley' | ||
4 | + | ||
5 | +from requests.exceptions import HTTPError | ||
6 | +from wscacicneo import config | ||
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 ColetaManualBase(): | ||
20 | + """ | ||
21 | + Classe para a base de usuários | ||
22 | + """ | ||
23 | + def __init__(self): | ||
24 | + """ | ||
25 | + Método construtor | ||
26 | + """ | ||
27 | + self.rest_url = config.REST_URL | ||
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 Processadores | ||
36 | + """ | ||
37 | + nome_processador = Field(**dict( | ||
38 | + name='nome_processador', | ||
39 | + description='Nome do Processador', | ||
40 | + alias='nome_processador', | ||
41 | + datatype='Text', | ||
42 | + indices=['Textual'], | ||
43 | + multivalued=False, | ||
44 | + required=True | ||
45 | + )) | ||
46 | + versao_processador = Field(**dict( | ||
47 | + name='versao_processador', | ||
48 | + description='Versão do Processador', | ||
49 | + alias='versao_processaodr', | ||
50 | + datatype='Text', | ||
51 | + indices=['Textual'], | ||
52 | + multivalued=False, | ||
53 | + required=True | ||
54 | + )) | ||
55 | + | ||
56 | + data_instalacao_processador = Field(**dict( | ||
57 | + name='data_instalacao_processador', | ||
58 | + description='Data da Instalação do Processador', | ||
59 | + alias='data_instalacao_processaodr', | ||
60 | + datatype='Text', | ||
61 | + indices=['Textual'], | ||
62 | + multivalued=False, | ||
63 | + required=True | ||
64 | + )) | ||
65 | + | ||
66 | + """ | ||
67 | + LB HD | ||
68 | + """ | ||
69 | + marca_hd = Field(**dict( | ||
70 | + name='marca_hd', | ||
71 | + description='Marca do HD', | ||
72 | + alias='marca_hd', | ||
73 | + datatype='Text', | ||
74 | + indices=['Textual'], | ||
75 | + multivalued=False, | ||
76 | + required=True | ||
77 | + )) | ||
78 | + tamanho_hd = Field(**dict( | ||
79 | + name='tamanho_hd', | ||
80 | + description='Tamanho do HD', | ||
81 | + alias='tamanho_hd', | ||
82 | + datatype='Text', | ||
83 | + indices=['Textual'], | ||
84 | + multivalued=False, | ||
85 | + required=True | ||
86 | + )) | ||
87 | + tipo_hd = Field(**dict( | ||
88 | + name='tipo_hd', | ||
89 | + description='Tipo do HD', | ||
90 | + alias='tipo_hd', | ||
91 | + datatype='Text', | ||
92 | + indices=['Textual'], | ||
93 | + multivalued=False, | ||
94 | + required=True | ||
95 | + )) | ||
96 | + idade_hd = Field(**dict( | ||
97 | + name='idade_hd', | ||
98 | + description='Idade do HD', | ||
99 | + alias='idade_hd', | ||
100 | + datatype='Text', | ||
101 | + indices=['Textual'], | ||
102 | + multivalued=False, | ||
103 | + required=True | ||
104 | + )) | ||
105 | + | ||
106 | + """ | ||
107 | + LB Memória | ||
108 | + """ | ||
109 | + | ||
110 | + interface_memoria = Field(**dict( | ||
111 | + name='interface_memoria', | ||
112 | + description='Interface da Memória', | ||
113 | + alias='interface_memoria', | ||
114 | + datatype='Text', | ||
115 | + indices=['Textual'], | ||
116 | + multivalued=False, | ||
117 | + required=True | ||
118 | + )) | ||
119 | + armazenamento_memoria = Field(**dict( | ||
120 | + name='armazenamento_memoria', | ||
121 | + description='Armazenamento da Memória', | ||
122 | + alias='armazenamento_memoria', | ||
123 | + datatype='Text', | ||
124 | + indices=['Textual'], | ||
125 | + multivalued=False, | ||
126 | + required=True | ||
127 | + )) | ||
128 | + idade_memoria = Field(**dict( | ||
129 | + name='idade_memória', | ||
130 | + description='Idade do Memória', | ||
131 | + alias='idade_memória', | ||
132 | + datatype='Text', | ||
133 | + indices=['Textual'], | ||
134 | + multivalued=False, | ||
135 | + required=True | ||
136 | + )) | ||
137 | + | ||
138 | + """ | ||
139 | + LB Sistema Operacional | ||
140 | + """ | ||
141 | + nome_so = Field(**dict( | ||
142 | + name='nome_so', | ||
143 | + description='Nome do Sistema Operacional', | ||
144 | + alias='nome_so', | ||
145 | + datatype='Text', | ||
146 | + indices=['Textual'], | ||
147 | + multivalued=False, | ||
148 | + required=True | ||
149 | + )) | ||
150 | + versao_so = Field(**dict( | ||
151 | + name='versao_so', | ||
152 | + description='Versão do Sistema Operacional', | ||
153 | + alias='versao_so', | ||
154 | + datatype='Text', | ||
155 | + indices=['Textual'], | ||
156 | + multivalued=False, | ||
157 | + required=True | ||
158 | + )) | ||
159 | + fabricante_so = Field(**dict( | ||
160 | + name='fabricante_so', | ||
161 | + description='Fabricando do Sistema Operacional', | ||
162 | + alias='fabricante_so', | ||
163 | + datatype='Text', | ||
164 | + indices=['Textual'], | ||
165 | + multivalued=False, | ||
166 | + required=True | ||
167 | + )) | ||
168 | + | ||
169 | + """ | ||
170 | + LB Bios | ||
171 | + """ | ||
172 | + patrimonio_bios = Field(**dict( | ||
173 | + name='patrimonio_bios', | ||
174 | + description='Patrimonio da Bios', | ||
175 | + alias='patrimonio_bios', | ||
176 | + datatype='Text', | ||
177 | + indices=['Textual'], | ||
178 | + multivalued=False, | ||
179 | + required=True | ||
180 | + )) | ||
181 | + fabricante_bios = Field(**dict( | ||
182 | + name='fabricante_bios', | ||
183 | + description='Fabricante da Bios', | ||
184 | + alias='fabricante_bios', | ||
185 | + datatype='Text', | ||
186 | + indices=['Textual'], | ||
187 | + multivalued=False, | ||
188 | + required=True | ||
189 | + )) | ||
190 | + | ||
191 | + """ | ||
192 | + GROUP Sistema Operacional | ||
193 | + """ | ||
194 | + sistemaoperacional_content = Content() | ||
195 | + sistemaoperacional_content.append(nome_so) | ||
196 | + sistemaoperacional_content.append(versao_so) | ||
197 | + sistemaoperacional_content.append(fabricante_so) | ||
198 | + | ||
199 | + sistemaoperacional_metadata = GroupMetadata( | ||
200 | + name='sistemaoperacional', | ||
201 | + ) | ||
202 | + | ||
203 | + sistemaoperacional = Group( | ||
204 | + metadata = sistemaoperacional_metadata, | ||
205 | + content = sistemaoperacional_content | ||
206 | + ) | ||
207 | + | ||
208 | + """ | ||
209 | + GROUP Bios | ||
210 | + """ | ||
211 | + bios_content = Content() | ||
212 | + bios_content.append(patrimonio_bios) | ||
213 | + bios_content.append(fabricante_bios) | ||
214 | + | ||
215 | + bios_metadata = GroupMetadata( | ||
216 | + name='bios', | ||
217 | + ) | ||
218 | + | ||
219 | + bios = Group( | ||
220 | + metadata = bios_metadata, | ||
221 | + content = bios_content | ||
222 | + ) | ||
223 | + | ||
224 | + """ | ||
225 | + GROUP Memória | ||
226 | + """ | ||
227 | + memoria_content = Content() | ||
228 | + memoria_content.append(interface_memoria) | ||
229 | + memoria_content.append(armazenamento_memoria) | ||
230 | + memoria_content.append(idade_memoria) | ||
231 | + | ||
232 | + memoria_metadata = GroupMetadata( | ||
233 | + name='memoria', | ||
234 | + ) | ||
235 | + | ||
236 | + memoria = Group( | ||
237 | + metadata = memoria_metadata, | ||
238 | + content = memoria_content | ||
239 | + ) | ||
240 | + | ||
241 | + """ | ||
242 | + GROUP HD | ||
243 | + """ | ||
244 | + hd_content = Content() | ||
245 | + hd_content.append(marca_hd) | ||
246 | + hd_content.append(tamanho_hd) | ||
247 | + hd_content.append(tipo_hd) | ||
248 | + hd_content.append(idade_hd) | ||
249 | + | ||
250 | + hd_metadata = GroupMetadata( | ||
251 | + name='hd', | ||
252 | + ) | ||
253 | + | ||
254 | + hd = Group( | ||
255 | + metadata = hd_metadata, | ||
256 | + content = hd_content | ||
257 | + ) | ||
258 | + | ||
259 | + """ | ||
260 | + GROUP Processador | ||
261 | + """ | ||
262 | + processador_content = Content() | ||
263 | + processador_content.append(nome_processador) | ||
264 | + processador_content.append(versao_processador) | ||
265 | + processador_content.append(data_instalacao_processador) | ||
266 | + | ||
267 | + processador_metadata = GroupMetadata( | ||
268 | + name='processador', | ||
269 | + ) | ||
270 | + | ||
271 | + processador = Group( | ||
272 | + metadata = processador_metadata, | ||
273 | + content = processador_content | ||
274 | + ) | ||
275 | + | ||
276 | + | ||
277 | + return lbbase | ||
278 | + | ||
279 | + @property | ||
280 | + def metaclass(self): | ||
281 | + """ | ||
282 | + Retorna metaclass para essa base | ||
283 | + """ | ||
284 | + return self.lbbase.metaclass() | ||
285 | + | ||
286 | + def create_base(self): | ||
287 | + """ | ||
288 | + Cria base no LB | ||
289 | + """ | ||
290 | + response = self.baserest.create(self.lbbase) | ||
291 | + if response.status_code == 200: | ||
292 | + return self.lbbase | ||
293 | + else: | ||
294 | + return None | ||
295 | + | ||
296 | + def remove_base(self): | ||
297 | + """ | ||
298 | + Remove base from Lightbase | ||
299 | + :param lbbase: LBBase object instance | ||
300 | + :return: True or Error if base was not excluded | ||
301 | + """ | ||
302 | + response = self.baserest.delete(self.lbbase) | ||
303 | + if response.status_code == 200: | ||
304 | + return True | ||
305 | + else: | ||
306 | + raise IOError('Error excluding base from LB') | ||
0 | \ No newline at end of file | 307 | \ No newline at end of file |
wscacicneo/templates/editaruser.pt
@@ -114,7 +114,6 @@ | @@ -114,7 +114,6 @@ | ||
114 | 'permissao': permissao, | 114 | 'permissao': permissao, |
115 | 'senha': senha | 115 | 'senha': senha |
116 | } | 116 | } |
117 | - | ||
118 | if (data.email.indexOf("gov.br") > -1 == false){ | 117 | if (data.email.indexOf("gov.br") > -1 == false){ |
119 | alert('Somente é permitido cadastro de e-mails institucionais'); | 118 | alert('Somente é permitido cadastro de e-mails institucionais'); |
120 | }else{ | 119 | }else{ |
@@ -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 TestColetaManualBase(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
@@ -86,10 +86,6 @@ def cadastro(request): | @@ -86,10 +86,6 @@ def cadastro(request): | ||
86 | def orgao(request): | 86 | def orgao(request): |
87 | return {'project': 'WSCacicNeo'} | 87 | return {'project': 'WSCacicNeo'} |
88 | 88 | ||
89 | -@view_config(route_name='notify_coleta', renderer='templates/notify_coleta.pt') | ||
90 | -def notify_coleta(request): | ||
91 | - return {'project': 'WSCacicNeo'} | ||
92 | - | ||
93 | @view_config(route_name='listorgao', renderer='templates/list_orgao.pt') | 89 | @view_config(route_name='listorgao', renderer='templates/list_orgao.pt') |
94 | def listorgao(request): | 90 | def listorgao(request): |
95 | orgao_obj = Orgao( | 91 | orgao_obj = Orgao( |
@@ -324,7 +320,7 @@ def post_user(request): | @@ -324,7 +320,7 @@ def post_user(request): | ||
324 | 320 | ||
325 | return Response(str(id_doc)) | 321 | return Response(str(id_doc)) |
326 | else: | 322 | else: |
327 | - return {"yololo":"yololo"} | 323 | + return {"emailerrado":"emailerrado"} |
328 | 324 | ||
329 | @view_config(route_name='edituser', renderer='templates/editaruser.pt', permission="edit") | 325 | @view_config(route_name='edituser', renderer='templates/editaruser.pt', permission="edit") |
330 | def edituser(request): | 326 | def edituser(request): |
@@ -384,10 +380,15 @@ def put_user(request): | @@ -384,10 +380,15 @@ def put_user(request): | ||
384 | } | 380 | } |
385 | search = user_obj.search_user(matricula) | 381 | search = user_obj.search_user(matricula) |
386 | id = search.results[0]._metadata.id_doc | 382 | id = search.results[0]._metadata.id_doc |
387 | - doc = json.dumps(user) | ||
388 | - edit = user_obj.edit_user(id, doc) | 383 | + email_user = params['email'] |
384 | + email_is_institucional = Utils.verifica_email_institucional(email_user) | ||
385 | + if(email_is_institucional): | ||
386 | + doc = json.dumps(user) | ||
387 | + edit = user_obj.edit_user(id, doc) | ||
388 | + return Response(edit) | ||
389 | 389 | ||
390 | - return Response(edit) | 390 | + else: |
391 | + return { } | ||
391 | 392 | ||
392 | @view_config(route_name='listuser', renderer='templates/list_user.pt', permission="view") | 393 | @view_config(route_name='listuser', renderer='templates/list_user.pt', permission="view") |
393 | def listuser(request): | 394 | def listuser(request): |