Esempio n. 1
0
def create_app(config):
    app = Flask(__name__)
    app.config.from_object(config)
    db.init_app(app)
    with app.app_context():
        db.create_all()
        return app
Esempio n. 2
0
def init_db(app):
    """
    init db and create all tables
    """
    db.init_app(app)
    with app.app_context():
        db.create_all()
Esempio n. 3
0
def create_app(config):
    app = Flask(__name__)
    CORS(app)

    app.config.from_object(config)

    app.register_blueprint(route_path_general, url_prefix='/api')

    # START GLOBAL HTTP CONFIGURATIONS
    @app.after_request
    def add_header(response):
        return response

    @app.errorhandler(400)
    def bad_request(e):
        logging.error(e)
        return response_with(resp.BAD_REQUEST_400)

    @app.errorhandler(500)
    def server_error(e):
        logging.error(e)
        return response_with(resp.SERVER_ERROR_500)

    @app.errorhandler(404)
    def not_found(e):
        logging.error(e)
        return response_with(resp.NOT_FOUND_HANDLER_404)

    @app.errorhandler(AuthRequired)
    def auth_required(e):
        logging.error(e)
        return response_with(resp.UNAUTHORIZED_403, message=e.message)

    @app.errorhandler(DecodeError)
    def decode_error(e):
        logging.error(e)
        return response_with(resp.UNAUTHORIZED_403, message=e.message)

    @app.errorhandler(ExpiredSignatureError)
    def expired_error(e):
        logging.error(e)
        return response_with(resp.UNAUTHORIZED_403, message=e.message)

    @app.errorhandler(BaseJWTError)
    def base_jwt_error(e):
        logging.error(e)
        return response_with(resp.UNAUTHORIZED_403, message=e.message)

    # END GLOBAL HTTP CONFIGURATIONS

    db.init_app(app)
    with app.app_context():
        # from api.models import *
        db.create_all()

    logging.basicConfig(
        stream=sys.stdout,
        format='%(asctime)s|%(levelname)s|%(filename)s:%(lineno)s|%(message)s',
        level=logging.DEBUG)
    return app
Esempio n. 4
0
def create_app(config):
    app = Flask(__name__)
    app.config.from_object(app_config)

    db.init_app(app)
    with app.app_context():
        db.create_all()

    @app.after_request
    def add_header(response):
        return response

    @app.errorhandler(400)
    def bad_request(e):
        return response_with(resp.BAD_REQUEST_400)

    @app.errorhandler(500)
    def server_error(e):
        return response_with(resp.SERVER_ERROR_500)

    @app.errorhandler(404)
    def not_found(e):
        return response_with(resp.SERVER_ERROR_404)

    app.register_blueprint(author_routes, url_prefix='/api/authors')
    app.register_blueprint(book_routes, url_prefix='/api/books')

    return app
Esempio n. 5
0
def create_app(config):
	app = Flask(__name__)
	app.config.from_object(app_config)
	app.register_blueprint(category_routes, url_prefix='/api/categories')
	app.register_blueprint(product_routes, url_prefix='/api/products')
	# START GLOBAL HTTP CONFIGURATIONS
	@app.after_request
	def add_header(response):    
		return response
		
	@app.errorhandler(400)
	def bad_request(e):    
		logging.error(e)    
		return response_with(resp.BAD_REQUEST_400)

	@app.errorhandler(500)
	def server_error(e):    
		logging.error(e)    
		return response_with(resp.SERVER_ERROR_500)
		
	@app.errorhandler(404)
	def not_found(e):    
		logging.error(e)    
		return response_with(resp.SERVER_ERROR_404)
		
	db.init_app(app)
	with app.app_context():
		db.create_all()
	return app
Esempio n. 6
0
 def setUp(self) -> None:
     app = create_app('testing')
     # self.test_db_file = tempfile.mkstemp()[1]
     # app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + self.test_db_file
     with app.app_context():
         db.create_all()
     app.app_context().push()
     self.app = app.test_client()
