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


Python mongoengine.MongoEngine类代码示例

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


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

示例1: setUp

    def setUp(self):
        app = flask.Flask(__name__)
        app.config['MONGODB_DB'] = 'testing'
        app.config['TESTING'] = True
        db = MongoEngine()
        self.Todo = make_todo_model(db)

        db.init_app(app)

        self.Todo.drop_collection()

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

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

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

        self.app = app
        self.db = db
开发者ID:DYFeng,项目名称:flask-mongoengine,代码行数:30,代码来源:tests.py

示例2: setUp

    def setUp(self):
        super(JSONAppTestCase, self).setUp()
        self.app.config['MONGODB_DB'] = 'testing'
        self.app.config['TESTING'] = 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:mtsgrd,项目名称:flask-mongoengine,代码行数:34,代码来源:test_json_app.py

示例3: 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:brunobelarmino,项目名称:flask-mongoengine,代码行数:33,代码来源:test_basic_app.py

示例4: setUp

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

示例5: setUp

    def setUp(self):
        app = flask.Flask(__name__)
        app.config['MONGODB_DB'] = 'testing'
        app.config['TESTING'] = True
        app.json_encoder = DummyEncoder
        db = MongoEngine()
        db.init_app(app)

        self.app = app
        self.db = db
开发者ID:andrewelkins,项目名称:flask-mongoengine,代码行数:10,代码来源:test_json.py

示例6: test_connection_kwargs_with_false_values

 def test_connection_kwargs_with_false_values(self):
     self.app.config['MONGODB_SETTINGS'] = {
         'DB': 'testing',
         'alias': 'test',
         'use_greenlets': False
     }
     self.app.config['TESTING'] = True
     db = MongoEngine()
     db.init_app(self.app)
     self.assertFalse(db.connection.use_greenlets)
开发者ID:AlmogCohen,项目名称:flask-mongoengine,代码行数:10,代码来源:test_json_app.py

示例7: 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:hellwen,项目名称:pyservice,代码行数:12,代码来源:__init__.py

示例8: get_db

def get_db(database=None):
    if not database:
        database = conf.MONGODB_DB
    if os.environ.get("UNITTEST_MODE"):
        database = conf.MONGODB_DB_UNITTEST
    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-collection,项目名称:ezlog2,代码行数:14,代码来源:db.py

示例9: test_connection_kwargs_as_list

 def test_connection_kwargs_as_list(self):
     self.app.config['MONGODB_SETTINGS'] = [{
         'DB': 'testing_tz_aware',
         'alias': 'tz_aware_true',
         'TZ_AWARE': True
     }, {
         'DB': 'testing_tz_aware_off',
         'alias': 'tz_aware_false',
         'TZ_AWARE': False
     }]
     self.app.config['TESTING'] = True
     db = MongoEngine()
     db.init_app(self.app)
     self.assertTrue(db.connection['tz_aware_true'].tz_aware)
     self.assertFalse(db.connection['tz_aware_false'].tz_aware)
开发者ID:871392231,项目名称:flask-mongoengine,代码行数:15,代码来源:test_basic_app.py

示例10: setUp

 def setUp(self):
     super(PaginationTestCase, self).setUp()
     self.db_name = 'testing'
     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:pawl,项目名称:flask-mongoengine,代码行数:8,代码来源:test_pagination.py

示例11: test_connection_kwargs

    def test_connection_kwargs(self):
        app = flask.Flask(__name__)
        app.config['MONGODB_SETTINGS'] = {
            'DB': 'testing_tz_aware',
            'alias': 'tz_aware_true',
            'TZ_AWARE': True,
        }
        app.config['TESTING'] = True
        db = MongoEngine()
        db.init_app(app)
        self.assertTrue(db.connection.tz_aware)

        app.config['MONGODB_SETTINGS'] = {
            'DB': 'testing',
            'alias': 'tz_aware_false',
        }
        db.init_app(app)
        self.assertFalse(db.connection.tz_aware)
