Example #1
0
    def put(self, id):
        data = request.get_json()

        todoList = TodoList.get_by_id(id)

        if todoList is None:
            task_lst = []
            for task in data['tasks']:
                obj = Task(task_name=task['task_name'],
                           task_done=task['task_done'])
                task_lst.append(obj)

            todoList = TodoList(
                todoList_name=data['todoList_name'],
                todoList_done=data['todoList_done'],
            )
            todoList.tasks = task_lst

            todoList.save()

            return {'message': 'Successfully saved new data'}, 201
        else:
            todoList.todoList_name = data['todoList_name']
            todoList.todoList_done = data['todoList_done']
            for t in data['tasks']:
                task = Task.query.get(t['taskID'])
                task.task_name = t['task_name']
                task.task_done = t['task_done']

            todoList.save()
            return {'message': 'Updated data with '}
Example #2
0
 def test_delete_list_wrong_user(self):
     list_ = TodoList(owner=self.other_user)
     list_.save()
     self.client.login(username='******', password='******')
     response = self.client.delete(self.url.format(list_.id))
     self.assertEqual(response.status_code, 403)
     self.assertIsNotNone(TodoList.objects.get(id=list_.id))
Example #3
0
 def test_delete_list(self):
     list_ = TodoList(owner=self.user)
     list_.save()
     self.client.login(username='******', password='******')
     response = self.client.delete(self.url.format(list_.id))
     self.assertEqual(response.status_code, 204)
     with self.assertRaises(TodoList.DoesNotExist):
         TodoList.objects.get(id=list_.id)
Example #4
0
    def mutate(self, info, name):
        # CREATE
        if name:
            todo_list = TodoList(name=name, user_id=1)
            todo_list.save()
        else:
            todo_list = None

        return CreateTodoList(todo_list=todo_list)
Example #5
0
def create_todo(request):
    form = TodoForm(request.POST)

    if form.is_valid():
        todo = TodoList(name=form.cleaned_data['name'], description=form.cleaned_data['description'], is_done=False)
        todo.save()
        return redirect('todos index')

    return home(request, form)
Example #6
0
def create_list(owner, title, description, container=None):
    """
        Create and return a TodoList with given values.
        If container is passed, the item is saved and id is appended to container.
    """
    new_list = TodoList(owner=owner, title=title, description=description)

    if container is not None:
        new_list.save()
        container.append(new_list.id)

    return new_list
Example #7
0
 def setUpTestData(cls):
     cls.user = auth_models.User.objects.create_user("test",
                                                     password="******")
     cls.other_user = auth_models.User.objects.create_user("test2",
                                                           password="******")
     cls.list_ = TodoList(owner=cls.user)
     cls.list_.save()
     cls.url = "/todo/lists/{}/{}/update/"
Example #8
0
 def setUpTestData(cls):
     cls.user = auth_models.User.objects.create_user('test',
                                                     password='******')
     cls.other_user = auth_models.User.objects.create_user('test2',
                                                           password='******')
     cls.list_ = TodoList(owner=cls.user)
     cls.list_.save()
     cls.url = '/todo/lists/delete/{}'
Example #9
0
    def post(self):
        data = request.get_json()

        task_lst = []
        for task in data['tasks']:
            obj = Task(task_name=task['task_name'],
                       task_done=task['task_done'])
            task_lst.append(obj)

        todoList = TodoList(
            todoList_name=data['todoList_name'],
            todoList_done=data['todoList_done'],
        )
        todoList.tasks = task_lst

        todoList.save()

        return {'message': 'Successfully saved new data'}, 201
Example #10
0
def todo(request):
    if request.method == "GET":
        tasks = TodoList.objects.all()
        make_dictinary = {
            "all_data": tasks
        }
        return render(request, 'todo/todo.html', context=make_dictinary)
    if request.method == "POST":
        if request.method == "POST":
            usr = request.session.get('my_auth_user')
        
            if usr:
                task = request.POST['task']
                user = User.objects.get(username=request.session['my_auth_user'])

                sql = TodoList(task=task, user=user)
                sql.save()
                return JsonResponse({"success":"ok done "})
