File tree 2 files changed +45
-0
lines changed
2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ from flask import Flask , request , jsonify
2
+ from flask .ext .restful import Resource , Api
3
+ from models import Nacional
4
+
5
+ app = Flask (__name__ )
6
+ api = Api (app )
7
+
8
+
9
+ class CNE (Resource ):
10
+ def get (self , cedula ):
11
+ registro = Nacional .query .filter_by (cedula = cedula ).first ()
12
+ if registro is not None :
13
+ return registro .as_dict ()
14
+ else :
15
+ return {}
16
+
17
+
18
+
19
+ api .add_resource (CNE , '/<string:cedula>' )
20
+
21
+ if __name__ == '__main__' :
22
+ app .run (debug = True )
Original file line number Diff line number Diff line change
1
+ from flask import Flask
2
+ from flask .ext .sqlalchemy import SQLAlchemy
3
+
4
+ app = Flask (__name__ )
5
+ app .config ['SQLALCHEMY_DATABASE_URI' ] = 'postgres://overflow:137955@localhost/apicne'
6
+ db = SQLAlchemy (app )
7
+
8
+ class Nacional (db .Model ):
9
+ __tablename__ = 'nacional'
10
+ nacionalidad = db .Column (db .String (1 ))
11
+ cedula = db .Column (db .Integer , primary_key = True )
12
+ primer_apellido = db .Column (db .String (100 ))
13
+ segundo_apellido = db .Column (db .String (100 ))
14
+ primer_nombre = db .Column (db .String (100 ))
15
+ segundo_nombre = db .Column (db .String (100 ))
16
+ cod_centro = db .Column (db .Integer , unique = True )
17
+
18
+ def __repr__ (self ):
19
+ return '{primer_apellido: %s}' % self .primer_apellido
20
+
21
+ def as_dict (self ):
22
+ return {c .name : getattr (self , c .name ) for c in self .__table__ .columns }
23
+
You can’t perform that action at this time.
0 commit comments