Exemple #1
0
 def __init__(self):
     self.todolist = ToDoList("todolist")
     self.options = {
         '1': self.displayundone,
         '2': self.displaydone,
         '3': self.addtask,
         '4': self.removetask,
         '5': self.completetask,
         '6': self.quit
     }
Exemple #2
0
def did_task(item_id):
    user = users.get_current_user()
    users_list = ToDoList(user.nickname(), db)
    users_list.remove_item(item_id)
    user_info = UserInfo.get(user)
    new_points = random.randint(0, 1)
    while random.randint(1, 5) > 3 and new_points < 20:
        new_points *= 2
        new_points += random.randint(0, 3)
    user_info.score += new_points
    user_info.save()
    return [users_list.get_top_item(user_info.daily_limit), user_info.score]
Exemple #3
0
class User():
    def __init__(self, name):
        self.name = name[:20].capitalize()
        self.tasks = ToDoList()

    def __str__(self):
        return str(self.name)

    def add_task(self, name, description):
        self.tasks.add_task(name, description)

    def remove_task(self, task_id):
        del self.tasks.my_tasks[task_id]

    def change_task_name(self, task_id, new_name):
        self.tasks.my_tasks[task_id].set_new_name(new_name)

    def change_task_description(self, task_id, new_description):
        self.tasks.my_tasks[task_id].set_new_description(new_description)

    def mark_task_as_done(self, task_id):
        self.tasks.my_tasks[task_id].mark_me_as_done()

    def mark_task_as_todo(self, task_id):
        self.tasks.my_tasks[task_id].mark_me_as_todo()

    def get_task_name(self, task_id):
        """Return string."""
        return self.tasks.my_tasks[task_id].name

    def get_task_full_description(self, task_id):
        """Return string."""
        return str(self.tasks.my_tasks[task_id].name + ":\n" +
                   self.tasks.my_tasks[task_id].description)

    def get_task_id_by_name(self, name):
        """Return string."""
        for task_id, task in enumerate(self.tasks.my_tasks):
            if task.name == name:
                return str(task_id)
        return name + " - there's no such name in tasks list, type correct name..."

    def get_all_my_tasks(self):
        """Return string."""
        if self.tasks.my_tasks:
            return str(self.tasks)
        else:
            return "Don't have any task yet.."

    def remove_all_tasks(self):
        del self.tasks.my_tasks[:]
Exemple #4
0
def add_task(todo):
    user = users.get_current_user()
    users_list = ToDoList(user.nickname(), db)
    try:
        users_list.insert(todo)
    except AmbiguousUrgencyExeption, e:
        return {
            'success': False,
            'newthing': todo,
            'benchmark': {
                'task': e.benchmark.task,
                'urgency': e.benchmark.urgency,
            },
        }
 def setUp(self):
     self.username = helpers.make_random_string()
     self.list = ToDoList(item_type=FakeItem,
                          username=self.username,
                          db=mock.Mock())
     self.middle_char = all_chars[len(all_chars) / 2]
     print self.list
