From 1fff73f93fa710b2b15fc4f88fbca422eaa21a2b Mon Sep 17 00:00:00 2001 From: pedro Date: Tue, 19 Nov 2013 20:14:39 +0000 Subject: [PATCH] Correção na recepção de dados --- development.ini | 2 +- lbbulk/config/routing.py | 7 +++++-- lbbulk/model/BulkSources.py | 20 ++++++++++++++++++++ lbbulk/model/BulkUpload.py | 27 +++++++++++++++++++++++++++ lbbulk/model/Registro.py | 34 ---------------------------------- lbbulk/view/restfulview.py | 17 ++++++++++------- 6 files changed, 63 insertions(+), 44 deletions(-) create mode 100644 lbbulk/model/BulkSources.py create mode 100644 lbbulk/model/BulkUpload.py delete mode 100644 lbbulk/model/Registro.py diff --git a/development.ini b/development.ini index e6276fb..af700c9 100644 --- a/development.ini +++ b/development.ini @@ -12,7 +12,7 @@ pyramid.debug_notfound = false pyramid.debug_routematch = false pyramid.default_locale_name = en pyramid.includes = - pyramid_debugtoolbar +# pyramid_debugtoolbar pyramid_tm sqlalchemy.url = postgresql://postgres:postgres@10.1.0.152/projeto1 diff --git a/lbbulk/config/routing.py b/lbbulk/config/routing.py index b7cd1c3..c2166f8 100644 --- a/lbbulk/config/routing.py +++ b/lbbulk/config/routing.py @@ -1,5 +1,6 @@ # import lbbulk.model -from lbbulk.model.Registro import RegistroContextFactory +from lbbulk.model.BulkUpload import BulkUploadContextFactory +from lbbulk.model.BulkSources import BulkSourcesContextFactory from lbbulk.view.restfulview import RegCustomView def make_routes(config): @@ -8,4 +9,6 @@ def make_routes(config): """ config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') - config.add_restful_routes('registro', RegistroContextFactory, view=RegCustomView) \ No newline at end of file + config.add_restful_routes('sources', BulkSourcesContextFactory) + config.add_restful_routes('registro', BulkUploadContextFactory, + view=RegCustomView) \ No newline at end of file diff --git a/lbbulk/model/BulkSources.py b/lbbulk/model/BulkSources.py new file mode 100644 index 0000000..8e0cab9 --- /dev/null +++ b/lbbulk/model/BulkSources.py @@ -0,0 +1,20 @@ +from sqlalchemy import Table, Column, Integer, String +from pyramid_restler.model import SQLAlchemyORMContext +from lbbulk.model import Base, metadata, session + + +bulk_sources = Table('lb_bulk_sources', metadata, + Column('id_source', Integer, primary_key=True), + Column('nome_source', String, nullable=False) + ) + + +# map to it +class BulkSources(Base): + __table__ = bulk_sources + +class BulkSourcesContextFactory(SQLAlchemyORMContext): + entity = BulkSources + + def session_factory(self): + return session \ No newline at end of file diff --git a/lbbulk/model/BulkUpload.py b/lbbulk/model/BulkUpload.py new file mode 100644 index 0000000..f0464df --- /dev/null +++ b/lbbulk/model/BulkUpload.py @@ -0,0 +1,27 @@ +from sqlalchemy import Table, Column, Integer, String, ForeignKey +from pyramid_restler.model import SQLAlchemyORMContext +from lbbulk.model import Base, metadata, session +import json + + +bulk_upload = Table('lb_bulk_upload', metadata, + Column('id_reg', Integer, primary_key=True), + Column('chave_externa', String, nullable=False), + Column('id_source', Integer, + ForeignKey('lb_bulk_sources.id_source'), + nullable=False) + ) + +# map to it +class BulkUpload(Base): + __table__ = bulk_upload + +class BulkUploadContextFactory(SQLAlchemyORMContext): + entity = BulkUpload + + def session_factory(self): + return session + + 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/model/Registro.py b/lbbulk/model/Registro.py deleted file mode 100644 index d294300..0000000 --- a/lbbulk/model/Registro.py +++ /dev/null @@ -1,34 +0,0 @@ -from sqlalchemy import Table, Column, Integer, \ - String, join, ForeignKey -from sqlalchemy.orm import column_property -from pyramid_restler.model import SQLAlchemyORMContext -from lbbulk.model import Base, metadata, session - -# define two Table objects -bulk_sources = Table('lb_bulk_sources', metadata, - Column('id_source', Integer, primary_key=True), - Column('nome_source', String), - ) - -bulk_upload = Table('lb_bulk_upload', metadata, - Column('id_reg', Integer, primary_key=True), - Column('chave_externa', String), - Column('id_source', Integer, ForeignKey('lb_bulk_sources.id_source')) - ) - -# define a join between them. This -# takes place across the bulk_sources.id_source and bulk_upload.id_source -# columns. -registro = join(bulk_sources, bulk_upload) - -# map to it -class Registro(Base): - __table__ = registro - id_source = column_property(bulk_sources.c.id_source, bulk_upload.c.id_source) - -class RegistroContextFactory(SQLAlchemyORMContext): - - entity = Registro - - def session_factory(self): - return session \ No newline at end of file diff --git a/lbbulk/view/restfulview.py b/lbbulk/view/restfulview.py index 4c0b479..98cc002 100644 --- a/lbbulk/view/restfulview.py +++ b/lbbulk/view/restfulview.py @@ -2,10 +2,13 @@ from pyramid_restler.view import RESTfulView import json class RegCustomView(RESTfulView): - def get_member(self): - id = self.request.matchdict['id'] - json_reg = self.requests.params['json_reg'] - json_reg = json.loads(json_reg) - ins = registro.insert().values(chave_externa=json_reg['id_reg']) - member = self.context.get_member(id) - return self.render_to_response(member) \ No newline at end of file + def _get_data(self): + content_type = self.request.content_type + if content_type == 'application/json': + data = json.loads(self.request.body) + elif content_type == 'application/x-www-form-urlencoded': + data = dict(self.request.POST) + else: + data = self.request.params + data = data['json_reg'] + return data \ No newline at end of file -- libgit2 0.21.2