开发者ID:Frozen,项目名称:flask-mongoengine,代码行数:18,代码来源:test_basic_app.py

示例12: setUp

 def setUp(self):
     super(WTFormsAppTestCase, self).setUp()
     self.db_name = 'testing'
     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:brunobelarmino,项目名称:flask-mongoengine,代码行数:11,代码来源:test_forms.py

示例13: __init__

 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     # Support objectid in url routing
     self.url_map.converters['objectid'] = ObjectIdConverter
     # Custom json encoder for objectid and pagination
     # Mix between flask's root_path (module's path) and running dir path
     self.root_path = abspath(dirname(__file__) + '/..')
     # Overload default request to return 400 if no payload is provided
     self.request_class = JsonRequest
     self.json_encoder = dynamic_json_encoder_factory()
     restful.representations.json.settings['cls'] = self.json_encoder
     self.db = MongoEngine()
     self.solr = Solr()
开发者ID:Scille,项目名称:kalon,代码行数:13,代码来源:core_app.py

示例14: create_app

def create_app():
    app = Flask(__name__, static_folder='../public/', static_url_path='/public')
    app.response_class = ResponseJSON
    app.config.from_pyfile(config.FLASK_CONFIG_PATH)

    # change debug output formatter to a pretty one-liner
    format = Formatter("%(levelname)6s | %(relativeCreated)6d | %(filename)s:%(lineno)d | %(message)s")
    app.logger.handlers[0].setFormatter(format)

    # resolve paths relative to this file
    app_path = path.dirname(__file__)
    app.config.update({
        'RECORDINGS_PATH': path.realpath(app_path + '/../public/recordings/'),
        'PATH_USER_PROFILE_IMAGE': path.realpath(app_path + '/../public/profile_images/'),
        'PATH_ASSETS': path.realpath(app_path + '/../public/assets/'),
        'PATH_PUBLIC': path.realpath(app_path + '/../public/'),
    })

    # sanity checks
    if not path.isdir(app.config['RECORDINGS_PATH']):
        raise Exception("Recordings path does not exist: " + app.config['RECORDINGS_PATH'])

    if not path.isdir(app.config['PATH_USER_PROFILE_IMAGE']):
        raise Exception("User profile images path does not exist: " + app.config['PATH_USER_PROFILE_IMAGE'])

    # app.json_encoder = MongoJsonEncoder

    # setup database and session storage
    # db settings come from flask.ini
    # and same engine is used for storing sessions
    mongo = MongoEngine()
    mongo.init_app(app)
    app.session_interface = MongoEngineSessionInterface(mongo)

    # toolbar = DebugToolbarExtension(app)

    return app, mongo
开发者ID:halfvector,项目名称:quips-python,代码行数:37,代码来源:services.py

示例15: CoreApp

class CoreApp(Flask):
    """
    CoreApp is a regular :class:`Flask` app with cors, flask-principal,
    "restfulness" flavors
    """

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Support objectid in url routing
        self.url_map.converters['objectid'] = ObjectIdConverter
        # Custom json encoder for objectid and pagination
        # Mix between flask's root_path (module's path) and running dir path
        self.root_path = abspath(dirname(__file__) + '/..')
        # Overload default request to return 400 if no payload is provided
        self.request_class = JsonRequest
        self.json_encoder = dynamic_json_encoder_factory()
        restful.representations.json.settings['cls'] = self.json_encoder
        self.db = MongoEngine()
        self.solr = Solr()

    def bootstrap(self):
        """
        Initialize modules needing configuration

        :example:

            >>> app = CoreApp("my-app")
            >>> app.config['MY_CONF'] = 'DEFAULT_VALUE'
            >>> app.bootstrap()
        """
        # Principal and CORS support must be initialized at bootstrap time
        # in order to have up-to-date config
        self._principal = Principal(self, use_sessions=False)
        self._cors = cors.CORS(self)
        self.db.init_app(self)
        self.solr.init_app(self)
开发者ID:Scille,项目名称:kalon,代码行数:36,代码来源:core_app.py


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