def setUp(self): dbname = '%s.db' % str(uuid.uuid4()) self.dbpath = os.path.join(tempfile.gettempdir(), dbname) app = Flask(__name__) app.config['ORATOR_DATABASES'] = { 'test': { 'driver': 'sqlite', 'database': self.dbpath } } db = Orator(app) self.app = app self.db = db self.User = self.make_user_model() @app.route('/') def index(): return jsonify(self.User.order_by('id').paginate(5)) @app.route('/users', methods=['POST']) def create(): data = request.json user = self.User.create(**data) return jsonify(user) self.init_tables()
def app_init(appname): global db global app app = Flask(appname) app.config['ORATOR_DATABASES'] = load_db_config() app.config['ORATOR_DATABASES']['default'] = FLASK_ENV db = Orator(app) return app
ORATOR_DATABASES = { 'default': 'twittor', 'twittor': { 'driver': 'sqlite', 'database': os.path.join(os.path.dirname(__file__), 'twittor.db'), 'log_queries': True } } SECRET_KEY = '4K5UA6+BMeyNPgYxhjFU03dYA1NlDGrf3wRr8uOcIHU=' # Creating Flask application app = Flask(__name__) app.config.from_object(__name__) # Initializing Orator db = Orator(app) # Models class User(db.Model): __fillable__ = ['name', 'email'] __hidden__ = ['pivot'] @has_many def messages(self): return Message @belongs_to_many('followers',
from flask_mongoengine import MongoEngine from flask_orator import Orator mongo = MongoEngine() ora = Orator()
from flask import Flask from flask_orator import Orator from config import config from flask_bootstrap import Bootstrap db = Orator() bootstrap = Bootstrap() def create_app(config_name='develop'): app = Flask(__name__) app.config.from_object(config[config_name]) app.jinja_env.auto_reload = True db.init_app(app) bootstrap.init_app(app) from .mian_views import main as main_blueprint app.register_blueprint(main_blueprint) from .filter import register_template_filter register_template_filter(app) return app