Python flask_mongoengine.MongoEngine() Examples
The following are 3
code examples of flask_mongoengine.MongoEngine().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask_mongoengine
, or try the search function
.
Example #1
Source File: admin.py From SmartProxyPool with MIT License | 5 votes |
def init_app(app): admin = flask_admin.Admin(app=app, name='ProxyPool Admin', base_template="admin/master_base.html", index_view=ProxyPoolAdminIndexView(), template_mode='bootstrap3') admin.add_view(ProxyView(ProxyModel)) admin.add_view(SettingView(SettingModel)) # admin.add_view(ProxyPoolView(ProxyPoolModel)) admin.add_view(FetcherView(FetcherModel)) db = MongoEngine() db.init_app(app) user_datastore = MongoEngineUserDatastore(db, User, Role) init_security(user_datastore, app, admin) init_base_data(user_datastore, app)
Example #2
Source File: conftest.py From flask-security with MIT License | 4 votes |
def mongoengine_setup(request, app, tmpdir, realdburl): from flask_mongoengine import MongoEngine from mongoengine.fields import ( BooleanField, DateTimeField, IntField, ListField, ReferenceField, StringField, ) db_name = "flask_security_test_%s" % str(time.time()).replace(".", "_") app.config["MONGODB_SETTINGS"] = { "db": db_name, "host": "mongomock://localhost", "port": 27017, "alias": db_name, } db = MongoEngine(app) class Role(db.Document, RoleMixin): name = StringField(required=True, unique=True, max_length=80) description = StringField(max_length=255) permissions = StringField(max_length=255) meta = {"db_alias": db_name} class User(db.Document, UserMixin): email = StringField(unique=True, max_length=255) fs_uniquifier = StringField(unique=True, max_length=64, required=True) username = StringField(unique=True, required=False, sparse=True, max_length=255) password = StringField(required=False, max_length=255) security_number = IntField(unique=True, required=False, sparse=True) last_login_at = DateTimeField() current_login_at = DateTimeField() tf_primary_method = StringField(max_length=255) tf_totp_secret = StringField(max_length=255) tf_phone_number = StringField(max_length=255) us_totp_secrets = StringField() us_phone_number = StringField(max_length=255) last_login_ip = StringField(max_length=100) current_login_ip = StringField(max_length=100) login_count = IntField() active = BooleanField(default=True) confirmed_at = DateTimeField() roles = ListField(ReferenceField(Role), default=[]) meta = {"db_alias": db_name} def tear_down(): with app.app_context(): User.drop_collection() Role.drop_collection() db.connection.drop_database(db_name) request.addfinalizer(tear_down) return MongoEngineUserDatastore(db, User, Role)
Example #3
Source File: __init__.py From vulyk with BSD 3-Clause "New" or "Revised" License | 4 votes |
def init_app(name): """ :param name: application alias :type name: str :return: Bootstrapped cached application instance :rtype: flask.Flask """ key = 'app' if not hasattr(init_app, key): app = flask.Flask(name) app.config.from_object('vulyk.settings') try: app.config.from_object('local_settings') except ImportError: pass app.template_folder = app.config.get('TEMPLATES_FOLDER', 'templates') app.static_folder = app.config.get('STATIC_FOLDER', 'static') _logging.init_logger(app=app) app.logger.info('STARTING.') db = MongoEngine(app) app.logger.debug('Database is available at %s:%s', app.config['MONGODB_SETTINGS'].get('HOST', 'localhost'), app.config['MONGODB_SETTINGS'].get('PORT', 27017)) _assets.init(app) _social_login.init_social_login(app, db) if app.config.get('ENABLE_ADMIN', False): from . import _admin app.admin = _admin.init_admin(app) _blueprints.init_blueprints(app) setattr(init_app, key, app) app.logger.info('Vulyk bootstrapping complete.') return getattr(init_app, key) # endregion Init