Esempio n. 7
0
def create_app(config):
    app = Flask(__name__)
    app.config.from_object(config)

    app.register_blueprint(author_routes, url_prefix='/api/authors')
    app.register_blueprint(book_routes, url_prefix='/api/books')
    app.register_blueprint(user_routes, url_prefix='/api/users')

    SWAGGER_URL = '/api/docs'
    swaggerui_blueprint = get_swaggerui_blueprint(
        '/api/docs', '/api/spec', config={'app_name': "Flask Author DB"})
    app.register_blueprint(swaggerui_blueprint, url_prefix=SWAGGER_URL)

    @app.route('/avatar/<filename>')
    def uploaded_file(filename):
        return send_from_directory(app.config['UPLOAD_FOLDER'], filename)

    @app.after_request
    def add_header(response):
        return response

    @app.errorhandler(400)
    def bad_request(e):
        logging.error(e)
        return response_with(resp.BAD_REQUEST_400)

    @app.errorhandler(500)
    def server_error(e):
        logging.error(e)
        return response_with(resp.SERVER_ERROR_500)

    @app.errorhandler(404)
    def not_found(e):
        logging.error(e)
        return response_with(resp.SERVER_ERROR_404)

    @app.route('/api/spec')
    def spec():
        swag = swagger(app, prefix='/api')
        swag['info']['base'] = "http://localhost:5000"
        swag['info']['version'] = "1.0"
        swag['info']['title'] = "Flask Author DB"
        return jsonify(swag)

    jwt = JWTManager(app)
    mail.init_app(app)

    db.init_app(app)
    with app.app_context():
        db.create_all()

    logging.basicConfig(
        stream=sys.stdout,
        format='%(asctime)s|%(levelname)s|%(filename)s:%(lineno)s|%(message)s',
        level=logging.DEBUG)

    return app
