def db(app, request): """ Returns session-wide initialised database. """ with app.app_context(): _db.drop_all() _db.create_all()
def db_create(login='******', password='******'): "Will create the database from conf parameters." admin = {'is_admin': True, 'is_api': True, 'login': login, 'password': password} with application.app_context(): db.create_all() UserController(ignore_context=True).create(**admin)
def db_create(): "Will create the database from conf parameters." admin = {'is_admin': True, 'is_api': True, 'is_active': True, 'nickname': 'admin', 'pwdhash': generate_password_hash( os.environ.get("ADMIN_PASSWORD", "password"))} with application.app_context(): db.create_all() UserController(ignore_context=True).create(**admin)
def db_create(login='******', password='******'): "Will create the database from conf parameters." admin = { 'is_admin': True, 'is_api': True, 'login': login, 'password': password } with application.app_context(): db.create_all() UserController(ignore_context=True).create(**admin)
def app(): app = Flask(__name__) with app.app_context(): app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db' app.config['TESTING'] = True app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False init_app(app) db.drop_all() db.create_all() client = app.test_client() yield client
def db_create(): "Will create the database from conf parameters." admin = { "is_admin": True, "is_api": True, "is_active": True, "nickname": "admin", "pwdhash": generate_password_hash(os.environ.get("ADMIN_PASSWORD", "password")), } with application.app_context(): db.create_all() UserController(ignore_context=True).create(**admin)
def db_create(): "Will create the database from conf parameters." admin = { 'is_admin': True, 'is_api': True, 'is_active': True, 'nickname': 'admin', 'pwdhash': generate_password_hash(os.environ.get("ADMIN_PASSWORD", "password")) } with application.app_context(): db.create_all() UserController(ignore_context=True).create(**admin)
def setUp(self): app.config.from_object('config.testing') db.create_all() self.app = app.test_client()
#!/usr/bin/env python from flask_admin import Admin from flask_admin.contrib.sqla import ModelView from flask.ext.cors import CORS from flask.ext import restless from bootstrap import db, app from models import * # Crear tablas db.create_all() # Crear manager API Rest manager = restless.APIManager(app, flask_sqlalchemy_db=db) # Crear endpoints manager.create_api(Task, methods=['POST', 'GET', 'DELETE', 'PUT']) manager.create_api(User) manager.create_api(Comment, methods=['POST', 'GET', 'PUT']) manager.create_api(Category) manager.create_api(Status) manager.create_api(Priority) #Crear Admin admin = Admin(app, name="Task Manager", template_mode="bootstrap3") #Agregar Vistas del Admin admin.add_view(ModelView(Task, db.session)) admin.add_view(ModelView(User, db.session)) admin.add_view(ModelView(Comment, db.session)) admin.add_view(ModelView(Category, db.session))
# create required paths on the file system if not os.path.exists(basedir): os.makedirs(basedir) os.makedirs(os.path.join(basedir, 'data')) os.makedirs(os.path.join(basedir, 'fitness')) os.makedirs(os.path.join(basedir, 'fitness', 'tmp')) # create database files open(basedir + 'entrance.db', 'w') open(basedir + 'entrance.dev.db', 'w') open(basedir + 'entrance.test.db', 'w') from bootstrap import db, all_attr from bootstrap.models import Client, User db.create_all() # initialize databases # register the Windows 10 Client application # to enable OAuth authentication windows_client = Client( name='entrance Windows 10 App', description='Windows 10 Client Application of entrance', client_id='voUmLYgFOE2GlNQqrcBelKEuSCGQ6zWQZVsPKZM9', client_secret='09Nlj1XI11MgTeJwOJ3Dmy48jZMVsWvgHSuTV03Xdl6dKYoDZs', is_confidential=True, _redirect_uris='/', _default_scopes='' ) db.session.add(windows_client) db.session.commit()
def setUp(self): iiumschedule.app.config['TESTING'] = True self.app = iiumschedule.app.test_client() db.create_all()
def __init__(self): db.create_all()
class CardItem(db.Model): id = db.Column(db.Integer, primary_key=True) card_id = db.Column(db.Integer, db.ForeignKey('card.id'), nullable=False) item_id = db.Column(db.Integer, db.ForeignKey('item.id'), nullable=False) row = db.Column(db.Integer, nullable=False) col = db.Column(db.Integer, nullable=False) card = relationship('Card', back_populates='card_items') item = relationship('Item') __table_args__ = ( UniqueConstraint( 'card_id', 'item_id', name='_card_item_uc'), # can only add an item once to a card UniqueConstraint( 'card_id', 'row', 'col', name='_card_position_uc'), # can only put one item in a position ) def __repr__(self): return str(self) def __str__(self): return f'{self.__class__.__name__}: {self.card_id} ({self.row},{self.col})' def __lt__(self, other): # ordering for 2x2 should be (0,0),(0,1),(1,0),(1,1) return self.card.rows * self.row + self.col < other.card.rows * other.row + other.col db.create_all(app=app)
def create_db(): db.create_all() return "Done"
def reset_db(): db.drop_all() db.create_all() return "Done"
from sqlalchemy.orm import sessionmaker from bootstrap import db from models import Author if __name__ == '__main__': engine = create_engine( 'postgresql+psycopg2://postgres:postgres@localhost:5432') conn = engine.connect() try: conn.execute("commit") conn.execute("drop database flask_rest") except Exception as other: print("Can't delete 'flask_rest' because of:", other) try: conn.execute("commit") conn.execute("create database flask_rest") except Exception as other: print("Can't create 'flask_rest' because of:", other) conn.close() from flask_sqlalchemy import SQLAlchemy db.create_all() authors = [Author(firstname='Max', lastname='Ramalho')] db.session.add_all(authors) db.session.commit() db.session.close()