class ToDoListTestCase(helpers.DJOTTestCase):
    def setUp(self):
        self.username = helpers.make_random_string()
        self.list = ToDoList(item_type=FakeItem,
                             username=self.username,
                             db=mock.Mock())
        self.middle_char = all_chars[len(all_chars) / 2]
        print self.list

    def test_some_properties_about_all_chars(self):
        self.assert_greater(len(all_chars), 90)
        self.assertEqual('!', all_chars[0])
        self.assertEqual('}', all_chars[-1])

        for i in xrange(len(all_chars) - 1):
            self.assert_less(chr(i), chr(i + 1))

        for i in xrange(len(all_chars)):
            self.assertEqual(chr(i + 33), all_chars[i])
            self.assertEqual(i + 33, ord(all_chars[i]))

    def test_get_top_item(self):
        self.list._test_force(("top", "A"), ("bottom", "C"))
        self.assertEqual("top", self.list.get_top_item())

    def test_get_top_item_escaped(self):
        self.list._test_force(("& < >", "A"), ("bottom", "C"))
        self.assertEqual("&amp; &lt; &gt;", self.list.get_top_item())

    def test_get_top_item_longer_list(self):
        self.list._test_force(("top2", "A"), ("middle", "B"), ("bottom", "C"))
        self.assertEqual("top2", self.list.get_top_item())

    def test_get_top_item_empty_list_tells_you_to_add_things(self):
        self.assertEqual("Click on the + symbol to add a thing", self.list.get_top_item())

    def test_newly_created_list_has_extremes_of_allchars_as_first_and_last_elements(self):
        self.assertEqual(self.list._items[0].urgency, all_chars[-1])
        self.assertEqual(self.list._items[-1].urgency, all_chars[0])

    def test_newly_created_list_takes_username(self):
        self.assertEqual(self.username, self.list.username)

    def test_inserting_item_preserves_task(self):
        self.assertTrue(self.list.empty)

        self.list.insert("Do\ntaxes")

        self.assertEqual(1, self.list.length)
        item = self.list[0]
        self.assertEqual("Do\ntaxes", item.task)

    def test_inserting_item_adds_username(self):
        self.assertTrue(self.list.empty)

        self.list.insert("Do\ntaxes")

        self.assertEqual(1, self.list.length)
        item = self.list[0]
        self.assertEqual(self.username, item.username)

    def test_insert_to_empty_list_gets_middle_priority(self):
        self.assertTrue(self.list.empty)

        self.list.insert("Pay those bills\nThe ones on my desk")

        self.assertEqual(1, self.list.length)
        item = self.list[0]

        self.assertEqual(item.urgency, self.middle_char)

    def test_insert_into_list_with_item_requires_bounds(self):
        self.list.insert("Finish writing this app")
        self.assertEqual(1, self.list.length)
        try:
            self.list.insert("Do something else")
            self.fail("Should have excepted")
        except AmbiguousUrgencyExeption as e:
            self.assertEqual("Finish writing this app", e.benchmark.task)

    def test_insert_into_list_when_existing_item_is_less_urgent(self):
        self.list.insert("High priority thing")
        self.assertEqual(1, self.list.length)
        first_item = self.list[0]
        self.list.insert("Higher priority thing", lower_bound=first_item.urgency)
        self.assertEqual(2, self.list.length)

        high_priority_item = self.list[0]
        low_priority_item = self.list[1]

        self.assertEqual("Higher priority thing", high_priority_item.task)
        self.assertEqual("High priority thing", low_priority_item.task)
        self.assert_greater(high_priority_item.urgency, low_priority_item.urgency)

    def test_insert_into_list_when_existing_item_is_more_urgent(self):
        self.list.insert("High priority thing")
        self.assertEqual(1, self.list.length)
        high_priority_item = self.list[0]

        self.list.insert("Low priority thing",
                         upper_bound=high_priority_item.urgency)
        self.assertEqual(2, self.list.length)

        high_priority_item = self.list[0]
        low_priority_item = self.list[1]

        self.assertEqual("Low priority thing", low_priority_item.task)

        self.assertEqual("High priority thing", high_priority_item.task)

        self.assert_greater(high_priority_item.urgency, low_priority_item.urgency)

    def test_insert_into_list_between_two_things_that_start_with_gap_letters_ends_up_with_middle(self):
        self.list._test_force(("top", "A"), ("bottom", "C"))
        print self.list

        self.list.insert("middle", upper_bound='C', lower_bound='A')

        self.assertEqual(3, self.list.length)
        self.assertEqual('B', self.list[1].urgency)

    def test_insert_into_list_of_three_things_with_priority_between_top_and_bottom_but_ambiguous_with_middle(self):
        self.list._test_force(("top", "A"), ("middle", "B"), ("bottom", "C"))
        self.assertEqual(3, self.list.length)
        print self.list._items
        try:
            self.list.insert("middle2", upper_bound='C', lower_bound='A')
            self.fail("should have excepted")
        except AmbiguousUrgencyExeption as e:
            self.assertEqual("middle", e.benchmark.task)

    def test_insert_into_list_between_two_items_with_adjacent_urgencies_takes_first_one_and_adds_a_letter(self):
        self.list._test_force(("top", "A"), ("bottom", "B"))
        print self.list

        self.list.insert("middle", upper_bound='B', lower_bound='A')
        print self.list

        self.assertEqual(3, self.list.length)
        self.assertEqual('A' + self.middle_char, self.list[1].urgency)
        self.assertTrue(self.list[0].urgency > self.list[1].urgency > self.list[2].urgency)

    def test_insert_into_list_between_two_items_with_same_first_few_letters_does_the_right_thing(self):
        self.list._test_force(("top", "blahblahZZX"), ("bottom", "blahblahAAAAA"))
        print self.list

        self.list.insert("middle", upper_bound='blahblahZZX', lower_bound='blahblahAAAAA')
        print self.list

        self.assertEqual(3, self.list.length)
        self.assert_startswith(self.list[1].urgency, 'blahblah')
        self.assertEqual('top', self.list[0].task)
        self.assertEqual('middle', self.list[1].task)
        self.assertEqual('bottom', self.list[2].task)
        self.assertTrue(self.list[0].urgency > self.list[1].urgency > self.list[2].urgency)

    def test_insert_into_list_thats_lower_than_lowest_possible_item_rejiggers_list(self):
        self.list._test_force(("lowest_possible", all_chars[1]))
        print self.list

        self.list.insert("lower_than_low", upper_bound=all_chars[1])
        print self.list
        self.assertEqual('lowest_possible', self.list[0].task)
        self.assertEqual('lower_than_low', self.list[1].task)
        for i in xrange(self.list.length):
            self.assert_not_startswith(self.list[i].urgency, all_chars[0])
            self.assert_not_startswith(self.list[i].urgency, all_chars[-1])
        self.assertTrue(self.list[0].urgency > self.list[1].urgency > all_chars[0])