Esempio n. 8
0
 def setUp(self):
     app = create_app(Testing)
     self.test_db_file = tempfile.mkstemp()[1]
     app.config[
         'SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + self.test_db_file + '?check_same_thread=false'
     with app.app_context():
         db.create_all()
     app.app_context().push()
     self.app = app.test_client()
Esempio n. 9
0
def create_app(test_config=None):  # 1)
    app = Flask(__name__)
    if os.environ.get('WORK_ENV') == 'PROD':
        app_config = ProductionConfig
    elif os.environ.get('WORK_ENV') == 'TEST':
        app_config = TestingConfig
    else:
        app_config = DevelopmentConfig
    app.config.from_object(app_config)
    db.init_app(app)
    with app.app_context():
        db.create_all()

    # START GLOBAL HTTP CONFIGURATIONS
    @app.after_request
    def add_header(response):
        return response

    @app.errorhandler(400)
    def bad_request(e):
        logging.error(e)
        return response_with(resp.BAD_REQUEST_400)

    @app.errorhandler(500)
    def server_error(e):
        logging.error(e)
        return response_with(resp.SERVER_ERROR_500)

    @app.errorhandler(404)
    def not_found(e):
        logging.error(e)
        return response_with(resp.SERVER_ERROR_404)

    # END GLOBAL HTTP CONFIGURATIONS

    @app.route("/api/spec")
    def spec():
        swag = swagger(app, prefix='/api')
        swag['info']['base'] = "http://localhost:5000"
        swag['info']['version'] = "1.0"
        swag['info']['title'] = "Flask Author DB"
        return jsonify(swag)

    app.register_blueprint(product_routes, url_prefix='/api/products')
    swaggerui_blueprint = get_swaggerui_blueprint(
        '/api/docs', '/api/spec', config={'app_name': "Flask Author DB"})
    app.register_blueprint(swaggerui_blueprint,
                           url_prefix=swaggerui_blueprint.url_prefix)
    jwt = JWTManager(app)

    return app
Esempio n. 10
0
def create_app(config):
    app = Flask(__name__)

    app.config.from_object(config)

    app.register_blueprint(route_path_countries, url_prefix=url_prefix)
    app.register_blueprint(route_path_locations, url_prefix=url_prefix)
    app.register_blueprint(route_path_panels, url_prefix=url_prefix)
    app.register_blueprint(route_path_target_groups, url_prefix=url_prefix)

    # START GLOBAL HTTP CONFIGURATIONS
    @app.after_request
    def add_header(response):
        return response

    @app.errorhandler(400)
    def bad_request(e):
        logging.error(e)
        return response_with(resp.BAD_REQUEST_400)

    @app.errorhandler(500)
    def server_error(e):
        logging.error(e)
        return response_with(resp.SERVER_ERROR_500)

    @app.errorhandler(404)
    def not_found(e):
        logging.error(e)
        return response_with(resp.NOT_FOUND_HANDLER_404)

    # END GLOBAL HTTP CONFIGURATIONS

    @app.route("/api/spec")
    def spec():
        swag = swagger(app, prefix=url_prefix)
        swag['info']['version'] = "1.0"
        swag['info'][
            'title'] = "Flask powered by API, Alchemy and Marshmallow 'devtest' showcase"
        return jsonify(swag)

    db.init_app(app)
    with app.app_context():
        # from api.models import *
        db.create_all()

    logging.basicConfig(
        stream=sys.stdout,
        format='%(asctime)s|%(levelname)s|%(filename)s:%(lineno)s|%(message)s',
        level=logging.DEBUG)
    return app
Esempio n. 11
0
def create_app(config): 
    app = Flask(__name__)
    app.config.from_object(config)
    app.register_blueprint(author_routes, url_prefix='/api/authors')
    app.register_blueprint(book_routes, url_prefix='/api/books')
    app.register_blueprint(user_routes, url_prefix='/api/users')

    @app.route('/avatar/<filename>')
    def uploaded_file(filename):
        return send_from_directory(app.config['UPLOAD_ FOLDER'],filename)

    jwt = JWTManager(app)
    mail.init_app(app)

    db.init_app(app)
    with app.app_context():
        db.create_all()

    # START GLOBAL HTTP CONFIGURATIONS
    @app.after_request
    def add_header(response):
        return response
    
    @app.errorhandler(400)
    def bad_request(e):
        logging.error(e)
        return response_with(resp.BAD_REQUEST_400)
    
    @app.errorhandler(500)
    def server_error(e):
        logging.error(e)
        return response_with(resp.SERVER_ERROR_500)
    
    @app.errorhandler(404)
    def not_found(e):
        logging.error(e)
        return response_with(resp.SERVER_ERROR_404)
    
    @app.route("/api/spec")
    def spec():
        swag = swagger(app, prefix='/api')
        swag['info']['base'] = "http://localhost:5000"
        swag['info']['version'] = "1.0"
        swag['info']['title'] = "Flask Author DB"
        return jsonify(swag)
    
    swaggerui_blueprint = get_swaggerui_blueprint('/api/docs', '/api/spec', config={'app_name': "Flask Author DB"})
    app.register_blueprint(swaggerui_blueprint, url_prefix='/api/docs')
    return app
Esempio n. 12
0
def create_app(config):
    """
    This function is responsible of create the app
    instance in with the parameters provided in
    the config file.
    """

    app = Flask(__name__)

    app.config.from_object(config)

    db.init_app(app)
    with app.app_context():
        db.create_all()
    return app
Esempio n. 13
0
def create_app(config):
    app = Flask(__name__)

    app.config.from_object(config)

    app.register_blueprint(route_path_general, url_prefix='/api')
    app.register_blueprint(picture_blueprint)
    mongo = PyMongo(app)

    # START GLOBAL HTTP CONFIGURATIONS
    @app.after_request
    def add_header(response):
        return response

    @app.errorhandler(400)
    def bad_request(e):
        logging.error(e)
        return response_with(resp.BAD_REQUEST_400)

    @app.errorhandler(500)
    def server_error(e):
        logging.error(e)
        return response_with(resp.SERVER_ERROR_500)

    @app.errorhandler(404)
    def not_found(e):
        logging.error(e)
        return response_with(resp.NOT_FOUND_HANDLER_404)

    # END GLOBAL HTTP CONFIGURATIONS

    @app.route("/api/v1.0/spec")
    def spec():
        swag = swagger(app, prefix='/api/v1.0')
        swag['info']['version'] = "1.0"
        swag['info']['title'] = "Flask Starter API"
        return jsonify(swag)

    db.init_app(app)
    with app.app_context():
        # from api.models import *
        db.create_all()

    logging.basicConfig(stream=sys.stdout,
                        format='%(asctime)s|%(levelname)s|%(filename)s:%(lineno)s|%(message)s',
                        level=logging.DEBUG)
    return app
Esempio n. 14
0
def create_app(config):
    # that is skeleton of main
    app = Flask(__name__)

    app.register_blueprint(author_routes, url_prefix='/api/authors')
    app.register_blueprint(book_routers, url_prefix='/api/books')
    app.register_blueprint(user_routers, url_prefix='/api/users')
    app.config.from_object(config)

    # START GLOBAL HTTP CONFIGURATION
    @app.after_request
    def add_header(response):
        return response

    @app.errorhandler(400)
    def bad_request(e):
        logging.error(e)
        return response_with(resp.BAD_REQUEST_400)

    @app.errorhandler(500)
    def server_error(e):
        logging.error(e)
        return response_with(resp.SERVER_ERROR_500)

    @app.errorhandler(404)
    def not_found(e):
        logging.error(e)
        return response_with(resp.SERVER_ERROR_404)

    @app.route('/avatar/<filename>')
    def uploaded_file(filename):
        return send_from_directory(app.config['UPLOAD_FOLDER'], filename)

    db.init_app(app)
    jwt = JWTManager(app)
    mail.init_app(app)
    dashboard.bind(app)
    with app.app_context():
        db.create_all()

    logging.basicConfig(stream=sys.stdout,
                        format='%(asctime)s|%(levelname)s|%(filename)s:%(lineno)s|%(message)s',
                        level=logging.DEBUG)

    return app
Esempio n. 15
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(app_config)

    db.init_app(app)
    with app.app_context():
        db.create_all()

    app.register_blueprint(author_routes, url_prefix='/api/authors')
    app.register_blueprint(user_routes, url_prefix='/api/users')

    @app.after_request
    def add_header(response):
        return response

    @app.errorhandler(400)
    def bad_request(e):
        logging.error(e)
        return response_with(resp.BAD_REQUEST_400)

    @app.errorhandler(500)
    def server_error(e):
        logging.error(e)
        return response_with(resp.SERVER_ERROR_500)

    @app.errorhandler(404)
    def not_found(e):
        logging.error(e)
        return response_with(resp.SERVER_ERROR_404)

    jwt = JWTManager(app)
    db.init_app(app)

    with app.app_context():
        db.create_all()
    logging.basicConfig(
        stream=sys.stdout,
        format=
        '%(asctime)s | %(levelname)s | %(filename)s | %(lineno)s | %(message)s',
        level=logging.DEBUG)

    return app
Esempio n. 16
0
def create_app(config):
    app = Flask(__name__)

    app.config.from_object(config)

    app.register_blueprint(route_path_general, url_prefix='/api')

    # START GLOBAL HTTP CONFIGURATIONS
    @app.after_request
    def add_header(response):
        response.headers.add('Access-Control-Allow-Origin', '*')
        response.headers.add('Access-Control-Allow-Headers',
                             'Content-Type,Authorization')
        response.headers.add('Access-Control-Allow-Methods',
                             'GET,PUT,POST,DELETE,OPTIONS')
        return response

    @app.errorhandler(400)
    def bad_request(e):
        logging.error(e)
        return response_with(resp.BAD_REQUEST_400)

    @app.errorhandler(500)
    def server_error(e):
        logging.error(e)
        return response_with(resp.SERVER_ERROR_500)

    @app.errorhandler(404)
    def not_found(e):
        logging.error(e)
        return response_with(resp.NOT_FOUND_HANDLER_404)

    db.init_app(app)
    with app.app_context():
        # from api.models import *
        db.create_all()

    logging.basicConfig(
        stream=sys.stdout,
        format='%(asctime)s|%(levelname)s|%(filename)s:%(lineno)s|%(message)s',
        level=logging.DEBUG)
    return app
Esempio n. 17
0
def create_app():
    UPLOAD_FOLDER = './uploads'
    app = Flask(__name__)
    app.config['UPLOAD_FOLDER']= UPLOAD_FOLDER
    basedir = os.path.abspath(os.path.dirname(__file__))
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+os.path.join(basedir, 'db.sqlite')
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] =  False
    
   
    

    db.init_app(app)
    with app.app_context():
        db.create_all()
   # app.config.from_object(app_config)
    app.register_blueprint(posts_routes, url_prefix='/api/post')
    app.register_blueprint(comment_routes, url_prefix='/api/comments')
    @app.route('/image/<filename>')
    def uploaded_file(filename):
        return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
    @app.after_request
    def add_header(response):
        return response
    @app.errorhandler(400)
    def bad_request(e):
        logging.error(e)
        return response_with(resp.BAD_REQUEST_400)
    @app.errorhandler(500)
    def server_error(e):
        logging.error(e)
        return response_with(resp.SERVER_ERROR_500)
    @app.errorhandler(404)
    def not_found(e):
        logging.error(e)
        return response_with(resp.SERVER_ERROR_404)
   
    logging.basicConfig(stream=sys.stdout, format='%(asctime)s|%(levelname)s|%(filename)s:%(lineno)s|%(messages)s', level=logging.DEBUG) 
    @app.route('/')
    def index():
        return "<h1>Index route test</h1>"
    return app
