Exemplo n.º 1
0
 def startdb(self):
     logging.info("Initializing database: Host=%s User=%s", config.dbhost,
                  config.dbuser)
     with app.app_context():
         db.init_app(app)
         db.create_all(app=app)
         InitRoles()
Exemplo n.º 2
0
def create_app(enviroment):
    app = Flask(__name__)

    app.config.from_object(enviroment)
    with app.app_context():
        db.init_app(app)
        db.create_all()
    return app
Exemplo n.º 3
0
    def setUp(self):
        db.create_all()

        # initialize 100 cards
        for x in range(0, 100):
            new_card = Card("card" + str(x))
            db.session.add(new_card)
        db.session.commit()
Exemplo n.º 4
0
def create_app_db(db, test_config=""):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)

    # load the instance config, if it exists, when not testing
    #app.config.from_pyfile('config.py', silent=True)
    if not test_config:
        app.config.from_object("config.DefaultConfig")
    else:
        app.config.from_object(test_config)
    #mail = Mail(app)

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

    #format database connection uri
    db_user = app.config['DB_USER']
    db_password = app.config['DB_PASSWORD']
    db_url = app.config['DB_URL']
    db_name = app.config['DB_NAME']

    #connect to database using flask's sql alchemy
    #sqlalchemyuri = f'postgresql://{db_user}:{db_password}@{db_url}/{db_name}'
    sqlalchemyuri = 'postgresql://' + db_user + ':' + db_password + '@' + db_url + '/' + db_name
    app.config['SQLALCHEMY_DATABASE_URI'] = sqlalchemyuri

    #bind datbase to this app
    db.init_app(app)
    app.app_context().push()

    #initialize flask user for authentication
    #user_manager = UserManager(app, db, UserModel) #register_form=nameRegisterForm)
    user_manager = NameUserManager(app, db,
                                   UserModel)  #register_form=nameRegisterForm)

    #initialize database
    #try:
    #    db.drop_all()
    #except:
    #    print("couldn't drop")
    #    pass

    db.create_all()
    #addTransaction(db, 0)

    #add routes
    app.register_blueprint(login_routes)

    return app
Exemplo n.º 5
0
def initialize_db():
    with app.app_context():
        if not os.path.isfile("database.db"):
            db.create_all()
Exemplo n.º 6
0
        db.session.add(new_chat)
        db.session.commit()

        flash(f'Chat {chat_name} has been created successfully.',
              category='success')

        chat_created_message = Message(
            f'{user_in_db.login} has created the chat.',
            datetime.now(),
            new_chat.id,
            author_id=0,
            author_login='******')
        new_chat.messages.append(chat_created_message)

        for member in new_chat.members:
            user_joined_message = Message(
                f'{member.login} has joined the chat.',
                datetime.now(),
                new_chat.id,
                author_id=0,
                author_login='******')
            new_chat.messages.append(user_joined_message)
        db.session.commit()

        return redirect(url_for('home'))


if __name__ == '__main__':
    db.create_all()
    app.run(debug=True)
Exemplo n.º 7
0
def home():
  db.create_all()
  return 'hellow world!'