Example #11
0
    def put(self, list_id):
        data = request.get_json()

        user = User.find_by_id(get_jwt_identity())

        todoList = TodoList.query.filter(and_(TodoList.id == list_id, TodoList.user_id == user.userID)).first()

        if todoList is None:
            task_lst = []
            for task in data['tasks']:
                obj = Task(
                    task_name=task['task_name'],
                    task_done=task['task_done']
                    )
                task_lst.append(obj)

            todoList = TodoList(
                todoList_name=data['todoList_name'],
                todoList_done=data['todoList_done'],
                user_id=user.userID
            )
            todoList.tasks = task_lst

            todoList.save()

            return {'message': 'Successfully saved new data'}, 201
        else:
            todoList.todoList_name = data['todoList_name']
            todoList.todoList_done = data['todoList_done']
            for t in data['tasks']:
                if t['id'] is "":
                    task = Task(
                        task_name=t['task_name'],
                        task_done=t['task_done']
                    )
                    todoList.tasks.append(task)
                else:
                    task = Task.get_by_id(t['id'])
                    task.task_name = t['task_name']
                    task.task_done = t['task_done']


            todoList.save()
            return {'message': 'Updated data'}
Example #12
0
def list_create(request, **kwargs):
    new_list = TodoList()
    new_list.owner = request.user
    new_list.title = request.POST['title']
    new_list.description = request.POST['description']
    new_list.save()

    return HttpResponseRedirect(reverse('todo:list_index'))
Example #13
0
    def handle(self, *args, **kwargs):
        # Manual unpacking here since the integer values will be
        # encapsulated inside a list
        nb_todolists = kwargs['nb_todolists'][0]
        nb_subtasks = kwargs['nb_subtasks'][0]
        nb_tasks = kwargs['nb_tasks'][0]
        owner = kwargs['owner']
        todolist_names = kwargs['todolist_name']

        if todolist_names is not None and nb_todolists != len(todolist_names):
            error_msg = 'Length of todolists names and number of todolists mismatch: %d != %d'
            raise CommandError(error_msg % (len(todolist_names), nb_todolists))

        print(owner)
        owner = User.objects.get(username=owner)

        lists = [TodoList(owner=owner) for i in range(nb_todolists)]
        if todolist_names:
            for name, todolist in zip(todolist_names, lists):
                todolist.title = name
        # Insert all the lists with only one query
        TodoList.objects.bulk_create(lists)
        # Retrieve all the saved lists, this is a mandatory step since django's
        # bulk_create will NOT populate the model's primary key after insertion.
        lists = TodoList.objects.filter(title__in=todolist_names)

        tasks = []
        subtasks = []

        # First step: Create the tasks
        for todolist in lists:
            for i in range(nb_tasks):
                task = Task(owner=owner, parent_list=todolist, title=str(i))
                tasks.append(task)

        # Bulk insert the tasks
        Task.objects.bulk_create(tasks)
        # Retrieve the newly created task (see the why in line 49)
        tasks = Task.objects.filter(owner=owner)
        # Then bulk insert the subtasks, we cannot create the tasks and their
        # subtasks in the same SQL query since the subtasks will refer to their
        # parents that will no exist in the database at the time of insertion
        for task in tasks:
            for i in range(nb_subtasks):
                task = Task(owner=owner,
                            parent_list=todolist,
                            title=str(i),
                            parent_task=task)
                subtasks.append(task)
        Task.objects.bulk_create(subtasks)
Example #14
0
    def post(self):
        data = request.get_json()

        user = User.find_by_id(get_jwt_identity())


        task_lst = []
        for task in data['tasks']:
            obj = Task(
                task_name=task['task_name'],
                task_done=task['task_done']
                )
            task_lst.append(obj)

        todoList = TodoList(
            todoList_name=data['todoList_name'],
            todoList_done=data['todoList_done'],
            user_id=user.userID
        )
        todoList.tasks = task_lst

        todoList.save()

        return {'message': 'Successfully saved new data'}, 201
Example #15
0
def createTodoList(request):
    user_id = request.session.get('user_id')
    title = request.POST.get('title')
    
    try:
        if title is None:
            return HttpResponseBadRequest()

        user = User.objects.get(pk=user_id)
        todo_list = TodoList(title=title, owner=user)
        todo_list.full_clean()
        todo_list.save()

        # Add the user as a collaborator
        todo_list.collaborators.add(user)
        todo_list.save()

    except User.DoesNotExist:
        return HttpResponse(status=401)

    except ValidationError as e:
        return HttpResponse(status=400, content=e.message)

    return HttpResponse(content=todo_list.to_json(), content_type='application/json')
Example #16
0
 def setUpTestData(cls):
     cls.user = auth_models.User.objects.create_user('test', password='******')
     cls.list_ = TodoList(owner=cls.user)
     cls.list_.save()
