当前位置: 首页>>代码示例>>Python>>正文


Python flask_mongoengine.MongoEngine类代码示例

本文整理汇总了Python中flask_mongoengine.MongoEngine的典型用法代码示例。如果您正苦于以下问题:Python MongoEngine类的具体用法?Python MongoEngine怎么用?Python MongoEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MongoEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

    def setUp(self):
        super(BasicAppTestCase, self).setUp()
        db = MongoEngine()

        class Todo(db.Document):
            title = db.StringField(max_length=60)
            text = db.StringField()
            done = db.BooleanField(default=False)
            pub_date = db.DateTimeField(default=datetime.datetime.now)

        db.init_app(self.app)

        Todo.drop_collection()
        self.Todo = Todo

        @self.app.route('/')
        def index():
            return '\n'.join(x.title for x in self.Todo.objects)

        @self.app.route('/add', methods=['POST'])
        def add():
            form = flask.request.form
            todo = self.Todo(title=form['title'],
                             text=form['text'])
            todo.save()
            return 'added'

        @self.app.route('/show/<id>/')
        def show(id):
            todo = self.Todo.objects.get_or_404(id=id)
            return '\n'.join([todo.title, todo.text])

        self.db = db
开发者ID:adamchainz,项目名称:flask-mongoengine,代码行数:33,代码来源:test_basic_app.py

示例2: setUp

    def setUp(self):
        super(JSONAppTestCase, self).setUp()
        self.app.config['MONGODB_DB'] = 'testing'
        self.app.config['TESTING'] = True
        self.app.config['TEMP_DB'] = True
        db = MongoEngine()

        class Todo(db.Document):
            title = db.StringField(max_length=60)
            text = db.StringField()
            done = db.BooleanField(default=False)
            pub_date = db.DateTimeField(default=datetime.datetime.now)

        db.init_app(self.app)

        Todo.drop_collection()
        self.Todo = Todo

        @self.app.route('/')
        def index():
            return flask.jsonify(result=self.Todo.objects())

        @self.app.route('/add', methods=['POST'])
        def add():
            form = flask.request.form
            todo = self.Todo(title=form['title'],
                             text=form['text'])
            todo.save()
            return flask.jsonify(result=todo)

        @self.app.route('/show/<id>/')
        def show(id):
            return flask.jsonify(result=self.Todo.objects.get_or_404(id=id))

        self.db = db
开发者ID:adamchainz,项目名称:flask-mongoengine,代码行数:35,代码来源:test_json_app.py

示例3: setUp

 def setUp(self):
     super(JSONAppTestCase, self).setUp()
     self.app.config['MONGODB_DB'] = 'test_db'
     self.app.config['TESTING'] = True
     self.app.json_encoder = DummyEncoder
     db = MongoEngine()
     db.init_app(self.app)
     self.db = db
开发者ID:MongoEngine,项目名称:flask-mongoengine,代码行数:8,代码来源:test_json.py

示例4: get_db

def get_db(database=None):
    database = conf.MONGODB_DB
    mongo = MongoEngine()
    mongo.connect(
        database,
        host=conf.MONGODB_HOST,
        port=conf.MONGODB_PORT,
        username=conf.MONGODB_USER,
        password=conf.MONGODB_PASSWD
    )
    return mongo
开发者ID:zhy0216,项目名称:ezlog3,代码行数:11,代码来源:db.py

示例5: setup

def setup():
    app = Flask(__name__)
    app.config["SECRET_KEY"] = "1"
    app.config["CSRF_ENABLED"] = False
    app.config["MONGODB_SETTINGS"] = {"DB": "tests"}

    db = MongoEngine()
    db.init_app(app)

    admin = Admin(app)

    return app, db, admin
开发者ID:pombredanne,项目名称:pyramid-admin,代码行数:12,代码来源:__init__.py

示例6: create_app

def create_app():

    db = MongoEngine()
    app = Flask(__name__)
    app.config.from_object(Config)
    # flask_security config
    user_datastore = MongoEngineUserDatastore(db, Users, Roles)
    security = Security(app, user_datastore)

    # do some init
    db.init_app(app)
    create_user_role(user_datastore, db)
    return app
开发者ID:xinali,项目名称:penework,代码行数:13,代码来源:app.py

示例7: setUp

    def setUp(self):
        db = MongoEngine()
        app = Flask("corrdb")
        # app.config.MONGODB_SETTINGS = { 'db': 'corrdb', 'host': '0.0.0.0', 'port': 27017 }
        print(app.config.db)
        app.config.from_object({'db': 'corrdb', 'host': '0.0.0.0', 'port': 27017 })
        app.logger_name = "corrdb.app"

        # Flask-MongoEngine instance
        db.init_app(app)

        # Custom Converters
        app.url_map.converters['objectid'] = ObjectIDConverter

        app.run(debug='--no-debug', host='0.0.0.0', port=5000, threaded=True)
开发者ID:usnistgov,项目名称:corr,代码行数:15,代码来源:test_models.py

示例8: setUp

 def setUp(self):
     super(PaginationTestCase, self).setUp()
     self.db_name = 'test_db'
     self.app.config['MONGODB_DB'] = self.db_name
     self.app.config['TESTING'] = True
     self.app.config['CSRF_ENABLED'] = False
     self.db = MongoEngine()
     self.db.init_app(self.app)
