diff --git a/TODO.txt b/TODO.txt index 7517906..953bb38 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,5 +1,2 @@ -- Recebe registro -- Verifica se o registro já existe no lightbase: - se sim, atualiza - se não, cria -- salva na tabela de chaves a chave do lightbase que corresponde à esse registro \ No newline at end of file +lbbulk/view/restfulview.py line 41 +lbbulk/view/restfulview.py line 48 \ No newline at end of file diff --git a/development.ini b/development.ini index af700c9..24b6265 100644 --- a/development.ini +++ b/development.ini @@ -12,18 +12,12 @@ pyramid.debug_notfound = false pyramid.debug_routematch = false pyramid.default_locale_name = en pyramid.includes = -# pyramid_debugtoolbar pyramid_tm sqlalchemy.url = postgresql://postgres:postgres@10.1.0.152/projeto1 -# By default, the toolbar only appears for clients from IP addresses -# '127.0.0.1' and '::1'. -# debugtoolbar.hosts = 0.0.0.0/0 - -### -# wsgi server configuration -### +domain = http://localhost/lbgenerator +base_name = WMI [server:main] use = egg:waitress#main diff --git a/lbbulk/model/BulkUpload.py b/lbbulk/model/BulkUpload.py index f0464df..309141c 100644 --- a/lbbulk/model/BulkUpload.py +++ b/lbbulk/model/BulkUpload.py @@ -22,6 +22,12 @@ class BulkUploadContextFactory(SQLAlchemyORMContext): def session_factory(self): return session + def create_member(self, data): + member = self.entity(**data) + self.session.add(member) + self.session.commit() + return member + def get_member_id_as_string(self, member): id = self.get_member_id(member) return json.dumps(id, cls=self.json_encoder) \ No newline at end of file diff --git a/lbbulk/view/restfulview.py b/lbbulk/view/restfulview.py index 98cc002..2f9d13b 100644 --- a/lbbulk/view/restfulview.py +++ b/lbbulk/view/restfulview.py @@ -1,8 +1,12 @@ from pyramid_restler.view import RESTfulView +import configparser import json +import requests class RegCustomView(RESTfulView): def _get_data(self): + """ Read json data from the post sent by some source """ + print('\n\n\n\n\n\n\n\n\n\n\n\n') content_type = self.request.content_type if content_type == 'application/json': data = json.loads(self.request.body) @@ -10,5 +14,36 @@ class RegCustomView(RESTfulView): data = dict(self.request.POST) else: data = self.request.params - data = data['json_reg'] + data = self.send_to_lightbase(data) + # Must come with the external key as a value of + # 'data.json_reg.id_reg' + return data + + def send_to_lightbase(self, data): + """ Sends the register to a lightbase table and returns a dict + with the external key and lighbase's id_reg """ + registro = self.is_error(data) + id_source = registro['id_source'] + registro.pop('id_source', None) + registro['json_reg'] = json.loads(registro['json_reg']) + chave_externa = registro['json_reg']['id_reg'] + registro['json_reg'].pop('id_reg', None) + url = self.get_url_lightbase() + r = requests.post(url, data=registro) + id_reg = r.json() + data = { + 'id_source':id_source, + 'id_reg':id_reg, + 'chave_externa':chave_externa + } + return data + + def get_url_lightbase(self): #TODO + """ Returns url from config """ + domain = 'http://localhost/lbgenerator' + base_name = 'WMI' + url = domain + '/' + base_name + '/reg' + return url + + def is_error(self,data): #TODO return data \ No newline at end of file diff --git a/production.ini b/production.ini index 20b33ed..99704b3 100644 --- a/production.ini +++ b/production.ini @@ -16,6 +16,9 @@ pyramid.includes = sqlalchemy.url = postgresql://postgres:postgres@10.1.0.152/projeto1 +domain = http://localhost/lbgenerator +base_name = WMI + [server:main] use = egg:waitress#main host = 0.0.0.0 diff --git a/setup.py b/setup.py index a1c64b7..cb432d6 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,8 @@ requires = [ 'zope.sqlalchemy', 'waitress', 'pyramid_restler', + 'requests', + 'configparser' ] setup(name='LBBulk', -- libgit2 0.21.2