コード例 #1
0
def create_app():
    app = Flask(__name__,
                instance_relative_config=True,
                static_folder='static')
    cred = credentials.Certificate(
        os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config',
                     'ServiceAccountkey.json'))
    app.config['BASE_DIR'] = os.path.dirname(os.path.abspath(__file__))
    if not config.DEBUG:
        app.config['SQLALCHEMY_DATABASE_URI'] = os.environ[
            'SQLALCHEMY_DATABASE_URI']
    elif config.ENV == 'LOCAL':
        app.config[
            'SQLALCHEMY_DATABASE_URI'] = 'postgresql://%(user)s:%(pw)s@%(host)s:%(port)s/%(db)s' % config.POSTGRES
    else:
        app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL']
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True

    init_dimen()

    with app.app_context():
        db.init_app(app)
        db.create_all()
        settings = Settings.init_setup()
        firebase_admin.initialize_app(
            cred, {
                'storageBucket': settings.firebaseStorageBucket,
                'databaseURL': settings.firebaseDatabaseURL
            })
    app.config['SECRET_KEY'] = settings.secretKey
    if Settings.environment[settings.appEnvironment] == 'Development':
        app.config['DEBUG'] = True
    else:
        app.config['DEBUG'] = False
    app.config["POSTS_PER_PAGE"] = config.POSTS_PER_PAGE
    CORS(app, resources={r"*": {"origins": "*"}})

    return app
コード例 #2
0
ファイル: api.py プロジェクト: Horiol/calsotchat
def create_app(address, **kwargs):
    app = Flask(__name__)

    db_path = os.path.expanduser(kwargs['data_folder'] + '/calsotchat.sqlite')
    logging.info(f'DB file -> sqlite:///{db_path}')
    app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{db_path}'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    cors = CORS(app, resources={r"/api*": {"origins": "*"}})

    db.init_app(app)

    with app.app_context():
        db.create_all()

        # Check if current user is created in db, otherwise create it
        my_contact = Contact.query.filter_by(address=address).first()
        if not my_contact:
            my_contact = Contact(nickname="", address=address, online=True)
            my_contact.save()
            logging.info("Local user created")
            myself = Myself(address=address, )
            myself.save()

        return app
コード例 #3
0
def create_app():
    # Create Flask Application
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'

    #Database set up stuff
    from backend.db import db
    from backend.models import Request, Edge
    db.app = app
    db.init_app(app)
    db.create_all()

    #Using apimanager for some blueprints
    from backend.api import apimanager
    apimanager.init_app(app, flask_sqlalchemy_db=db)

    #Turn on CORS permissively for now
    CORS(app)

    @app.route('/')
    def hello():
        return "Hello dank wizard"

    return app
コード例 #4
0
def clean_database():
    # Clean the session and all tables in the test database
    db.session.rollback()
    db.drop_all(bind=None)
    db.create_all(bind=None)
コード例 #5
0
ファイル: models.py プロジェクト: jplulu/ECE464-HospitalApp
        self.drug = drug
        self.date = date
        self.dosage = dosage
        self.status = status

    def serialize(self, user_type):
        payload = {
            "id": self.id,
            "drug": self.drug,
            "date": self.date.strftime("%Y-%m-%d"),
            "dosage": self.dosage,
            "status": self.status.name
        }

        if user_type == UserType.DOCTOR:
            payload['patient'] = self.patient.serialize()
        elif user_type == UserType.PATIENT:
            payload['doctor'] = self.doctor.serialize()
        else:
            payload['patient'] = self.patient.serialize()
            payload['doctor'] = self.doctor.serialize()

        return payload


if __name__ == "__main__":
    db.engine.execute("DROP DATABASE hospital;")
    db.engine.execute("CREATE DATABASE hospital;")
    db.engine.execute("USE hospital;")
    db.create_all()
コード例 #6
0
ファイル: app.py プロジェクト: jplulu/ECE464-HospitalApp
def create_table():
    db.create_all()
コード例 #7
0
ファイル: users.py プロジェクト: Daoortor/API_v4
 def find_by_id(value):
     db.create_all()
     return db.session.query(User).filter_by(id=value).first()
コード例 #8
0
ファイル: users.py プロジェクト: Daoortor/API_v4
 def find_by_username(value):
     db.create_all()
     return db.session.query(User).filter_by(username=value).first()