Commit 1fff73f93fa710b2b15fc4f88fbca422eaa21a2b
1 parent
33b0d1d2
Exists in
master
Correção na recepção de dados
git-svn-id: http://svn.brlight.net/svn/lightbase-neo/trunk/LBBulk@781 29b92fdf-8c97-4584-b987-84e8d3c556fa
Showing
6 changed files
with
63 additions
and
44 deletions
Show diff stats
development.ini
... | ... | @@ -12,7 +12,7 @@ pyramid.debug_notfound = false |
12 | 12 | pyramid.debug_routematch = false |
13 | 13 | pyramid.default_locale_name = en |
14 | 14 | pyramid.includes = |
15 | - pyramid_debugtoolbar | |
15 | +# pyramid_debugtoolbar | |
16 | 16 | pyramid_tm |
17 | 17 | |
18 | 18 | sqlalchemy.url = postgresql://postgres:postgres@10.1.0.152/projeto1 | ... | ... |
lbbulk/config/routing.py
1 | 1 | # import lbbulk.model |
2 | -from lbbulk.model.Registro import RegistroContextFactory | |
2 | +from lbbulk.model.BulkUpload import BulkUploadContextFactory | |
3 | +from lbbulk.model.BulkSources import BulkSourcesContextFactory | |
3 | 4 | from lbbulk.view.restfulview import RegCustomView |
4 | 5 | |
5 | 6 | def make_routes(config): |
... | ... | @@ -8,4 +9,6 @@ def make_routes(config): |
8 | 9 | """ |
9 | 10 | config.add_static_view('static', 'static', cache_max_age=3600) |
10 | 11 | config.add_route('home', '/') |
11 | - config.add_restful_routes('registro', RegistroContextFactory, view=RegCustomView) | |
12 | 12 | \ No newline at end of file |
13 | + config.add_restful_routes('sources', BulkSourcesContextFactory) | |
14 | + config.add_restful_routes('registro', BulkUploadContextFactory, | |
15 | + view=RegCustomView) | |
13 | 16 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +from sqlalchemy import Table, Column, Integer, String | |
2 | +from pyramid_restler.model import SQLAlchemyORMContext | |
3 | +from lbbulk.model import Base, metadata, session | |
4 | + | |
5 | + | |
6 | +bulk_sources = Table('lb_bulk_sources', metadata, | |
7 | + Column('id_source', Integer, primary_key=True), | |
8 | + Column('nome_source', String, nullable=False) | |
9 | + ) | |
10 | + | |
11 | + | |
12 | +# map to it | |
13 | +class BulkSources(Base): | |
14 | + __table__ = bulk_sources | |
15 | + | |
16 | +class BulkSourcesContextFactory(SQLAlchemyORMContext): | |
17 | + entity = BulkSources | |
18 | + | |
19 | + def session_factory(self): | |
20 | + return session | |
0 | 21 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,27 @@ |
1 | +from sqlalchemy import Table, Column, Integer, String, ForeignKey | |
2 | +from pyramid_restler.model import SQLAlchemyORMContext | |
3 | +from lbbulk.model import Base, metadata, session | |
4 | +import json | |
5 | + | |
6 | + | |
7 | +bulk_upload = Table('lb_bulk_upload', metadata, | |
8 | + Column('id_reg', Integer, primary_key=True), | |
9 | + Column('chave_externa', String, nullable=False), | |
10 | + Column('id_source', Integer, | |
11 | + ForeignKey('lb_bulk_sources.id_source'), | |
12 | + nullable=False) | |
13 | + ) | |
14 | + | |
15 | +# map to it | |
16 | +class BulkUpload(Base): | |
17 | + __table__ = bulk_upload | |
18 | + | |
19 | +class BulkUploadContextFactory(SQLAlchemyORMContext): | |
20 | + entity = BulkUpload | |
21 | + | |
22 | + def session_factory(self): | |
23 | + return session | |
24 | + | |
25 | + def get_member_id_as_string(self, member): | |
26 | + id = self.get_member_id(member) | |
27 | + return json.dumps(id, cls=self.json_encoder) | |
0 | 28 | \ No newline at end of file | ... | ... |
lbbulk/model/Registro.py
... | ... | @@ -1,34 +0,0 @@ |
1 | -from sqlalchemy import Table, Column, Integer, \ | |
2 | - String, join, ForeignKey | |
3 | -from sqlalchemy.orm import column_property | |
4 | -from pyramid_restler.model import SQLAlchemyORMContext | |
5 | -from lbbulk.model import Base, metadata, session | |
6 | - | |
7 | -# define two Table objects | |
8 | -bulk_sources = Table('lb_bulk_sources', metadata, | |
9 | - Column('id_source', Integer, primary_key=True), | |
10 | - Column('nome_source', String), | |
11 | - ) | |
12 | - | |
13 | -bulk_upload = Table('lb_bulk_upload', metadata, | |
14 | - Column('id_reg', Integer, primary_key=True), | |
15 | - Column('chave_externa', String), | |
16 | - Column('id_source', Integer, ForeignKey('lb_bulk_sources.id_source')) | |
17 | - ) | |
18 | - | |
19 | -# define a join between them. This | |
20 | -# takes place across the bulk_sources.id_source and bulk_upload.id_source | |
21 | -# columns. | |
22 | -registro = join(bulk_sources, bulk_upload) | |
23 | - | |
24 | -# map to it | |
25 | -class Registro(Base): | |
26 | - __table__ = registro | |
27 | - id_source = column_property(bulk_sources.c.id_source, bulk_upload.c.id_source) | |
28 | - | |
29 | -class RegistroContextFactory(SQLAlchemyORMContext): | |
30 | - | |
31 | - entity = Registro | |
32 | - | |
33 | - def session_factory(self): | |
34 | - return session | |
35 | 0 | \ No newline at end of file |
lbbulk/view/restfulview.py
... | ... | @@ -2,10 +2,13 @@ from pyramid_restler.view import RESTfulView |
2 | 2 | import json |
3 | 3 | |
4 | 4 | class RegCustomView(RESTfulView): |
5 | - def get_member(self): | |
6 | - id = self.request.matchdict['id'] | |
7 | - json_reg = self.requests.params['json_reg'] | |
8 | - json_reg = json.loads(json_reg) | |
9 | - ins = registro.insert().values(chave_externa=json_reg['id_reg']) | |
10 | - member = self.context.get_member(id) | |
11 | - return self.render_to_response(member) | |
12 | 5 | \ No newline at end of file |
6 | + def _get_data(self): | |
7 | + content_type = self.request.content_type | |
8 | + if content_type == 'application/json': | |
9 | + data = json.loads(self.request.body) | |
10 | + elif content_type == 'application/x-www-form-urlencoded': | |
11 | + data = dict(self.request.POST) | |
12 | + else: | |
13 | + data = self.request.params | |
14 | + data = data['json_reg'] | |
15 | + return data | |
13 | 16 | \ No newline at end of file | ... | ... |