Exemple #7
0
 def __init__(self, name):
     self.name = name[:20].capitalize()
     self.tasks = ToDoList()
import json
from whaaaaat import prompt, print_json
from todolist import ToDoList

#using_app = True
active_list = ToDoList()


def main():
    questions = [{
        'type': 'input',
        'name': 'first_name',
        'message': 'What\'s your first name'
    }]

    answers = prompt(questions)
    print_json(answers)


if __name__ == "__main__":
    main()

#with open('todolist.json') as todo_list_json:
#    todo_list_dictionary = json.load(todo_list_json)

#while using_app:
#    for todo_list in todo_list_dictionary.items():
#        user_input = int(input("Which list would you like to load?"))
#        if user_input is 0:
#            using_app = False
#        elif user_input is 1:
Exemple #9
0
class Main():
    def __init__(self):
        self.todolist = ToDoList("todolist")
        self.options = {
            '1': self.displayundone,
            '2': self.displaydone,
            '3': self.addtask,
            '4': self.removetask,
            '5': self.completetask,
            '6': self.quit
        }

    def displaymenu(self):
        '''Display to-do list menu'''
        print('''
        Welcome to To-Do List App!

        To-Do List Menu

        1. Display undone tasks
        2. Display done tasks
        3. Add new task
        4. Remove task
        5. Complete task
        6. Quit
        ''')

    def run(self):
        '''Keep program in running'''
        while True:
            self.displaymenu()
            choice = input('\nEnter you choice: ')
            option = self.options.get(choice)
            try:
                option()
            except KeyError:
                print('Please enter valid choice!')
            except TypeError:
                print('Please enter valid choice in numeric!')

    def displayundone(self):
        '''Display the incompleted tasks if there is any'''
        try:
            self.todolist.display('Undone')
        except Exception:
            print('There is no any incompleted tasks at the moment.')

    def displaydone(self):
        '''Display the completed tasks if there is any'''
        try:
            self.todolist.display('Done')
        except Exception:
            print('There is no any completed tasks at the moment.')

    def addtask(self):
        '''Add task into to do list and identify potential
        value error caused by invalid deadline input'''
        task = input('\nEnter task: ')
        deadline = input('Enter task deadline: ')
        label = input('Enter label for this tasks: ')
        label = label.split(',')
        label = [labels.strip(' ') for labels in label]
        try:
            self.todolist.addtask(task, deadline, label)
        except ValueError:
            print('Failed to add task! Please enter valid date.')
        else:
            print('Successfully add task.')
            self.todolist.save()

    def removetask(self):
        '''Remove task using index and detect invalid index input'''
        try:
            self.todolist.display('Undone')
        except Exception:
            print('There is no any incompleted tasks at the moment.')
        else:
            delchoice = input('\nEnter task to be removed: ')
            try:
                self.todolist.removetask(int(delchoice))
            except IndexError:
                print('Please enter valid task!')
                self.removetask()
            except ValueError:
                print('Please enter valid task in numeric!')
                self.removetask()
            else:
                self.todolist.save()

    def completetask(self):
        '''Mark completed task to Done by index'''
        try:
            self.todolist.display('Undone')
        except Exception:
            print('There is no any completed tasks at the moment.')
        else:
            taskcompleted = input('\nPlease enter completed tasks: ')
            try:
                self.todolist.completetask(int(taskcompleted))
            except IndexError:
                print('Please enter valid task!')
                self.completetask()
            except ValueError:
                print('Please enter valid task in numeric!')
                self.completetask()
            else:
                self.todolist.save()

    def quit(self):
        '''Serialize file into pickle and quit'''
        self.todolist.save()
        print("Thank you for using this app.")
        sys.exit()
Exemple #10
0
def get_next_task_and_score():
    user = users.get_current_user()
    user_info = UserInfo.get(user)
    users_list = ToDoList(user.nickname(), db)
    user_info = UserInfo.get(user)
    return [users_list.get_top_item(user_info.daily_limit), user_info.score]
Exemple #11
0
def delay_task(item_id):
    user = users.get_current_user()
    users_list = ToDoList(user.nickname(), db)
    users_list.delay_item(item_id)
    user_info = UserInfo.get(user)
    return users_list.get_top_item(user_info.daily_limit)
Exemple #12
0
def create_todo_list():
    """Get a todo list name from user"""
    print("Enter you todo list information when prompted. Type 'q' to quit.")
    list_name = input("Enter your todo list name: ")
    return ToDoList(list_name)