def select_backup(self): filename = list_choice(listdir(self.config['backup_dir'])) if bool_question('are you sure you want to overwrite all data?', default=False): # first of all, backup existing data write_backup(self.db, self.config['backup_dir']) # now load new data load_backup(self.db, filename, self.config['backup_dir'])
def edit_categories(self): for item in self.db.query(Category): print(item.name) menu = list_choice(['add', 'edit', 'delete', 'back']) if menu == 'add': new = Category(name=str_input('Name')) self.db.add(new) elif menu == 'edit': edit = query_choice(self.db.query(Category)) edit.name = str_input('New name') elif menu == 'delete': rm = query_choice(self.db.query(Category)) self.db.delete(rm) self.db.commit()
def main_menu(self): menu = '' while menu != 'exit': menu = list_choice(['track expense', 'last month', 'categories', 'load backup', 'exit']) if menu == 'exit': self.end() elif menu == 'track expense': self.track_expense() elif menu == 'last month': self.history() self.stats() elif menu == 'categories': self.edit_categories() elif menu == 'load backup': self.select_backup()