示例#1
0
def db(app, request):
    """Session-wide test database."""
    def teardown():
        _db.drop_all()

    _db.app = app
    _db.create_all()

    request.addfinalizer(teardown)
    return _db
示例#2
0
def initdb():
    from website.models import db, User
    db.drop_all()
    db.create_all()
    db.session.add(
        User(username='******',
             password=bcrypt.hashpw('admin'.encode('utf8'), bcrypt.gensalt())))
    db.session.add(
        User(username='******',
             password=bcrypt.hashpw('user'.encode('utf8'), bcrypt.gensalt())))
    db.session.commit()
示例#3
0
def create_app(test_config=None):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        SECRET_KEY='dev',
        DATABASE=os.path.join(app.instance_path, 'myCodeWars.sqlite'),
    )
    app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(
        app.instance_path, 'myCodeWars.sqlite')
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    # Importing configurations and blueprints
    from website.models import db
    db.init_app(app)
    with app.app_context():
        if not os.path.isfile(app.config['DATABASE']):
            from website.models import User, Exercise
            db.create_all()
            admin_user = User(username="******",
                              password=generate_password_hash("admin"))
            db.session.add(admin_user)
            db.session.commit()

    from . import auth, user, exercises
    app.register_blueprint(auth.bp)
    app.register_blueprint(user.bp)
    app.register_blueprint(exercises.bp)

    @app.route('/')
    def index():
        return redirect(url_for("user.main_page"))

    return app
示例#4
0
def initdb():
    from website.models import db
    db.create_all()
示例#5
0
文件: app.py 项目: UTSA-ICS/galahad
def initdb():
    db.create_all()
    print('WAT: db created')
__author__ = 'isak.johansson'

from website.models import db
from website.models import Guest
db.create_all()


class Booking:
    def __init__(self, date, time):
        self.number_of_tables = 3
        self.date = date
        self.time = time
        self.occupied_times = []
        self.available_times = []
        self.eligible_times = ['17:00', '17:15', '17:30', '17:45', '18:00', '18:15', '18:30', '18:45', '19:00', '19:15',
                               '19:30', '19:45', '20:00', '20:15', '20:30', '20:45', '21:00', '21:15', '21:30', '21:45',
                               '22:00', '22:15', '22:30', '22:45', '23:00', '23:15', '23:30', '23:45', '24:00']

    def time_index(self, time):
        return self.eligible_times.index(time)

    def booked_tables(self):

        guests = Guest.query.filter_by(date=self.date).all()
        
        for guest in guests:
            
            self.occupied_times.append(guest.time)

    def available_tables(self):
        
示例#7
0
def initdb():
  db.create_all()
示例#8
0
def initdb():
    """ Create database """
    db.create_all()
    # posts = buildPosts()
    print('Successful')
示例#9
0
def create_db():
  if not exists("data"):
    mkdir("data")

  with app.app_context():
    db.create_all()
示例#10
0
def init_db():
    from website.models import db

    db.create_all()
示例#11
0
def initdb():
    """
    数据库初始化
    """
    from website.models import db
    db.create_all()
示例#12
0
def initialize_database(app):
    from website.models import db
    with app.app_context():
        db.create_all()