Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Base = declarative_base(cls=Base)
- class Training(Entity, Base):
- id = Column(BigInteger, Sequence('training_id_seq', start=1, increment=1))
- meet = Column(Integer, primary_key=True, default=Constants.DefaultInteger)
- trdate = Column(Date, primary_key=True)
- hrno = Column(String, primary_key=True)
- sptime = Column(DateTime, primary_key=True)
- part = Column(String, nullable=True)
- partno = Column(String, nullable=True)
- app = Flask('rest-api', template_folder='../templates', static_folder='../static')
- CORS(app)
- @app.errorhandler(InvalidUsage)
- def handle_invalid_usage(error):
- response = jsonify(error.to_dict())
- response.status_code = error.status_code
- return response
- if __name__ == "__main__":
- app.config['SQLALCHEMY_DATABASE_URI'] = ServerConstants.FUNDAMENTAL_DB
- app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
- app.register_blueprint(training_api)
- app.run(host=ServerConstants.host, port=ServerConstants.port, debug=ServerConstants.debug,
- ssl_context=('cert.pem', 'key.pem'))
- training_api = Blueprint('training_api', __name__)
- @training_api.route("/training/get", methods=['GET'])
- def get_training():
- **session = Connector.Session()**
- query = session.query(Training)
- query = order_by_latest(query, Training)
- query = add_pagination(request, query)
- trainings = query.all()
- **session.close()**
- return respond_with_json({'trainings': [t.toDict() for t in trainings]})
- from sqlalchemy.orm import sessionmaker
- from tools import ServerConstants
- Session = sessionmaker(bind=ServerConstants.ENGINE)
- db = SQLAlchemy(app)
- db.session.query(Training)
- ...
- session.connection()
Add Comment
Please, Sign In to add comment