def __init__(self, app): """Initialises the connection between RabbitMQ queue and Flask server, in order to get the objects waiting in Rabbit queue and put them in the database.""" Thread.__init__(self) self.connection_channel = False self.app = app self.handle_connection() self.database_handler = DatabaseHandler(self.app)
"""Handles the connection of flask and database""" from flask import Flask from flask import render_template from flask import request from threads.get_objects_from_rabbit import RabbitObjectHandler from files.configuration_handler import CreateConfiguration from files.read_configuration_handler import ReadHandler from database.database_handler import DatabaseHandler APP = Flask(__name__, template_folder="templates") CONFIG = CreateConfiguration() DATABASE_HANDLER = DatabaseHandler(APP) @APP.route('/') def main_page_route(): """Displays the main page and the types of information you can get the server to display.""" return render_template("main_page.html") @APP.route('/current_supported_metrics') def current_supported_metrics_route(): """Displays the currently supported metrics.""" return render_template("current_supported_metrics.html", metrics=READER.get_supported_metrics()) @APP.route('/packets')
def __init__(self, user: User, database_handler=None): # to set another user it can be accessed as calendar_user object attribute self.user = user self.database_handler: DatabaseHandler = database_handler if database_handler is not None else DatabaseHandler() # check connection to database here if not self.database_handler.check_connected(): print("Application not connected to database")
def __init__(self, user_admin: User, database_handler=None): if AccountType(user_admin.account_type) is not AccountType.Admin: raise CalendarAdmin.NotAdminUserException() self.user_admin = user_admin self.database_handler: DatabaseHandler = database_handler if database_handler is not None else DatabaseHandler( ) # check connection to database here if not self.database_handler.check_connected(): print("Application not connected to database")
def db_handler_obj() -> DatabaseHandler: handler = DatabaseHandler(new_name="testcalendar") handler._recreate_all_tables() yield handler handler.__del__()