from flask import Flask
import json
from config import config as configs
from flask_elasticsearch import FlaskElasticsearch

from dmutils.flask import DMGzipMiddleware
from dmutils.flask_init import init_app, api_error_handlers

elasticsearch_client = FlaskElasticsearch()


def get_service_by_name_from_vcap_services(vcap_services, name):
    """Returns the first service from a VCAP_SERVICES json object that has name"""
    for services in vcap_services.values():
        for service in services:
            if service['name'] == name:
                return service

    raise RuntimeError(f"Unable to find service with name {name} in VCAP_SERVICES")


def create_app(config_name):
    application = Flask(__name__)

    init_app(
        application,
        configs[config_name],
        error_handlers=api_error_handlers,
    )

    if application.config['VCAP_SERVICES']:
Exemple #2
0
#Redis
app.config["REDIS_URL"] = "redis://127.0.0.1:6379/0"
app.config["ELASTICSEARCH_HOST"] = "47.52.0.90:9200"



# 开启调试模式
app.debug = False
app.use_reloader=False


# 实例化对象
db = SQLAlchemy(app)
redis = FlaskRedis(app)
es = FlaskElasticsearch(app)
scheduler = APScheduler()


# 导入蓝图模块 # 不要在生成db之前导入注册蓝图。
from app.home import home as home_blueprint

# 注册蓝图
app.register_blueprint(home_blueprint)



# 404 错误页面
@app.errorhandler(404)
def page_not_found(error):
    return render_template("home/404.html")  # 搜索页面
Exemple #3
0
def register_es(app: Flask) -> Flask:
    from flask_elasticsearch import FlaskElasticsearch
    app.es = FlaskElasticsearch(app)
    return app
Exemple #4
0
from flask_redis import FlaskRedis
from flask_elasticsearch import FlaskElasticsearch
from sqlalchemy import create_engine

from app.config import get_env_var, DefaultConfig, TestConfig

app = Flask(__name__)
if get_env_var("TESTING", False):
    app.config.from_object(TestConfig)
else:
    app.config.from_object(DefaultConfig)

app.debug = bool(get_env_var("DEBUG", "True"))

db = SQLAlchemy(app)
es = FlaskElasticsearch(app)
try:
    es.ping()
except TypeError:
    es = None
redis_store = FlaskRedis(app)
engine = create_engine(app.config["SQLALCHEMY_DATABASE_URI"], echo=False)

try:
    from flask_debugtoolbar import DebugToolbarExtension

    toolbar = DebugToolbarExtension(app)
except ImportError:
    DebugToolbarExtension = None
    toolbar = None
Exemple #5
0
Copyright (c) 2017, Ernesto Ruge
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""

from flask_mongoengine import MongoEngine

db = MongoEngine()

from flask_elasticsearch import FlaskElasticsearch

es = FlaskElasticsearch()

# Flask-Login
from flask_login import LoginManager

login_manager = LoginManager()

# Flask-WTF csrf protection
from flask_wtf.csrf import CSRFProtect

csrf = CSRFProtect()

# Flask-Mail
from flask_mail import Mail

mail = Mail()
Exemple #6
0
def setup_elasticsearch(app):
    es = FlaskElasticsearch()
    es.init_app(app)
    return es
Exemple #7
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: LonJE

from flask import Flask
from flask_elasticsearch import FlaskElasticsearch

app = Flask(__name__)
app.config.from_object('config')

es = FlaskElasticsearch(app, timeout=1000)

__import__('app.views')
Exemple #8
0
 """
from flask_cors import CORS
from flask_elasticsearch import FlaskElasticsearch
from flask_jwt_extended import JWTManager
from flask_mail import Mail
from flask_sqlalchemy import SQLAlchemy
from flask_principal import Principal
from alexandria.modules.utils.vendor.flask_restplus_patched import Api
from flask_babel import Babel
from flask_migrate import Migrate
# from flask_caching import Cache
from flask_rq2 import RQ
from flask_uploads import IMAGES, UploadSet

__author__ = 'oclay'

es = FlaskElasticsearch(using='default')
db = SQLAlchemy()
api = Api(prefix='/api', doc='/api/doc', ui=False, title='Alexandria API')
jwt = JWTManager()
rq = RQ()
principal = Principal()
mail = Mail()
migrate = Migrate()
babel = Babel()
# cache = Cache()
corsd = CORS()
document_file = UploadSet('documents', ('pdf',))
thumbnail_image = UploadSet('thumbnails', IMAGES)
profile_image = UploadSet('profiles', IMAGES)
Exemple #9
0
from flask import Flask
from flask_elasticsearch import FlaskElasticsearch
import json

es = FlaskElasticsearch()
app = Flask(__name__)
es.init_app(app)


@app.route('/')
def search():
    with app.app_context():
        return json.dump(es.search(index="mbdb",
                                   body={"query": {
                                       "match_all": {}
                                   }}),
                         indent=4)