def init_database(): init_db() # Creating plans plans = [Plan("Free",False),Plan("Basic",False),Plan("Premium",True)] # Creating services services = [Service(name="Evernote"),Service(name="Onenote")] db_session.add_all(plans) db_session.add_all(services) db_session.commit() return jsonify(status="ok")
def save_data(data): init_db() request = Request() request.distance_imbalance = data['calculate'] user_location = Location() user_location.latitude = data['user_location']['latitude'] user_location.longitude = data['user_location']['latitude'] request.location = user_location request.radius = data['radius'] medical_centers = [ build_medical_center(medical_center, request) for medical_center in data['medical_centers'] ] request.medical_centers = medical_centers db_session.add(request) db_session.commit()
def create_app(settings=SQLALCHEMY_SETTINGS): logger.info("Connecting to DB") app = Flask(__name__) api = Api(app) app.config["SQLALCHEMY_DATABASE_URI"] = settings["SQLALCHEMY_DATABASE_URI"] app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = settings[ "SQLALCHEMY_TRACK_MODIFICATIONS"] with app.app_context(): database.init_db() Resources.load_resources(api) return app, database
def create_app(settings=SQLALCHEMY_SETTINGS): app = Flask(__name__) api = Api(app) logger.info("Connecting to the DB") app.config["SQLALCHEMY_DATABASE_URI"] = settings["SQLALCHEMY_DATABASE_URI"] app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = settings["SQLALCHEMY_TRACK_MODIFICATIONS"] with app.app_context(): from core import database database.init_db() # TODO Future improvement # yield app Resources.load_resources(api) return app, database
def create_app(): app = Flask(__name__) api = Api(app) logger.info("Connecting to the DB") app.config['SQLALCHEMY_DATABASE_URI'] = db_uri app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['ERROR_404_HELP'] = False with app.app_context(): from core import database database.init_db() # TODO Future improvement # yield app Resources.load_resources(api) return app
def create_app(config_filename): app = Flask(__name__) app.url_map.strict_slashes = False app.config.from_object(config_filename) from core.database import init_db, db_session init_db() from web.views.main import home_blueprint from web.views.user import user_blueprint from web.views.windfarm import windfarm_blueprint from web.views.maintenance import maintenance_blueprint from web.views.alerts import alerts_blueprint from web.views.settings import settings_blueprint from web.views.company import company_blueprint from web.views.authentication import authentication_blueprint from web.views.dashboard import dashboard_blueprint from web.views.data_exploration import data_exploration_blueprint app.register_blueprint(home_blueprint, url_prefix='/') app.register_blueprint(dashboard_blueprint, url_prefix='/dashboard') app.register_blueprint(windfarm_blueprint, url_prefix='/windfarm') app.register_blueprint(user_blueprint, url_prefix='/user') app.register_blueprint(authentication_blueprint, url_prefix='/auth') app.register_blueprint(company_blueprint, url_prefix='/company') app.register_blueprint(maintenance_blueprint, url_prefix='/maintenance') app.register_blueprint(alerts_blueprint, url_prefix='/alerts') app.register_blueprint(data_exploration_blueprint, url_prefix='/exploration') app.register_blueprint(settings_blueprint, url_prefix='/settings') @app.before_request def before_request(): # When you import jinja2 macros, they get cached which is annoying for local # development, so wipe the cache every request. if 'localhost' in request.host_url or '0.0.0.0' in request.host_url: app.jinja_env.cache = {} @app.teardown_appcontext def shutdown_session(exception=None): db_session.remove() @app.errorhandler(404) def render_404(e): response = ApiResponse( content_type=request.accept_mimetypes.best, context={'message': e.description}, template='404.html', status_code=404 ) return response() @app.errorhandler(401) def render_401(e): response = ApiResponse( content_type=request.accept_mimetypes.best, context={'message': e.description}, template='401.html', status_code=401 ) return response() @app.errorhandler(400) def render_400(e): response = ApiResponse( content_type=request.accept_mimetypes.best, context={'message': e.description}, template='400.html', status_code=400 ) return response() @app.errorhandler(500) def render_500(e): # We don't want to show internal exception messages... return render_template('500.html'), 500 app.json_encoder = CustomJSONEncoder # for folder in ['UPLOAD_ROOT_FOLDER', 'TEMPORARY_UPLOAD_FOLDER', 'TRAIN_ROOT_FOLDER', 'WINDFARM_CONFIGURATION_FOLDER']: # path = Path(app.config[folder]) # path.mkdir(parents=True, exist_ok=True) return app
def setUp(self): # Load tables schema & seed data database.init_db() database.load_fixtures()
def setUp(self): self._engine = database.init_engine(self.SQLALCHEMY_DATABASE_URI) # Load tables schema & seed data database.init_db() database.load_fixtures()
# ============ # # Products App # # ============ # from flask import Blueprint, render_template from core.database import init_db, db_session from products.models import Product products_app = Blueprint("products_app", __name__, template_folder="./templates", static_folder="./static", static_url_path='products/static') init_db() @products_app.route("/", methods=["GET"]) def show_products(): products = Product.query.all() template_path = "products/products.html" context = { "products": products, "products_page": True, } return render_template(template_path, **context) @products_app.route("/add_products", methods=["GET"]) def add_products(): db_session.add( Product('Computer', 15,
def initialize_database(): db_settings = database.Settings() database.create_database(db_settings, TEST_DB_NAME, delete=True) db_settings.database_name = TEST_DB_NAME database.init_db(db_settings)
def main(): if len(sys.argv) != 2: exit("Usage: {} <name>".format(sys.argv[0])) database.init_db(sys.argv[1])
async def initialize_database(): init_db() with get_db(): migrator.run()
def post(self): init_db() return dict(result="ok")