开发者ID:MongoEngine,项目名称:flask-mongoengine,代码行数:8,代码来源:test_pagination.py

示例9: create_app

def create_app(app_name=None, blueprints=None):
    """Create the flask app."""
    if app_name is None:
        app_name = "cowrie_api"
    if blueprints is None:
        blueprints = DEFAULT_BLUEPRINTS

    app = Flask(app_name)

    configure_app(app)
    configure_logging(app)

    db = MongoEngine()
    db.app = app
    db.init_app(app)

    configure_blueprints(app, blueprints)

    return app
开发者ID:donthack-me,项目名称:donthackme_api,代码行数:19,代码来源:app.py

示例10: setUp

 def setUp(self):
     super(WTFormsAppTestCase, self).setUp()
     self.db_name = 'test_db'
     self.app.config['MONGODB_DB'] = self.db_name
     self.app.config['TESTING'] = True
     # For Flask-WTF < 0.9
     self.app.config['CSRF_ENABLED'] = False
     # For Flask-WTF >= 0.9
     self.app.config['WTF_CSRF_ENABLED'] = False
     self.db = MongoEngine()
     self.db.init_app(self.app)
开发者ID:MongoEngine,项目名称:flask-mongoengine,代码行数:11,代码来源:test_forms.py

示例11: test_live_connection

    def test_live_connection(self):
        db = MongoEngine()
        self.app.config['TEMP_DB'] = True
        self.app.config['MONGODB_SETTINGS'] = {
            'host' : 'localhost',
            'port' : 27017
        }
        class Todo(db.Document):
            title = db.StringField(max_length=60)
            text = db.StringField()
            done = db.BooleanField(default=False)

        db.init_app(self.app)
        Todo.drop_collection()

        # Test persist
        todo = Todo()
        todo.text = "Sample"
        todo.title = "Testing"
        todo.done = True
        s_todo = todo.save()

        f_to = Todo.objects().first()
        self.assertEqual(s_todo.title, f_to.title)
开发者ID:adamchainz,项目名称:flask-mongoengine,代码行数:24,代码来源:test_connection.py

示例12: test_connection_default

    def test_connection_default(self):
        self.app.config['MONGODB_SETTINGS'] = {}
        self.app.config['TESTING'] = True

        db = MongoEngine()
        db.init_app(self.app)

        self.app.config['TESTING'] = True
        db = MongoEngine()
        db.init_app(self.app)
开发者ID:adamchainz,项目名称:flask-mongoengine,代码行数:10,代码来源:test_basic_app.py

示例13: QuokkaDocument

        try:
            doc = self.get(*q_objs, **query)
            return doc, False
        except self._document.DoesNotExist:
            query.update(defaults)
            doc = self._document(**query)

            if auto_save:
                doc.save(write_options=write_options)
            return doc, True


class QuokkaDocument(Document):
    """Abstract document with extra helpers in the queryset class"""

    meta = {'abstract': True,
            'queryset_class': QuokkaQuerySet}


class QuokkaDynamicDocument(DynamicDocument):
    """Abstract Dynamic document with extra helpers in the queryset class"""

    meta = {'abstract': True,
            'queryset_class': QuokkaQuerySet}


db = MongoEngine()
db.ListField = ListField
db.Document = QuokkaDocument
db.DynamicDocument = QuokkaDynamicDocument
开发者ID:Madankapoor,项目名称:quokka,代码行数:30,代码来源:db.py

示例14: Flask

from flask_cors import CORS
from flask_mongoengine import MongoEngine
from flask_httpauth import HTTPBasicAuth


# Flask 实例
blog = Flask(__name__,
            instance_relative_config=True,
			static_folder = "../../dist/static",
			template_folder= "../../dist")

# auth
auth = HTTPBasicAuth()

# 载入配置
blog.config.from_object('config')
blog.config.from_pyfile('config.py')

# 允许跨域
cors = CORS(blog, resource={"/api/*": {"origins": "*"}})

# 数据库初始化
db = MongoEngine()
db.init_app(blog)

# 所有路由由 vue 接管
@blog.route("/", defaults={'path': ''})
@blog.route('/<path:path>')
def catch_all(path):
    return render_template("index.html")
开发者ID:huybery,项目名称:huybery-blog,代码行数:30,代码来源:__init__.py

示例15: Flask

from flask_sqlalchemy import SQLAlchemy
from flask_security import Security, SQLAlchemyUserDatastore, \
    UserMixin, RoleMixin, login_required, current_user
from flask_security.utils import encrypt_password
import flask_admin
from flask_admin.contrib import sqla
from flask_mongoengine import MongoEngine
from flask_admin.contrib.mongoengine import ModelView
from flask_admin import helpers as admin_helpers
# Create Flask application
app = Flask(__name__)
app.config.from_pyfile('config.py')
# Creamos modelo relacional
db = SQLAlchemy(app)
#Creamos modelo
dbm = MongoEngine()
dbm.init_app(app)


# Define models
roles_users = db.Table(
    'roles_users',
    db.Column('user_id', db.Integer(), db.ForeignKey('user.id')),
    db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))
)


class Role(db.Model, RoleMixin):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(80), unique=True)
    description = db.Column(db.String(255))
开发者ID:e-gob,项目名称:Notificaciones-SES,代码行数:31,代码来源:app.py


注:本文中的flask_mongoengine.MongoEngine类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。