def test_save_edit_good(self): e_dict = {'timestamp': datetime.datetime(2018, 7, 2, 8), 'user_name': 'White Diamond', 'task_name': 'Unknown', 'task_minutes': 1200, 'task_notes': "mystery"} updater = CardCatalog().acquire_target(e_dict) updater.task_name = 'Reknowned' updater.task_minutes = 21 updater.task_notes = 'solved' updater.timestamp = datetime.datetime(2015, 6, 2, 8) saver = CardCatalog().save_edits(updater) self.assertTrue(saver)
def edit_entry(entry): updater = CardCatalog().acquire_target(entry) if updater is False: input('Error. Entry not found. Press "enter" to return to main menu.') return clear_screen() print("{}'s entry, {}.".format(entry['user_name'], entry['task_name'])) entry_adding = 1 while entry_adding: new_task = '' new_task = input('Edit task name, or hit enter to skip.\n> ') new_minutes = '' nm_check = 1 while nm_check: new_minutes = input( 'Edit integer of minutes, or enter to skip.\n> ') if new_minutes: if CardCatalog().minute_check(new_minutes): break else: invalid_input('integer') continue new_date = '' nd_check = 1 print('Original Timestamp: ' + entry['timestamp'].strftime('%m/%d/%Y')) while nd_check: new_date = input( "Type new date in MM/DD/YYYY format. Or enter to skip.") if new_date != '': try: new_dto = datetime.datetime.strptime(new_date, "%m/%d/%Y") break except ValueError: invalid_input('date string') continue new_notes = '' if input('Any notes? [y/N]').upper().strip() == "Y": print('Type notes here. Press "ctrl+d" when finished.') new_notes = sys.stdin.read().strip() clear_screen() print('Name: ' + entry['user_name']) if new_task != '': print('Task: ' + new_task) else: print('Task: ' + entry['task_name']) if new_minutes != '': print('Minutes: ' + new_minutes) else: print('Minutes: ' + str(entry['task_minutes'])) if new_notes: if len(new_notes) > 50: print('Notes: ' + new_notes[:50] + '. . . ') else: print('Notes: ' + new_notes) else: print('Notes: ' + entry['task_notes']) if input('Save entry? [Y/n]\n> ').lower() != 'n': if new_task != '': updater.task_name = new_task if new_minutes != '': updater.task_minutes = new_minutes if new_notes != '': updater.task_notes = new_notes if new_date != '': updater.timestamp = new_dto saver = CardCatalog().save_edits(updater) if saver: print("Saved succesfully!") press_enter() else: press_enter() return