def main(): # 1 usename_input = input('Podaj nazwę użytkownika: ') password_input = input('Podaj hasło użtkownika: ') user = User(usename_input, password_input) # 2 tasks = Todo() # tworzymy obiekt z klasy todo # 3 tasks.assign_user_to_todo(user) print(tasks.assigned_user) # 5 first_note = TodoItem('zrobić zakupy') second_note = TodoItem('ogarnąć się') third_note = TodoItem('nauczyć się programować') # 4 tasks.add_note(first_note) tasks.add_note(second_note) tasks.add_note(third_note) tasks.display_notes # przed zmianą wyświetlamy tasks.notes[0].toggle_done() # zmieniamy na 'Done' tasks.display_notes() # po zmianie wyśiwetlamy
def test_db_helpers(): table_name = 'test_table' assert check_table_exists(table_name) == False #testing query function(new table when if not exist) key=1 query_db('select * from {username}') assert check_table_exists(table_name) == False #testing insert function todoitem = TodoItem('this is title',True, datetime(year= 2019, month = 10,day= 29)) create_todo(todoitem) #testing query function(get all rows from a table if exist) for todo in query_db('select * from {username}'): print(todo) if todo[2] != '': temp_todo = TodoItem(todo[1], True if todo[3]==1 else False, datetime.datetime.strptime(todo[2],"%m/%d/%Y, %H:%M:%S")) print(temp_todo.is_done) todos.append(temp_todo) assert todos[0].title == 'this is title' #testing delete row function key = 0 delete_todo('this is title') assert len(query_db('select * from {username}')) == 0 #testing delete table function delete_table(table_name) assert check_table_exists(table_name) == False
def items_view2(): reader = "ReadOnly" # added as part of module 10 os.environ['LOGIN_DISABLED'] = 'True' return ViewModel([ TodoItem(1, "Test in progress Todo", "To Do", datetime.now()), TodoItem(2, "Test Pending Todo", "Pending", datetime.now()), TodoItem(3, "Test Done Todo", "Done", datetime.now()) ], reader) # added as part of module 10
def index(): form = ExampleForm() if form.field1.data != None: title = form.field1.data todo_item = TodoItem(title, False, datetime.datetime.now()) create_todo(todo_item) print(form.field1.data) else: form.field1.description = '' #get all todos from database print('before the for loop') todos.clear() username = current_user.username print(current_user.username) for todo in query_db('select * from {username}'): print(todo) todo_items[todo[1]] = False if todo[2] != '': temp_todo = TodoItem( todo[1], True if todo[3] == 1 else False, datetime.datetime.strptime(todo[2], "%m/%d/%Y, %H:%M:%S")) print(temp_todo.is_done) todos.append(temp_todo) form.field1.data = "" done_count = len(list(filter(lambda todo: todo.is_done, todos))) undone_count = len( list( filter( lambda todo: not helpers.is_greater_than_24_hours( todo.creation_date) and not todo.is_done, todos))) failed_count = len( list( filter( lambda todo: helpers.is_greater_than_24_hours( todo.creation_date) and not todo.is_done, todos))) return render_template( 'home.html', title='Home', form=form, todo_items=todo_items, todos=todos, get_time_elapse=helpers.get_time_elapse, done_count=done_count, undone_count=undone_count, failed_count=failed_count, is_greater_than_24_hours=helpers.is_greater_than_24_hours)
def test_show_all_done_items_returns_true_for_small_numbers_of_items(): # Arrange items = [ TodoItem(1, "Started Todo", "Not Started", ""), TodoItem(2, "Doing Todo", "In Progress", ""), TodoItem(3, "Done Todo", "Completed", ""), ] vader = ViewModel(items) # Act result = vader.show_all_done_items # Assert assert result == True
def read_from_file(self): """ Read items from file and append all items to todo items list """ name_index = 0 description_index = 1 deadline_index = 2 is_done_index = 3 year_index = 0 month_index = 1 day_index = 2 with open('data.csv', 'r') as csvfile: reader = csv.reader(csvfile) for row in reader: if row[deadline_index] != 'None': date = row[deadline_index].split('-') date = datetime.date(int(date[year_index]), int(date[month_index]), int(date[day_index])) else: date = None self.todo_items.append( TodoItem(row[name_index], row[description_index], date, True if row[is_done_index] == 'True' else False))
def main(): todo = Todo() while True: print("How can I help you?\n") print("1.Add task\n" "2.List tasks\n" "3.Toggle done\n" "4.Remove task\n" "0.Exit\n") number = input("\nPlease select number: ") if number == "1": item = TodoItem(input("\nPlease add a task: ")) todo.add_item(item) print("\nTask added.") elif number == "2": print("\nItems list: ") todo.list_items() elif number == "3": todo.list_items() done = input("\nChoose a number for task which is done?: ") todo.items[int(done) - 1].toggle_done() todo.list_items() elif number == "4": todo.list_items() remove = input("\nChoose a number for task to remove: ") removed = int(remove) - 1 todo.remove_item(removed) todo.list_items() elif number == "0": print("\nGoodbye!") else: print("Please choose a valid option.")
def add_item(self, name, description, deadline): """ Add item to todo items list :param name: string -> name of the todo item :param description: string -> description of the todo item :param deadline: Datetime -> deadline of the todo item """ self.todo_items.append(TodoItem(name, description, deadline))
def test_filters_by_status( ): # first test to see if view model item matches each status created_todo = TodoItem(1, "Test in progress Todo", "To Do", datetime.now()) pending_todo = TodoItem(2, "Test Pending Todo", "Pending", datetime.now()) done_todo = TodoItem(3, "Test Done Todo", "Done", datetime.now()) todos = [created_todo, pending_todo, done_todo] # added as part of module 10 project reader = "ReadOnly" view_model = ViewModel(todos, reader) assert view_model.to_do_items == [created_todo] assert view_model.doing_items == [pending_todo] assert view_model.done_items == [done_todo]
def test_done(): items = ( TodoItem(1, "Started Todo", "Not Started", ""), TodoItem(2, "Doing Todo", "In Progress", ""), TodoItem(3, "Done Todo", "Completed", ""), ) storm = ViewModel(items) done_items = storm.done assert len(done_items) == 1 done_item = done_items[0] assert done_item.status == "Completed" assert done_item.id == 3
def test_constructor(self): date = datetime(2017, 6, 4) item = TodoItem('implement ToDoItem class', date) self.assertEqual(item.title, 'implement ToDoItem class', "Wrong todo_item") self.assertEqual(item.deadline, date, 'Wrong deadline') self.assertEqual(item.is_done, False, 'dupa') self.assertIsInstance
def modify_item(self, index, name, description, deadline): """ Modify item by index :param index: int -> index of item we want to modify :param name: string -> name of the todo item :param description: string -> description of the todo item :param deadline: Datetime -> deadline of the todo item """ self.todo_items[index] = TodoItem(name, description, deadline)
def add_item(self, title, deadline): if not isinstance(deadline, date): raise ValueError('Deadline should be datetime object') else: self.todo_items.append(TodoItem(title, deadline)) self.sort_items()
def test_doing(): # Arrange items = [ TodoItem(1, "Started Todo", "Not Started", ""), TodoItem(2, "Doing Todo", "In Progress", ""), TodoItem(3, "Done Todo", "Completed", ""), ] vader = ViewModel(items) # Act doing_items = vader.doing # Assert assert len(doing_items) == 1 doing_item = doing_items[0] assert doing_item.status == "In Progress" assert doing_item.id == 2
def test_show_all_done_items_today(): today = arrow.utcnow().floor('day').format('YYYY-MM-DD') items = (TodoItem(1, "Started Todo", "Not Started", today), TodoItem(2, "Doing Todo", "In Progress", today), TodoItem(3, "Done Todo", "Completed", today), TodoItem(4, "Done Todo", "Completed", "2021-04-06")) egg = ViewModel(items) # Act result = egg.show_all_done_items_today # Assert assert len(result) == 1 done_item = result[0] assert done_item.status == "Completed" assert done_item.id == 3
def test_to_do(): # Passing through blank value for the Date Input as not required for this test items = [ TodoItem(1, "Started Todo", "Not Started", ""), TodoItem(2, "Doing Todo", "In Progress", ""), TodoItem(3, "Done Todo", "Completed", ""), ] frank = ViewModel(items) # Act # [TodoItem(1, "Started Todo", "Not Started")] todo_items = frank.to_do # Assert assert len(todo_items) == 1 todo_item = todo_items[0] assert todo_item.status == "Not Started"
def add_item(self, title, deadline): ''' Method adds new Item object with attributes title and deadline to list. Args: title - string deadline - datetime object Returns: None ''' self.todo_items.append(TodoItem(title, deadline)) self.sort_items()
def my_app(): form = ExampleForm() if form.field1.data != None: title = form.field1.data todo_item = TodoItem(title, False, datetime.datetime.now()) create_todo(todo_item) print(form.field1.data) else: form.field1.description = '' global ButtonPressed ButtonPressed += 1 """ create() : Add document to Firestore collection with request body Ensure you pass a custom ID as part of json body in post request e.g. json={'id': '1', 'title': 'Write a blog post'} """ #get all todos from database print('before the for loop') todos.clear() for todo in query_db('select * from todos'): print(todo) todo_items[todo[1]] = False if todo[2] != '': temp_todo = TodoItem( todo[1], True if todo[3] == 1 else False, datetime.datetime.strptime(todo[2], "%m/%d/%Y, %H:%M:%S")) print(temp_todo.is_done) todos.append(temp_todo) form.field1.data = "" return render_template('home.html', ButtonPressed=ButtonPressed, form=form, todo_items=todo_items, todos=todos, get_time_elapse=helpers.get_time_elapse)
def add_item(self, title, deadline): """ Method adds new object of TodoItem class into todo_items attribute list Args: title (str): name of the item deadline (obj): object of datetime class Returns: None """ if type(deadline) is not datetime: raise TypeError self.todo_items.append(TodoItem(title, deadline)) self.sort_items()
def add_item(self): ''' Add an item to the TODO store ''' # print(self.priority.get()) # print(self.due.get()) # print(self.description.get("1.0", END)) print(self.completed.get()) item = TodoItem(self.description.get("1.0", END), self.completed.get(), self.priority.get(), self.due.get()) self.store.addItem(item) displayBox = Checkbutton(self.master, text=item.itemToString(), onvalue="complete", offvalue="incomplete") displayBox.pack(side="bottom")
def test_str3(self): date = datetime(2017, 6, 4) item = TodoItem('implement TodoItem class', date) item.mark() test_string = item.__str__() self.assertEqual(test_string[1], 'x', 'Wrong sign')
def test_unmark(self): date = datetime(2017, 6, 4) item = TodoItem('implement TodoItem class', date) item.mark() item.unmark() self.assertEqual(item.is_done, False, 'Item wasn\'t unmarked')
def add_item(self, title, deadline): self.todo_items.append(TodoItem(title, deadline)) TodoQuarter.sort_items(self)
from todo_store import TodoStore from todo_item import TodoItem mainStore = TodoStore() command = input("What would you like to do? ") while command != "quit": if command == "add": priority = input("Priority: ") description = input("Description: ") isDue = input("Is it due (True/False): ") if isDue == "True": due = input("Due date: ") item = TodoItem(description, priority=priority, isDue=isDue) mainStore.addItem(item) elif command == "complete": itemNum = input("Enter item number: ") mainStore.completeItem(itemNum) elif command == "export": mainStore.exportList() elif command == "total": print(f"Number of items: {mainStore.getNumItems()}") command = input("What would you like to do? ") exit(0)
def test_value_error2(self): date = datetime(2017, 5, 16) with self.assertRaises(ValueError, msg='Title must be a string'): item = TodoItem(100, date)
from flask_materialize import Material from flask_wtf import Form, RecaptchaField from flask_wtf.file import FileField from wtforms import TextField, HiddenField, ValidationError, RadioField,\ BooleanField, SubmitField, IntegerField, FormField, validators, DateField, SelectField from wtforms.validators import Required import helpers THIS_FOLDER = os.path.dirname(os.path.abspath(__file__)) key_json_file_path = os.path.join(THIS_FOLDER, 'key.json') DATABASE = os.path.join(THIS_FOLDER, 'database.db') #mock data todo_items = {'todo1': True, 'todo222': False, 'just simple to do': True} todos = [ TodoItem('This is a mock todo that has not been completed yet', False, datetime.datetime.now()) ] # straight from the wtforms docs: class TelephoneForm(Form): country_code = IntegerField('Country Code', [validators.required()]) area_code = IntegerField('Area Code/Exchange', [validators.required()]) number = TextField('Number') class ExampleForm(Form): field1 = TextField('Title', description='') submit_button = SubmitField('Create')
print('\t' + str(item)) if no_arguments_are_passed(): todo_list = read_todo_list() if not todo_list: if not args.silent: print('Nothing to do here...\n' 'type \'todo something\' to add a todo or\n' 'type \'todo -h\' for usage info.') else: show_todo_list(todo_list) if args.new_item: new_content = ' '.join(args.new_item) new_item = TodoItem(new_content) todo_list = read_todo_list() not_done_items = [item for item in todo_list if item.status == 'todo'] for item in not_done_items: if item.content == new_item.content: print('This item already exists:\n' + '\t' + str(item)) exit(0) try: with open(filename, 'a') as todo_file: todo_file.write(new_item.serialize() + '\n') except EnvironmentError as err: print(str(err)) else: print('You have one more thing to do: \n' + '\t' + str(new_item)) if args.done_item:
def test_str(self): date = datetime(2017, 6, 4) item = TodoItem('implement TodoItem class', date) self.assertIsInstance(item.__str__(), str)
def test_value_error(self): date = '2017-03-05' with self.assertRaises(ValueError, msg='Deadline must be a Datetime object'): item = TodoItem('implement TodoItem class', date)
def item_view(): reader = "ReadOnly" created_todo = TodoItem(1, "Test in progress Todo", "To Do", date.today()) created_todo2 = TodoItem(2, "Test in progress Todo", "To Do", date.today()) created_todo3 = TodoItem(3, "Test in progress Todo", "To Do", date.today()) pending_todo = TodoItem(4, "Test Pending Todo", "Pending", date.today()) pending_todo2 = TodoItem(5, "Test Pending Todo", "Pending", date.today()) done_todo = TodoItem(6, "You're not done", "Done", date.today() - timedelta(days=2)) done_todo2 = TodoItem(7, "Are you sure you're done", "Done", date.today() - timedelta(days=3)) done_todo3 = TodoItem(8, "Are you sure you're done1", "Done", date.today() - timedelta(days=4)) done_todo4 = TodoItem(9, "Are you sure you're done2", "Done", date.today() - timedelta(days=5)) done_todo5 = TodoItem(10, "Are you sure you're done3", "Done", date.today()) done_todo6 = TodoItem(11, "Are you sure you're done4", "Done", date.today()) todos = [ created_todo, created_todo2, created_todo3, pending_todo, pending_todo2, done_todo, done_todo2, done_todo3, done_todo4, done_todo5, done_todo6 ] return ViewModel(todos, reader)