diff --git a/.gitignore b/.gitignore index 51cbe85..bafddcd 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,6 @@ coverage.xml # Sphinx documentation docs/_build/ +# Pycharm +.idea/ + diff --git a/development.ini b/development.ini index c237de6..ad9e8fb 100644 --- a/development.ini +++ b/development.ini @@ -45,3 +45,6 @@ formatter = generic [formatter_generic] format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s + +[lbgenerator] +rest_url = http://localhost/api \ No newline at end of file diff --git a/setup.py b/setup.py index 5d0651d..9f12e99 100644 --- a/setup.py +++ b/setup.py @@ -15,11 +15,12 @@ requires = [ 'zope.sqlalchemy', 'waitress', 'requests', - 'pyramid_chameleon' + 'pyramid_chameleon', + 'liblightbase' ] setup(name='WSCacicNeo', - version='0.0', + version='0.1', description='WSCacicNeo', long_description=README + '\n\n' + CHANGES, classifiers=[ diff --git a/wscacicneo/__init__.py b/wscacicneo/__init__.py index 0f63020..f31590b 100644 --- a/wscacicneo/__init__.py +++ b/wscacicneo/__init__.py @@ -1,6 +1,26 @@ +#!/usr/env python +# -*- coding: utf-8 -*- +import os +import configparser from pyramid.config import Configurator +config = configparser.ConfigParser() +here = os.path.abspath(os.path.dirname(__file__)) +config_file = os.path.join(here, '../development.ini') +config.read(config_file) + + +class WSCacicNeo(object): + """ + Classe genérica com os parâmetros de configuração + """ + def __init__(self): + """ + Método construtor + """ + self.rest_url = config.get('lbgenerator', 'rest_url') + def main(global_config, **settings): """ This function returns a Pyramid WSGI application. @@ -16,10 +36,12 @@ def main(global_config, **settings): config.add_route('admin', 'admin') config.add_route('proc', 'proc') config.add_route('sistema', 'sistema') + #Órgão config.add_route('orgao', 'orgao') + config.add_route('post_orgao', 'post_orgao') + # config.add_route('list', 'list') config.add_route('gestao', 'gestao') - config.add_route('bot', 'bot') config.add_route('memoria', 'memoria') config.add_route('basico', 'basico') config.add_route('rede', 'rede') @@ -27,6 +49,7 @@ def main(global_config, **settings): config.add_route('hd', 'hd') config.add_route('config', 'config') config.add_route('users', 'users') + config.add_route('bot', 'bot') config.add_route('login', 'login') config.add_route('reports', 'reports') config.add_route('computador', 'computador') @@ -49,4 +72,3 @@ def main(global_config, **settings): config.scan() return config.make_wsgi_app() - diff --git a/wscacicneo/model/orgao.py b/wscacicneo/model/orgao.py new file mode 100644 index 0000000..4da6152 --- /dev/null +++ b/wscacicneo/model/orgao.py @@ -0,0 +1,164 @@ +#!/usr/env python +# -*- coding: utf-8 -*- +__author__ = 'eduardo' + +from wscacicneo import WSCacicNeo +from liblightbase.lbbase.struct import Base, BaseMetadata +from liblightbase.lbbase.lbstruct.group import * +from liblightbase.lbbase.lbstruct.field import * +from liblightbase.lbbase.content import Content +from liblightbase.lbrest.base import BaseREST + +class OrgaoBase(WSCacicNeo): + """ + Classe para a base de órgãos + """ + def __init__(self): + """ + Método construtor + """ + WSCacicNeo.__init__(self) + self.baserest = BaseREST(rest_url=self.rest_url, response_object=True) + + @property + def lbbase(self): + """ + LB Base do órgão + """ + nome = Field(**dict( + name='nome', + description='Nome do órgão', + alias='nome', + datatype='Text', + indices=['Textual'], + multivalued=False, + required=True + )) + + sigla = Field(**dict( + name='sigla', + alias='sigla', + description='Sigla do órgão', + datatype='Text', + indices=['Textual'], + multivalued=False, + required=True + )) + + cargo = Field(**dict( + name='cargo', + alias='cargo', + description='Cargo do gestor', + datatype='Text', + indices=['Textual'], + multivalued=False, + required=True + )) + + telefone = Field(**dict( + name='telefone', + alias='telefone', + description='Telefone do órgão', + datatype='Text', + indices=['Textual'], + multivalued=False, + required=True + )) + + email = Field(**dict( + name='email', + alias='email', + description='E-mail do órgão', + datatype='Text', + indices=['Textual'], + multivalued=False, + required=True + )) + + endereco = Field(**dict( + name='endereco', + alias='endereco', + description='Endereço do orgao', + datatype='Text', + indices=['Textual'], + multivalued=False, + required=True + )) + + coleta = Field(**dict( + name='coleta', + alias='coleta', + description='Intervalo de coleta', + datatype='Text', + indices=['Textual'], + multivalued=False, + required=True + )) + + base_metadata = BaseMetadata(**dict( + name='orgaos', + description='Órgãos da administração pública', + password='123456', + idx_exp=False, + idx_exp_url='index_url', + idx_exp_time=300, + file_ext=True, + file_ext_time=300, + color='#FFFFFF' + )) + + content_list = Content() + content_list.append(nome) + content_list.append(sigla) + content_list.append(cargo) + content_list.append(telefone) + content_list.append(email) + content_list.append(endereco) + content_list.append(coleta) + + lbbase = Base( + metadata=base_metadata, + content=content_list + ) + + return lbbase + + @property + def metaclass(self): + """ + Retorna metaclass para essa base + """ + return self.lbbase.metaclass() + + def create_base(self): + """ + Cria base no LB + """ + response = self.baserest.create(self.lbbase) + #print(response.status_code) + if response.status_code == 200: + return self.lbbase + else: + return None + + def remove_base(self): + """ + Remove base from Lightbase + :param lbbase: LBBase object instance + :return: True or Error if base was not excluded + """ + response = self.baserest.delete(self.lbbase) + if response.status_code == 200: + return True + else: + raise IOError('Error excluding base from LB') + +orgao = OrgaoBase().metaclass + + +class Orgao(orgao): + """ + Classe genérica de órgãos + """ + def __init__(self, **args): + super(Orgao, self).__init__(**args) \ No newline at end of file diff --git a/wscacicneo/static/orgao.js b/wscacicneo/static/orgao.js index 9bf2d80..ddaedc9 100644 --- a/wscacicneo/static/orgao.js +++ b/wscacicneo/static/orgao.js @@ -86,14 +86,11 @@ painel = Ext.create('Ext.panel.Panel', { }); Ext.onReady(function(){ - - Ext.create('Ext.Container', { padding: '15px', items: [painel], renderTo: 'widgets' }); - }); @@ -116,7 +113,8 @@ $('#button-1017-btnIconEl').click(function(){ } $.ajax({ type: "POST", - url: 'http://10.1.0.121/wscacicneo/orgao', + url: 'post_orgao', + data : reg, cache: false, success: function(jqXHR, textStatus, errorThrown){ alert('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') diff --git a/wscacicneo/test/test_orgao_base.py b/wscacicneo/test/test_orgao_base.py new file mode 100644 index 0000000..985821c --- /dev/null +++ b/wscacicneo/test/test_orgao_base.py @@ -0,0 +1,81 @@ +#!/usr/env python +# -*- coding: utf-8 -*- +__author__ = 'eduardo' + +import unittest +from wscacicneo.model import orgao +from liblightbase.lbbase.struct import Base +from liblightbase.lbutils import conv + +class TestOrgaoBase(unittest.TestCase): + """ + Testa base do órgão no LB + """ + def setUp(self): + """ + Carregando atributos genéricos do teste + """ + pass + + def test_base(self): + """ + Testa criação do objeto base no LB + """ + orgao_base = orgao.OrgaoBase() + lbbase = orgao_base.lbbase + self.assertIsInstance(lbbase, Base) + + fd = open('/tmp/orgao_base.json', 'w+') + fd.write(lbbase.json) + fd.close() + self.assertIsInstance(lbbase, Base) + j = lbbase.json + b = conv.json2base(j) + self.assertIsInstance(b, Base) + + def test_create_base(self): + """ + Testa criação da base no LB + """ + orgao_base = orgao.OrgaoBase() + lbbase = orgao_base.lbbase + self.assertIsInstance(lbbase, Base) + + retorno = orgao_base.create_base() + self.assertIsInstance(retorno, Base) + + retorno = orgao_base.remove_base() + self.assertTrue(retorno) + + def test_orgao_metaclass(self): + """ + testa atribuição de metaclass + """ + orgao_base = orgao.OrgaoBase() + lbbase = orgao_base.lbbase + self.assertIsInstance(lbbase, Base) + + self.assertIsNotNone(orgao_base.metaclass) + + def test_orgao_attributes(self): + """ + Testa verificação de atributos + """ + orgao_obj = orgao.Orgao( + nome='Ministério do Planejamento', + cargo='Gestor', + coleta='4h', + sigla='MPOG', + endereco='Esplanada bloco C', + email='admin@planemaneto.gov.br', + telefone='(61) 2025-4117' + ) + self.assertIsInstance(orgao_obj, orgao.Orgao) + self.assertEqual(orgao_obj.nome, 'Ministério do Planejamento') + self.assertEqual(orgao_obj.cargo, 'Gestor') + + def tearDown(self): + """ + Apaga dados do teste + """ + pass \ No newline at end of file diff --git a/wscacicneo/views.py b/wscacicneo/views.py index 089cd1d..c4d0313 100644 --- a/wscacicneo/views.py +++ b/wscacicneo/views.py @@ -1,4 +1,5 @@ import requests +import json from pyramid.response import Response from pyramid.httpexceptions import HTTPFound from pyramid.view import view_config @@ -16,11 +17,7 @@ Session = sessionmaker(bind=engine) session = Session() @view_config(route_name='master', renderer='templates/master.pt') def master(request): - url = REST_URL + '/orgao_sg/doc' - json_reg = request.params - data = {'value': json_reg} - response = requests.post(url, data=data) - return response.text + return {'project': 'WSCacicNeo'} @view_config(route_name='home', renderer='templates/home.pt') def home(request): @@ -192,3 +189,16 @@ def my_view8(request): #print (dc) return {'project':'WSCacicNeo', 'data': data} + +#URL POST + +@view_config(route_name='post_orgao') +def post_orgao(request): + url = REST_URL + '/orgao_sg/doc' + reg = dict(request.params) + json_reg = json.dumps(reg) + data = {'value': json_reg} + response = requests.post(url, data=data) + print(response.text) + + return Response(response.text) -- libgit2 0.21.2