Esempio n. 18
0
def create_app(app_config):
    app = Flask(__name__)

    app.config.from_object(app_config)

    #routes
    app.register_blueprint(customer_routes, url_prefix='/api/customers')
    app.register_blueprint(user_routes, url_prefix='/api/users')

    #route for upload photo
    @app.route('/photo/<filename>')
    def uploaded_file(filename):
        return send_from_directory(app.config['UPLOAD_FOLDER'], filename)

    jwt = JWTManager(app)
    db.init_app(app)
    ma.init_app(app)
    mail.init_app(app)

    with app.app_context():
        db.create_all()

    return app
Esempio n. 19
0
def create_app(test_config=None):  # 1)
    app = Flask(__name__)
    app_config = Config
    app.config.from_object(app_config)
    db.init_app(app)
    with app.app_context():
        db.create_all()

    @app.route("/test/insert-post", methods=["GET", "POST"])
    def add_post():
        py = Category(id=1, name="hennie")
        p = Post(title='Snakes2', body='Ssssssss2', category_id=py.id)
        # py.posts.append(p)
        db.session.add(p)
        db.session.commit()

        return "success"

    @app.route("/test/insert-category", methods=["GET"])
    def get_category():
        category1 = Category(id=6, name="checkcommit")
        db.session.add(category1)
        db.session.commit()

        return "success"

    @app.route("/test/get-all-post", methods=["GET"])
    def get_post():
        res1 = Post.query.all()
        res2 = Post.query.get(2)
        print(res2)
        return "success"

    # @app.route("/test/add" , methods=["GET"])
    # def add_user():
    #     User1 = User(username="******",email="pulovelty@nav" , password="******")
    #     User1.create()
    #     return "success"
    #
    #
    #
    #
    # @app.route("/test/get-all",methods=["GET"])
    # def get_users():
    #     res1= User.query.all()
    #
    #     return "success"
    #
    # @app.route("/test/get-detail",methods=["GET"])
    # def get_detail():
    #
    #     res1 = User.query.filter_by(id =2)
    #     print(res1 is None)
    #     for elm in res1:
    #         print(elm.username)
    #
    #     res2 = User.query.order_by(User.username).all()
    #     res3 = User.query.limit(1).all()
    #     res4 = User.query.get(2)
    #
    #     print("res2 :" , res2)
    #     print("res3 :" , res3)
    #     print("res4 : ", res4)
    #     return "success"
    #
    # @app.route('/test/user/<username>')
    # def show_user(username):
    #
    #     user = User.query.filter_by(username=username).all()
    #
    #     if len(user)==0:
    #         return "fail"
    #
    #     return "success"

    @app.route("/")
    def main():
        return "pong"

    return app
Esempio n. 20
0
@app.errorhandler(404)
def not_found(e):
	logging.error(e)
	return response_with(resp.SERVER_ERROR_404)

@app.route('/avatar/<filename>', methods=['GET'])
def uploaded_file(filename):
	return send_from_directory(app.config['UPLOAD_FOLDER'], filename)

# to use JWT for authorization
jwt = JWTManager(app)

mail.init_app(app)

db.init_app(app)
with app.app_context():
	db.create_all()

'''
def create_app(config):
	app = Flask(__name__)
	app.config.from_object(config)
	
	db.init_app(app)
	with app.app_context():
		db.create_all()
	return app
'''

Esempio n. 21
0
from api.utils.database import db
from api.routes.routes import limiter
from api.routes.routes import route_page
from flask import Flask
from api.utils.config import DevelopmentConfig, ProductionConfig

app = Flask(__name__)
app.config.from_object(DevelopmentConfig)
app.register_blueprint(route_page)

db.init_app(app)
db.app = app
db.create_all()

limiter.init_app(app)