def new_user_view(): """ User is directed here if they selected that they are a new user to this system Here, they enter a username and password Those are stored in the database User is then redirected back to the main login page to login as an existing user :return: """ screen = curses.initscr() screen.clear() screen.addstr(5, 5, 'Enter Username:'******'Enter Password:'******' account created...') screen.refresh() time.sleep(2) dashboard_database.database_menu(username) else: # print "User already exists" screen.addstr(11, 5, 'Username ' + username + ' already exists...') screen.refresh() time.sleep(2) dashboard_program.main_menu()
def edit_selected_database_menu(username, database): screen = curses.initscr() screen.clear() screen.keypad(1) selection = -1 option = 0 while selection < 0: choices = [0] * 4 choices[option] = curses.A_REVERSE screen.addstr(1, 1, 'BACK TO MAIN MENU', curses.A_UNDERLINE | choices[0]) screen.addstr(3, 5, database, curses.A_BOLD | curses.A_UNDERLINE) screen.addstr(5, 5, 'What would you like to do in this database?', curses.A_BOLD | curses.A_UNDERLINE) screen.addstr(8, 5, 'Edit/View an Existing Table', choices[1]) screen.addstr(11, 5, 'Create a New Table', choices[2]) screen.refresh() action = screen.getch() if action == curses.KEY_UP: option = (option - 1) % 2 elif action == curses.KEY_DOWN: option = (option + 1) % 2 elif action == ord('\n'): selection = option if selection == 0: dashboard_database.database_menu(username) elif selection == 1: edit_table_view_selected_database(username, database) elif selection == 2: create_new_table(username, database)
def existing_user_view(): """ User is directed here if they choose that they are an existing user In this function, user enters a password and user name And these are validated through calls to the database. If they are acceptable, they enter the database viewer, if they are not, They are returned to the main menu :return: """ screen = curses.initscr() screen.clear() screen.addstr(5, 5, 'Enter Username:'******'Enter Password:'******'Logging you in...') screen.refresh() time.sleep(2) dashboard_database.database_menu(username) else: screen.addstr(11, 5, 'Invalid username/password. Try again...') screen.refresh() time.sleep(2) dashboard_program.main_menu()
def edit_database(username): """ User is taken here if they would like to edit an existing database All of the databases that are associated with the user's username Are displayed, and the user can scroll through the pick the database they would like to edit The database that they select is sent to edit_selected_database_menu() the username and database name are sent :param username: :return: """ screen = curses.initscr() screen.clear() screen.keypad(1) screen.addstr(3, 5, 'Choose a database to edit/view', curses.A_BOLD | curses.A_UNDERLINE) """ Here we query all the databases associated with this user And put all the names as elements of 'databases' variable Also, query the count of databases and save that as 'databases_count' """ #databases = display_databases(username) conn = connect_to_db('postgres', 'postgres') cursor = conn.cursor() # check for duplicate database name find_query = "SELECT datname FROM pg_catalog.pg_database d WHERE pg_catalog.pg_get_userbyid(d.datdba) = %s;" cursor.execute(find_query, (username,)) length = cursor.rowcount databases = [] for db_name in cursor: databases.append(db_name[0]) selection = -1 option = 0 selected_database = None while selection < 0: choices = [0] * (length + 1) choices[option] = curses.A_REVERSE screen.addstr(1, 1, 'BACK TO MAIN MENU', choices[0]) screen.addstr(1, 23, 'length: ' + str(length)) y = 5 i = 1 for db in databases: screen.addstr(y, 5, db, choices[i]) i += 1 y += 3 screen.refresh() action = screen.getch() if action == curses.KEY_UP: option = (option - 1) % (length + 1) elif action == curses.KEY_DOWN: option = (option + 1) % (length + 1) elif action == ord('\n'): selection = option screen.addstr(19, 5, 'option: ' + str(option)) screen.addstr(20, 5, 'selection: ' + str(selection)) screen.refresh() if selection == 0: dashboard_database.database_menu(username) selected_database = databases[selection] edit_selected_database_menu(username, selected_database)
def edit_table_view_selected_database(username, database): """ This is a poorly named function User is brought here if they selected that they wanted to edit an existing database It pulls all the tables that are in that database and that are associated the username User then selected a table from that list This table, the username, and database is sent to tableOptions.py tableOptions() :param username: :param selected_database: :return: """ screen = curses.initscr() screen.clear() screen.keypad(1) """ Here we query all the tables associated with this user and this database And put all the names as elements of 'tables' variable (instead of the hardcoded testing elements) Also, query the count of tables and save that as 'tables_count' """ tables = ['name1', 'name2', 'name3', 'name4'] tables_count = 4 selection = -1 option = 0 screen.addstr(3, 5, 'Choose a table to edit/view', curses.A_BOLD | curses.A_UNDERLINE) selected_table = None while selection < 0: y = 5 i = 0 choices = [0] * (tables_count + 1) choices[option] = curses.A_REVERSE screen.addstr(1, 1, 'BACK TO MAIN MENU', curses.A_UNDERLINE | choices[0]) for name in tables: screen.addstr(y, 5, name, choices[i]) i += 1 y += 3 screen.refresh() action = screen.getch() if action == curses.KEY_UP: option = (option - 1) % tables_count elif action == curses.KEY_DOWN: option = (option + 1) % tables_count elif action == ord('\n'): selection = option if selection == 0: dashboard_database.database_menu(username) selected_table = tables[selection] table_menu(username, database, selected_table)