Commit 9371f5c645e9b1845d2848c9ffaa7c800cee79c7

Authored by Eduardo Santos
Committed by Eduardo Santos
1 parent 2a197bf4
Exists in master

Cria estruturas de bases no LB

.gitignore
... ... @@ -52,3 +52,6 @@ coverage.xml
52 52 # Sphinx documentation
53 53 docs/_build/
54 54  
  55 +# Pycharm
  56 +.idea/
  57 +
... ...
development.ini
... ... @@ -45,3 +45,6 @@ formatter = generic
45 45  
46 46 [formatter_generic]
47 47 format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
  48 +
  49 +[lbgenerator]
  50 +rest_url = http://localhost/api
48 51 \ No newline at end of file
... ...
setup.py
... ... @@ -15,11 +15,12 @@ requires = [
15 15 'zope.sqlalchemy',
16 16 'waitress',
17 17 'requests',
18   - 'pyramid_chameleon'
  18 + 'pyramid_chameleon',
  19 + 'liblightbase'
19 20 ]
20 21  
21 22 setup(name='WSCacicNeo',
22   - version='0.0',
  23 + version='0.1',
23 24 description='WSCacicNeo',
24 25 long_description=README + '\n\n' + CHANGES,
25 26 classifiers=[
... ...
wscacicneo/__init__.py
  1 +#!/usr/env python
  2 +# -*- coding: utf-8 -*-
  3 +import os
  4 +import configparser
1 5 from pyramid.config import Configurator
2 6  
3 7  
  8 +config = configparser.ConfigParser()
  9 +here = os.path.abspath(os.path.dirname(__file__))
  10 +config_file = os.path.join(here, '../development.ini')
  11 +config.read(config_file)
  12 +
  13 +
  14 +class WSCacicNeo(object):
  15 + """
  16 + Classe genérica com os parâmetros de configuração
  17 + """
  18 + def __init__(self):
  19 + """
  20 + Método construtor
  21 + """
  22 + self.rest_url = config.get('lbgenerator', 'rest_url')
  23 +
4 24  
5 25 def main(global_config, **settings):
6 26 """ This function returns a Pyramid WSGI application.
... ... @@ -16,10 +36,12 @@ def main(global_config, **settings):
16 36 config.add_route('admin', 'admin')
17 37 config.add_route('proc', 'proc')
18 38 config.add_route('sistema', 'sistema')
  39 + #Órgão
19 40 config.add_route('orgao', 'orgao')
  41 + config.add_route('post_orgao', 'post_orgao')
  42 + #
20 43 config.add_route('list', 'list')
21 44 config.add_route('gestao', 'gestao')
22   - config.add_route('bot', 'bot')
23 45 config.add_route('memoria', 'memoria')
24 46 config.add_route('basico', 'basico')
25 47 config.add_route('rede', 'rede')
... ... @@ -27,6 +49,7 @@ def main(global_config, **settings):
27 49 config.add_route('hd', 'hd')
28 50 config.add_route('config', 'config')
29 51 config.add_route('users', 'users')
  52 + config.add_route('bot', 'bot')
30 53 config.add_route('login', 'login')
31 54 config.add_route('reports', 'reports')
32 55 config.add_route('computador', 'computador')
... ... @@ -49,4 +72,3 @@ def main(global_config, **settings):
49 72 config.scan()
50 73 return config.make_wsgi_app()
51 74  
52   -
... ...
wscacicneo/model/orgao.py 0 → 100644
... ... @@ -0,0 +1,164 @@
  1 +#!/usr/env python
  2 +# -*- coding: utf-8 -*-
  3 +__author__ = 'eduardo'
  4 +
  5 +from wscacicneo import WSCacicNeo
  6 +from liblightbase.lbbase.struct import Base, BaseMetadata
  7 +from liblightbase.lbbase.lbstruct.group import *
  8 +from liblightbase.lbbase.lbstruct.field import *
  9 +from liblightbase.lbbase.content import Content
  10 +from liblightbase.lbrest.base import BaseREST
  11 +
  12 +class OrgaoBase(WSCacicNeo):
  13 + """
  14 + Classe para a base de órgãos
  15 + """
  16 + def __init__(self):
  17 + """
  18 + Método construtor
  19 + """
  20 + WSCacicNeo.__init__(self)
  21 + self.baserest = BaseREST(rest_url=self.rest_url, response_object=True)
  22 +
  23 + @property
  24 + def lbbase(self):
  25 + """
  26 + LB Base do órgão
  27 + """
  28 + nome = Field(**dict(
  29 + name='nome',
  30 + description='Nome do órgão',
  31 + alias='nome',
  32 + datatype='Text',
  33 + indices=['Textual'],
  34 + multivalued=False,
  35 + required=True
  36 + ))
  37 +
  38 + sigla = Field(**dict(
  39 + name='sigla',
  40 + alias='sigla',
  41 + description='Sigla do órgão',
  42 + datatype='Text',
  43 + indices=['Textual'],
  44 + multivalued=False,
  45 + required=True
  46 + ))
  47 +
  48 + cargo = Field(**dict(
  49 + name='cargo',
  50 + alias='cargo',
  51 + description='Cargo do gestor',
  52 + datatype='Text',
  53 + indices=['Textual'],
  54 + multivalued=False,
  55 + required=True
  56 + ))
  57 +
  58 + telefone = Field(**dict(
  59 + name='telefone',
  60 + alias='telefone',
  61 + description='Telefone do órgão',
  62 + datatype='Text',
  63 + indices=['Textual'],
  64 + multivalued=False,
  65 + required=True
  66 + ))
  67 +
  68 + email = Field(**dict(
  69 + name='email',
  70 + alias='email',
  71 + description='E-mail do órgão',
  72 + datatype='Text',
  73 + indices=['Textual'],
  74 + multivalued=False,
  75 + required=True
  76 + ))
  77 +
  78 + endereco = Field(**dict(
  79 + name='endereco',
  80 + alias='endereco',
  81 + description='Endereço do orgao',
  82 + datatype='Text',
  83 + indices=['Textual'],
  84 + multivalued=False,
  85 + required=True
  86 + ))
  87 +
  88 + coleta = Field(**dict(
  89 + name='coleta',
  90 + alias='coleta',
  91 + description='Intervalo de coleta',
  92 + datatype='Text',
  93 + indices=['Textual'],
  94 + multivalued=False,
  95 + required=True
  96 + ))
  97 +
  98 + base_metadata = BaseMetadata(**dict(
  99 + name='orgaos',
  100 + description='Órgãos da administração pública',
  101 + password='123456',
  102 + idx_exp=False,
  103 + idx_exp_url='index_url',
  104 + idx_exp_time=300,
  105 + file_ext=True,
  106 + file_ext_time=300,
  107 + color='#FFFFFF'
  108 + ))
  109 +
  110 + content_list = Content()
  111 + content_list.append(nome)
  112 + content_list.append(sigla)
  113 + content_list.append(cargo)
  114 + content_list.append(telefone)
  115 + content_list.append(email)
  116 + content_list.append(endereco)
  117 + content_list.append(coleta)
  118 +
  119 + lbbase = Base(
  120 + metadata=base_metadata,
  121 + content=content_list
  122 + )
  123 +
  124 + return lbbase
  125 +
  126 + @property
  127 + def metaclass(self):
  128 + """
  129 + Retorna metaclass para essa base
  130 + """
  131 + return self.lbbase.metaclass()
  132 +
  133 + def create_base(self):
  134 + """
  135 + Cria base no LB
  136 + """
  137 + response = self.baserest.create(self.lbbase)
  138 + #print(response.status_code)
  139 + if response.status_code == 200:
  140 + return self.lbbase
  141 + else:
  142 + return None
  143 +
  144 + def remove_base(self):
  145 + """
  146 + Remove base from Lightbase
  147 + :param lbbase: LBBase object instance
  148 + :return: True or Error if base was not excluded
  149 + """
  150 + response = self.baserest.delete(self.lbbase)
  151 + if response.status_code == 200:
  152 + return True
  153 + else:
  154 + raise IOError('Error excluding base from LB')
  155 +
  156 +orgao = OrgaoBase().metaclass
  157 +
  158 +
  159 +class Orgao(orgao):
  160 + """
  161 + Classe genérica de órgãos
  162 + """
  163 + def __init__(self, **args):
  164 + super(Orgao, self).__init__(**args)
0 165 \ No newline at end of file
... ...
wscacicneo/static/orgao.js
... ... @@ -86,14 +86,11 @@ painel = Ext.create('Ext.panel.Panel', {
86 86 });
87 87  
88 88 Ext.onReady(function(){
89   -
90   -
91 89 Ext.create('Ext.Container', {
92 90 padding: '15px',
93 91 items: [painel],
94 92 renderTo: 'widgets'
95 93 });
96   -
97 94 });
98 95  
99 96  
... ... @@ -116,7 +113,8 @@ $('#button-1017-btnIconEl').click(function(){
116 113 }
117 114 $.ajax({
118 115 type: "POST",
119   - url: 'http://10.1.0.121/wscacicneo/orgao',
  116 + url: 'post_orgao',
  117 + data : reg,
120 118 cache: false,
121 119 success: function(jqXHR, textStatus, errorThrown){
122 120 alert('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
... ...
wscacicneo/test/test_orgao_base.py 0 → 100644
... ... @@ -0,0 +1,81 @@
  1 +#!/usr/env python
  2 +# -*- coding: utf-8 -*-
  3 +__author__ = 'eduardo'
  4 +
  5 +import unittest
  6 +from wscacicneo.model import orgao
  7 +from liblightbase.lbbase.struct import Base
  8 +from liblightbase.lbutils import conv
  9 +
  10 +class TestOrgaoBase(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_base(self):
  21 + """
  22 + Testa criação do objeto base no LB
  23 + """
  24 + orgao_base = orgao.OrgaoBase()
  25 + lbbase = orgao_base.lbbase
  26 + self.assertIsInstance(lbbase, Base)
  27 +
  28 + fd = open('/tmp/orgao_base.json', 'w+')
  29 + fd.write(lbbase.json)
  30 + fd.close()
  31 + self.assertIsInstance(lbbase, Base)
  32 + j = lbbase.json
  33 + b = conv.json2base(j)
  34 + self.assertIsInstance(b, Base)
  35 +
  36 + def test_create_base(self):
  37 + """
  38 + Testa criação da base no LB
  39 + """
  40 + orgao_base = orgao.OrgaoBase()
  41 + lbbase = orgao_base.lbbase
  42 + self.assertIsInstance(lbbase, Base)
  43 +
  44 + retorno = orgao_base.create_base()
  45 + self.assertIsInstance(retorno, Base)
  46 +
  47 + retorno = orgao_base.remove_base()
  48 + self.assertTrue(retorno)
  49 +
  50 + def test_orgao_metaclass(self):
  51 + """
  52 + testa atribuição de metaclass
  53 + """
  54 + orgao_base = orgao.OrgaoBase()
  55 + lbbase = orgao_base.lbbase
  56 + self.assertIsInstance(lbbase, Base)
  57 +
  58 + self.assertIsNotNone(orgao_base.metaclass)
  59 +
  60 + def test_orgao_attributes(self):
  61 + """
  62 + Testa verificação de atributos
  63 + """
  64 + orgao_obj = orgao.Orgao(
  65 + nome='Ministério do Planejamento',
  66 + cargo='Gestor',
  67 + coleta='4h',
  68 + sigla='MPOG',
  69 + endereco='Esplanada bloco C',
  70 + email='admin@planemaneto.gov.br',
  71 + telefone='(61) 2025-4117'
  72 + )
  73 + self.assertIsInstance(orgao_obj, orgao.Orgao)
  74 + self.assertEqual(orgao_obj.nome, 'Ministério do Planejamento')
  75 + self.assertEqual(orgao_obj.cargo, 'Gestor')
  76 +
  77 + def tearDown(self):
  78 + """
  79 + Apaga dados do teste
  80 + """
  81 + pass
0 82 \ No newline at end of file
... ...
wscacicneo/views.py
1 1 import requests
  2 +import json
2 3 from pyramid.response import Response
3 4 from pyramid.httpexceptions import HTTPFound
4 5 from pyramid.view import view_config
... ... @@ -16,11 +17,7 @@ Session = sessionmaker(bind=engine)
16 17 session = Session()
17 18 @view_config(route_name='master', renderer='templates/master.pt')
18 19 def master(request):
19   - url = REST_URL + '/orgao_sg/doc'
20   - json_reg = request.params
21   - data = {'value': json_reg}
22   - response = requests.post(url, data=data)
23   - return response.text
  20 + return {'project': 'WSCacicNeo'}
24 21  
25 22 @view_config(route_name='home', renderer='templates/home.pt')
26 23 def home(request):
... ... @@ -192,3 +189,16 @@ def my_view8(request):
192 189 #print (dc)
193 190  
194 191 return {'project':'WSCacicNeo', 'data': data}
  192 +
  193 +#URL POST
  194 +
  195 +@view_config(route_name='post_orgao')
  196 +def post_orgao(request):
  197 + url = REST_URL + '/orgao_sg/doc'
  198 + reg = dict(request.params)
  199 + json_reg = json.dumps(reg)
  200 + data = {'value': json_reg}
  201 + response = requests.post(url, data=data)
  202 + print(response.text)
  203 +
  204 + return Response(response.text)
... ...