當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。