def create_app(test_config=None): """Construct the core application.""" # Create the Flask app object. app = Flask(__name__) data_path = "movie/datafiles/Data1000Movies.csv" if test_config is not None: # Load test configuration, and override any configuration settings. app.config.from_mapping(test_config) data_path = app.config['TEST_DATA_PATH'] # Create the MemoryRepository implementation for a memory-based repository. repo.repo_instance = MemoryRepository() populate(data_path, repo.repo_instance) # Build the application - these steps require an application context. with app.app_context(): # Register blueprints. from .home import home app.register_blueprint(home.home_blueprint) from .news import news app.register_blueprint(news.news_blueprint) return app
def create_app(test_config=None): """Construct the core application.""" # Create the Flask app object. app = Flask(__name__) # Configure the app from configuration-file settings. app.config.from_object('config.Config') data_path = os.path.join('movie', 'adapters', 'data') if test_config is not None: # Load test configuration, and override any configuration settings. app.config.from_mapping(test_config) data_path = app.config['TEST_DATA_PATH'] # Create the MemoryRepository implementation for a memory-based repository. repo.repo_instance = MemoryRepository() populate(data_path, repo.repo_instance) # Build the application - these steps require an application context. with app.app_context(): # Register blueprints. from .home import home app.register_blueprint(home.home_blueprint) from .articles import news app.register_blueprint(news.news_blueprint) from .authentication import authentication app.register_blueprint(authentication.authentication_blueprint) from .utilities import utilities app.register_blueprint(utilities.utilities_blueprint) return app
def create_app(): app = Flask(__name__) data_path = os.path.join('movie', 'adapters', 'data', 'Data1000Movies.csv') print(data_path) repo.repo_instance = MemoryRepository() populate(data_path, repo.repo_instance) @app.route("/") def index(): return "<h1>Welcome</h1> \n <h4><a href=/hello>Click me</a></h4>" @app.route("/hello/") def hello(): html_page = render_template( 'view_movies.html', name = repo.repo_instance.get_movies(), desc = repo.repo_instance.get_movies().description, direc = repo.repo_instance.get_movies().director, actor = repo.repo_instance.get_movies().actors, genre = repo.repo_instance.get_movies().genres ) return html_page return app
def create_app(test_config: dict = None): app = Flask(__name__) app.config.from_object('config.Config') app.config['MOVIE_DATA_PATH'] = os.path.join('movie', 'adapters', 'datafiles', MOVIE_DATA_FILE) app.config['USER_DATA_PATH'] = os.path.join('movie', 'adapters', 'datafiles', USER_DATA_FILE) app.config['REVIEW_DATA_PATH'] = os.path.join('movie', 'adapters', 'datafiles', REVIEW_DATA_FILE) if test_config: app.config.from_mapping(test_config) app.config['MOVIE_DATA_PATH'] = app.config['TEST_MOVIE_DATA_PATH'] app.config['MOVIE_DATA_PATH'] = app.config['TEST_USERS_DATA_PATH'] app.config['REVIEW_DATA_PATH'] = app.config['TEST_REVIEWS_DATA_PATH'] movie_data_path = app.config['MOVIE_DATA_PATH'] users_data_path = app.config['USER_DATA_PATH'] reviews_data_path = app.config['REVIEW_DATA_PATH'] repo.repo_instance = MemoryRepository() populate_movies(movie_data_path, repo.repo_instance) populate_users(users_data_path, repo.repo_instance) populate_reviews(reviews_data_path, repo.repo_instance) with app.app_context(): from .home import home app.register_blueprint(home.home_blueprint) from .movie import movie app.register_blueprint(movie.movie_blueprint) from .authentication import authentication app.register_blueprint(authentication.auth_blueprint) from .review import review app.register_blueprint(review.review_blueprint) return app
def create_app(test_config=None): """Construct the core application.""" # Create the Flask app object. app = Flask(__name__) # Configure the app from configuration-file settings. app.config.from_object('config.Config') data_path = os.path.join('movie', 'adapters', 'data') if test_config is not None: # Load test configuration, and overrride any configuration settings. app.config.from_mapping(test_config) data_path = app.config['TEST_DATA_PATH'] # Create the MemoryRepository implementation for a memory-based repository. repo.repo_instance = MemoryRepository() populate(data_path, repo.repo_instance) return app
def create_app(test_config=None): """Construct the core application.""" # Create the Flask app object. app = Flask(__name__) # Configure the app from configuration-file settings. app.config.from_object('config.Config') data_path = os.path.join('covid', 'adapters', 'data') if test_config is not None: # Load test configuration, and override any configuration settings. app.config.from_mapping(test_config) data_path = app.config['TEST_DATA_PATH'] repo.repo_instance = MemoryRepository() with app.app_context(): # Register blueprints. from .home import home app.register_blueprint(home.home_blueprint) return app
def test_in_memory_repo(): repo = MemoryRepository() memory_repository.populate(TEST_DATA_PATH, repo) return repo
def in_memory_repo(): repo = MemoryRepository() memory_repository.populate(MOVIE_DATA_PATH, repo) return repo
def populated_memory_repository(populated_movies, genres): repository = MemoryRepository() populate(repository, TEST_DATA_PATH_MEMORY, 123) return repository
def memory_repository(): return MemoryRepository()
def in_memory_repo(): repo = MemoryRepository() return repo
def create_app(test_config=None): """Construct the core application.""" # Create the Flask app object. app = Flask(__name__) # app.secret_key = '#%$sd4{?$$^44D73bd}]' # Configure the app from configuration-file settings. app.config.from_object('config.Config') data_path = os.path.join('movie', 'adapters', 'data') # if test_config is not None: # Load test configuration, and override any configuration settings. # app.config.from_mapping(test_config) # data_path = app.config['TEST_DATA_PATH'] if app.config['REPOSITORY'] == 'memory': # Create the MemoryRepository implementation for a memory-based repository. repo.repo_instance = MemoryRepository() populate(data_path, repo.repo_instance) elif app.config['REPOSITORY'] == 'database': # Configure database. database_uri = app.config['SQLALCHEMY_DATABASE_URI'] # We create a comparatively simple SQLite database, which is based on a single file (see .env for URI). # For example the file database could be located locally and relative to the application in covid-19.db, # leading to a URI of "sqlite:///covid-19.db". # Note that create_engine does not establish any actual DB connection directly! database_echo = app.config['SQLALCHEMY_ECHO'] database_engine = create_engine( database_uri, connect_args={"check_same_thread": False}, poolclass=NullPool, echo=database_echo) # test if app.config['TESTING'] == 'True' or len( database_engine.table_names()) == 0: print("REPOPULATING DATABASE") # For testing, or first-time use of the web application, reinitialise the database. clear_mappers() metadata.create_all( database_engine) # Conditionally create database tables. for table in reversed(metadata.sorted_tables ): # Remove any data from the tables. database_engine.execute(table.delete()) # Generate mappings that map domain model classes to the database tables. map_model_to_tables() database_repository.populate(database_engine, data_path) else: # Solely generate mappings that map domain model classes to the database tables. map_model_to_tables() # Create the database session factory using sessionmaker (this has to be done once, in a global manner) session_factory = sessionmaker(autocommit=False, autoflush=True, bind=database_engine) # Create the SQLAlchemy DatabaseRepository instance for an sqlite3-based repository. repo.repo_instance = database_repository.SqlAlchemyRepository( session_factory) # Build the application - these steps require an application context. with app.app_context(): # Register blueprints. from .home import home app.register_blueprint(home.home_blueprint) from .detail import detail app.register_blueprint(detail.detail_blueprint) from .authentication import authentication app.register_blueprint(authentication.authentication_blueprint) return app
def in_memory_repo(): repo = MemoryRepository() memory_repository.populate(TEST_DATA_PATH_MEMORY, repo) return repo
def create_app(test_config=None): """Construct the core application.""" # Create the Flask app object. app = Flask(__name__) # Configure the app from configuration-file settings. app.config.from_object('config.Config') data_path = os.path.join('movie', 'adapters', 'data') if test_config is not None: # Load test configuration, and override any configuration settings. app.config.from_mapping(test_config) data_path = app.config['TEST_DATA_PATH'] # base on the setup to create the repository if app.config['REPOSITORY'] == 'memory': repo.repo_instance = MemoryRepository() populate(data_path, repo.repo_instance) elif app.config['REPOSITORY'] == 'database': # Configure database. database_uri = app.config['SQLALCHEMY_DATABASE_URI'] # We create a comparatively simple SQLite database, which is based on a single file (see .env for URI). # For example the file database could be located locally and relative to the application in covid-19.db, # leading to a URI of "sqlite:///covid-19.db". # Note that create_engine does not establish any actual DB connection directly! database_echo = app.config['SQLALCHEMY_ECHO'] database_engine = create_engine( database_uri, connect_args={"check_same_thread": False}, poolclass=NullPool, echo=database_echo) if app.config['TESTING'] == 'True' or len( database_engine.table_names()) == 0: print("REPOPULATING DATABASE") # For testing, or first-time use of the web application, reinitialise the database. clear_mappers() metadata.create_all( database_engine) # Conditionally create database tables. for table in reversed(metadata.sorted_tables ): # Remove any data from the tables. database_engine.execute(table.delete()) # Generate mappings that map domain model classes to the database tables. map_model_to_tables() database_repository.populate(database_engine, data_path) else: # Solely generate mappings that map domain model classes to the database tables. map_model_to_tables() # Create the database session factory using sessionmaker (this has to be done once, in a global manner) session_factory = sessionmaker(autocommit=False, autoflush=True, bind=database_engine) # Create the SQLAlchemy DatabaseRepository instance for an sqlite3-based repository. repo.repo_instance = database_repository.SqlAlchemyRepository( session_factory) # Build the application - these steps require an application context. with app.app_context(): # Register blueprints. from .home import home app.register_blueprint(home.home_blueprint) # from .movies import movies app.register_blueprint(movies.movie_blueprint) from .authentication import authentication app.register_blueprint(authentication.authentication_blueprint) # from .utilities import utilities # app.register_blueprint(utilities.utilities_blueprint) # Register a callback the makes sure that database sessions are associated with http requests # We reset the session inside the database repository before a new flask request is generated @app.before_request def before_flask_http_request_function(): if isinstance(repo.repo_instance, database_repository.SqlAlchemyRepository): repo.repo_instance.reset_session() # Register a tear-down method that will be called after each request has been processed. @app.teardown_appcontext def shutdown_session(exception=None): if isinstance(repo.repo_instance, database_repository.SqlAlchemyRepository): repo.repo_instance.close_session() return app