Пример #1
0
def create_app(config=DevelopmentConfig):
    app = Flask(__name__)
    migrate = Migrate(app, db)
    csrf = CSRFProtect(app)
    app.config.from_object(config)
    login_manager = LoginManager()
    login_manager.login_view = 'auth.login'

    login_manager.init_app(app)
    db.init_app(app)
    ma.init_app(app)
    csrf.init_app(app)

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

    # register each active blueprint
    for url, blueprint in ACTIVE_ENDPOINTS:
        app.register_blueprint(blueprint, url_prefix=url)

    @login_manager.user_loader
    def load_user(user_id):
        return User.query.get(int(user_id))

    @app.route('/spec')
    def spec():
        swag = swagger(app)
        swag['info']['version'] = "1.0.0"
        swag['info']['title'] = "pygroup-Web"
        swag['info']['description'] = "My shop example using Flask"
        return jsonify(swag)

    app.register_blueprint(swagger_blueprint, url_prefix=SAWGGER_URL)

    return app
Пример #2
0
def create_app(config=DevelopmentConfig):
    app = Flask(__name__)
    migrate = Migrate(app, db)
    csrf = CSRFProtect(app)
    app.config.from_object(config)
    db.init_app(app)
    ma.init_app(app)
    csrf.init_app(app)

    with app.app_context():  #el contexto es la DB, el serializable
        db.create_all()

    for url, blueprint in ACTIVE_ENDPOINTS:
        app.register_blueprint(blueprint, url_prefix=url)
    return app
Пример #3
0
def create_app(config=DevelopmentConfig):
    app = Flask(__name__)
    migrate = Migrate(app, db)
    csrf = CSRFProtect(app)
    app.config.from_object(config)
    login_manager = LoginManager()
    login_manager.login_view = 'auth.login'
    login_manager.login_message = "Ingrese para acceder a esta pagina."

    login_manager.init_app(app)
    db.init_app(app)
    ma.init_app(app)
    csrf.init_app(app)
    migrate.init_app(app, db)

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

    # register each active blueprint
    for url, blueprint in ACTIVE_ENDPOINTS:
        app.register_blueprint(blueprint, url_prefix=url)

    @login_manager.user_loader
    def load_user(user_id):
        return User.query.get(int(user_id))

    # ruta principal de la pagina
    @app.route('/', methods=['GET'])
    def index():
        last_products = get_last_products()
        random_cat = get_random_categories()
        categories = get_all_categories()
        my_info = {
            "products": last_products,
            "random_cat": random_cat,
            "categories": categories
        }
        return render_template("index.html", my_info=my_info)

    # Varables globales para ser usadas en cualquier plantilla
    @app.context_processor
    def global_variables():
        categories = get_all_categories()
        basics = {"categories": categories}
        return dict(basics=basics)

    return app
Пример #4
0
def create_app(config=DevelopmentConfig):
    app = Flask(__name__)
    csrf = CSRFProtect(app)
    app.config.from_object(config)
    db.init_app(app)
    ma.init_app(app)
    csrf.init_app(app)

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

    # register each active blueprint
    for url, blueprint in ACTIVE_ENDPOINTS:
        app.register_blueprint(blueprint, url_prefix=url)

    csrf.exempt(products)
    return app
Пример #5
0
def create_app(name) -> Flask:
    app = Flask(name)
    app.config.from_object(get_config())

    db.init_app(app)
    ma.init_app(app)
    migrate = Migrate(app, db)
    api = Api(app, errors=errors)

    api.add_resource(GrabAndSave, "/grab_and_save")
    api.add_resource(Last, "/last")

    @app.cli.command("create-db")
    def create_db():
        db.create_all()

    return app
def create_app(config=DevelpmentConfig):
    app = Flask(__name__)
    migrate = Migrate(app, db)
    csrf = CSRFProtect(app)
    app.config.from_object(config)


    login_manager = LoginManager()
    login_manager.login_view = "auth.login"
    login_manager.init_app(app)
    
    db.init_app(app)
    ma.init_app(app)    
    csrf.init_app(app)
    migrate.init_app(app, db)
    
    @app.template_filter('datetimeformat')
    def datetimeformat(value, format="%Y"):
        return value.strftime(format)
    


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

    # register each active blueprint
    for url, blueprint in ACTIVE_ENDPOINTS:
        app.register_blueprint(blueprint, url_prefix=url)

    #This line disable csrf, I have a problem with addStock because it
    csrf.exempt(auth)
    @login_manager.user_loader
    def load_user(user_id):
        # since the user_id is just the primary key of our user table,
        # use it in
        # the query for the user
        return User.query.get(int(user_id))
    
    
    @login_manager.unauthorized_handler
    def unauthorized():
        # do stuff
        return redirect(url_for("products.catalog"))
    
    return app
Пример #7
0
def create_app(config=DevelopmentConfig):
    app = Flask(__name__)
    app.jinja_env.filters['zip'] = zip
    app.jinja_env.filters['len'] = len

    app.config.from_object(config)
    login_manager = LoginManager()
    csrf = CSRFProtect(app)
    migrate = Migrate(app)

    login_manager.init_app(app)
    db.init_app(app)
    ma.init_app(app)
    csrf.init_app(app)
    migrate.init_app(app, db=db)

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

    app.register_blueprint(swaggerui_blueprint)
    # register each active blueprint
    for url, blueprint in ACTIVE_ENDPOINTS:
        app.register_blueprint(blueprint, url_prefix=url)

    login_manager.login_view = "userBp.login"

    def login_required(f):
        @wraps(f)
        def wrap(*args, **kwargs):
            if 'logged_in' in session:
                return f(*args, **kwargs)
            else:
                flash("Primero debes inicicar sesion")
                return redirect(url_for('userBp.login'))

        return wrap

    @app.route("/")
    def redirect_home():
        if current_user.is_anonymous:
            return redirect(url_for('store.home_page'))
        else:
            if str(current_user.id).isalpha():
                return redirect(url_for('adminBp.admin_panel'))
            else:
                return redirect(url_for('store.home_page'))

    @login_manager.user_loader
    def load_user(user_id):
        if user_id.isdigit():
            return User.query.get(int(user_id))
        elif user_id.isalpha():
            return AdminUser.query.filter_by(id=user_id).first()

    @app.route("/spec")
    def spec():
        swag = swagger(app)
        swag['info']['version'] = "1.0"
        swag['info']['title'] = "CompuTech Store"
        swag['info']['Description'] = "A cool technology store"
        swag['tags'] = [{
            "name": "store",
            "description": "only the home page"
        }, {
            "name":
            "products",
            "description":
            "Everything related to the handling and presentation of the products "
        }]
        return jsonify(swag)

    return app