Example #17
0
 def test_user_not_null(self):
     """Todo list must have an assigned user."""
     todo_list = TodoList(name='Test')
     self.assertRaises(IntegrityError, todo_list.save)
Example #18
0
 def test_name_default_blank(self):
     """Name cannot be null."""
     todo_list = TodoList(user=self.user)
     todo_list.save()
     self.assertEqual(todo_list.name, '')
Example #19
0
 def test_TwoTodos(self):
     item1 = TodoList(name="Go to the mall")
     item2 = TodoList(name="Go to the car wash")
     self.assertEqual(str(item1), item1.name)
     self.assertEqual(str(item2), item2.name)
Example #20
0
 def test_OneTodos(self):
     item = TodoList(name="Go to the gym")
     self.assertEqual(str(item), item.name)
Example #21
0
 def test_string_representation(self):
     entry = TodoList(name="My entry name")
     self.assertEqual(str(entry), entry.name)
Example #22
0
    def get(self, id):
        todoList = TodoList.get_by_id(id)

        return {'todoList': todoList.to_dict()}, 201
Example #23
0
    def get(self):
        todo = TodoList.get_all()

        return {'todoLists': [t.to_dict() for t in todo]}, 201
Example #24
0
def todo_view(request):
    todos = TodoList.objects.all()
    checked = FinishedItems.objects.all()
    categories = Category.objects.all()
    current_user = request.user
    priority_choices = PriorityForm()
    if request.method == "POST":
        if "taskAdd" in request.POST:
            title = request.POST["description"]
            priority = request.POST["priority_select"]
            category = request.POST["category_select"]
            if request.POST["date"] != "":
                date = str(request.POST["date"])
            else:
                date = None
            try:
                content = request.POST["content"]
                if content:
                    Todo = TodoList(
                        title=title,
                        content=content,
                        due_date=date,
                        priority=priority,
                        category=Category.objects.get(id=category),
                        created_by_id=current_user.id,
                    )
                else:
                    Todo = TodoList(
                        title=title,
                        due_date=date,
                        priority=priority,
                        category=Category.objects.get(id=category),
                        created_by_id=current_user.id,
                    )
            except MultiValueDictKeyError:
                Todo = TodoList(
                    title=title,
                    due_date=date,
                    priority=priority,
                    category=Category.objects.get(id=category),
                    created_by_id=current_user.id,
                )
            Todo.save()
            return redirect('todo_view')
    if request.method == "GET":
        if "changeTask" in request.GET:
            task_id = request.GET['task_id']
            priority = request.GET['priority_select']
            date = request.GET['date']
            task = TodoList.objects.get(id=int(task_id))
            task.due_date = date
            if date == "":
                task.due_date = None
            task.priority = priority
            if request.GET['content']:
                content = request.GET['content']
                task.content = content
            task.save()
        try:
            task_id = int(request.GET['delete_task'])
            try:
                task = TodoList.objects.get(id=task_id)
                done = FinishedItems(
                    title=task.title,
                    content=task.content,
                    due_date=task.due_date,
                    category=task.category,
                    priority=task.priority,
                    created_by_id=int(task.created_by.id),
                )
                done.save()
                task.delete()
            except FinishedItems.DoesNotExist:
                pass
        except MultiValueDictKeyError:
            pass
        try:
            priority_id = request.GET['priority_id']
            try:
                task = TodoList.objects.get(id=int(priority_id))
                if task.priority:
                    task.priority = False
                else:
                    task.priority = True
                task.save()
            except TodoList.DoesNotExist:
                pass
        except MultiValueDictKeyError:
            pass
        try:
            id = request.GET['undelete_task']
            try:
                #Save it into Finished Items before deleting#
                task = FinishedItems.objects.get(id=int(id))
                if task.created_by_id:
                    created_by = CustomUser.objects.get(id=task.created_by_id)
                    todo = TodoList(
                        title=task.title,
                        content=task.content,
                        due_date=task.due_date,
                        category=task.category,
                        priority=task.priority,
                        created_by_id=created_by.id,
                    )
                else:
                    todo = TodoList(title=task.title,
                                    content=task.content,
                                    due_date=task.due_date,
                                    category=task.category)
                todo.save()
                task.delete()
            except FinishedItems.DoesNotExist:
                pass
        except MultiValueDictKeyError:
            pass
    return render(
        request, "todo/todo_list.html", {
            "todos": todos,
            "checked": checked,
            "priority_choices": priority_choices,
            "categories": categories
        })