예제 #1
0
 def test_add_task_form_is_invalid_with_missing_name(self):
     """
     Test that the add task form is invalid if the required task_name field is missing
     """
     form = AddTaskForm({'task_name': ''})
     
     """ The form can not be valid because the value is missing so should assert false """
     self.assertFalse(form.is_valid())
예제 #2
0
    def post(self, request, pk, *args, **kwargs):
        t = TodoItem.objects.get(id=pk)
        form = AddTaskForm(request.POST, instance=t)
        if form.is_valid():
            new_task = form.save(commit=False)
            new_task.owner = request.user
            new_task.save()
            return HttpResponseRedirect(reverse("tasks:list"))

        return render(request, "tasks/edit.html", {"form": form, "task": t})
예제 #3
0
 def test_can_create_an_task_with_just_a_name_and_difficulty(self):
     """
     Test that a user can create a task with just a task name and difficulty set
     Task notes are also part of the model, but this is an optional field
     """
     form = AddTaskForm({
         'task_name': 'Do Tests', 
         'task_difficulty': 'EA'
     })
     
     """ Assert that form.is_valid() is true """
     self.assertTrue(form.is_valid())
예제 #4
0
    def test_should_validate_input(self):
        # Arrange
        owner = UserFactory.build()
        form = AddTaskForm(self._data, author=owner, owner=owner)

        # Act
        result = form.is_valid()

        # Assert
        self.assertTrue(result)
        self.assertEqual(form.cleaned_data['title'], self._title)
        self.assertEqual(form.cleaned_data['priority'], self._priority)
예제 #5
0
    def post(self, request, *args, **kwargs):
        form = AddTaskForm(request.POST)
        if form.is_valid():
            # form.save()
            # подмешаем юзера в форму
            new_task = form.save(commit=False)
            new_task.owner = request.user
            new_task.save()
            return HttpResponseRedirect(reverse('tasks:list'))


        return self.my_render(request, form)
예제 #6
0
    def test_should_validate_input(self):
        # Arrange
        owner = UserFactory.build()
        form = AddTaskForm(self._data, author=owner, owner=owner)

        # Act
        result = form.is_valid()

        # Assert
        self.assertTrue(result)
        self.assertEqual(form.cleaned_data['title'], self._title)
        self.assertEqual(form.cleaned_data['priority'], self._priority)
예제 #7
0
    def test_should_create_task(self):
        # Arrange
        owner = UserFactory.create()
        form = AddTaskForm(self._data, author=owner, owner=owner)

        # Act
        form.is_valid()
        obj = form.save()

        # Assert
        self.assertIsNotNone(obj.pk)
        self.assertEqual(obj.title, self._title)
        self.assertEqual(obj.priority, self._priority)
        self.assertEqual(obj.author, owner)
        self.assertEqual(obj.owner, owner)
예제 #8
0
    def test_should_create_task(self):
        # Arrange
        owner = UserFactory.create()
        form = AddTaskForm(self._data, author=owner, owner=owner)

        # Act
        form.is_valid()
        obj = form.save()

        # Assert
        self.assertIsNotNone(obj.pk)
        self.assertEqual(obj.title, self._title)
        self.assertEqual(obj.priority, self._priority)
        self.assertEqual(obj.author, owner)
        self.assertEqual(obj.owner, owner)
예제 #9
0
def task_add(request):
    group = get_current_group(request)
    if group == None:
        return HttpResponseRedirect(reverse('index'))

    if request.method == "POST":
        form = AddTaskForm(group, request.POST, label_suffix='')
        if form.is_valid():
            form.save(group)
            return HttpResponseRedirect(reverse('task-list'))
    else:
        form = AddTaskForm(group, label_suffix='')

    menu = {'parent': 'tasks', 'child': 'new_task'}
    return render(request, 'task_add.html', {
                  'menu': menu,
                  'form': form,
                  })
예제 #10
0
def add_task(req):
    logger.debug('Add Task')
    req_logger.debug(req)

    data = {}
    data.update(csrf(req))

    if req.method == 'POST':
        form = AddTaskForm(req.POST)
        if form.is_valid():
            task = Task(task_title=form.cleaned_data['task_name'])
            task.save()
            return redirect('task_list')
        else:
            data['errors'] = form.errors
            return render_to_response('tasks/add_task.html', data)

    return render_to_response('tasks/add_task.html', data)
예제 #11
0
파일: views.py 프로젝트: funkybob/taask
def add_task(request):
    """Add a task."""

    tw_error = ''
    view = 'new_task'

    if request.method == "POST":
        form = AddTaskForm(request.POST, label_suffix='')
        if form.is_valid():
            # Assign each cleaned data item to its own variable
            description = form.cleaned_data['description']
            view = form.cleaned_data['view']
            priority = form.cleaned_data['priority']
            time = form.cleaned_data['time']
            project = form.cleaned_data['project']
            due = form.cleaned_data['due']
            recur = form.cleaned_data['recur']
            until = form.cleaned_data['until']
            wait = form.cleaned_data['wait']
            context_1 = form.cleaned_data['context_1']
            context_2 = form.cleaned_data['context_2']
            context_3 = form.cleaned_data['context_3']
            # Context data is held in Taskwarrior's 'tags' field
            # Construct 'tags' in the format which taskw expects
            tags = [context_1, context_2, context_3]
            # Create the new task
            try:
                w.task_add(description,
                           view=view,
                           priority=priority,
                           time=time,
                           project=project,
                           due=due,
                           recur=recur,
                           until=until,
                           wait=wait,
                           tags=tags)
                return redirect('list-tasks', 'today')
            except TaskwarriorError, e:
                tw_error = str(e).rpartition('stderr:')[2].\
                           partition('; stdout')[0]
예제 #12
0
    def post(self, request, *args, **kwargs):
        form = AddTaskForm(request.POST)
        if form.is_valid():
            # form.save()
            # подмешаем юзера в форму
            new_task = form.save(commit=False)
            new_task.owner = request.user
            new_task.save()
            # чтобы сохранить теги (по дефолту поля m2m не сохраняются при commit=False)
            form.save_m2m()
            return HttpResponseRedirect(reverse('tasks:list'))

        return self.my_render(request, form)
예제 #13
0
def task_add(request):
    group = get_current_group(request)
    if group == None:
        return HttpResponseRedirect(reverse('index'))

    if request.method == "POST":
        form = AddTaskForm(group, request.POST, label_suffix='')
        if form.is_valid():
            form.save(group)
            return HttpResponseRedirect(reverse('task-list'))
    else:
        form = AddTaskForm(group, label_suffix='')

    menu = {'parent': 'tasks', 'child': 'new_task'}
    return render(request, 'task_add.html', {
        'menu': menu,
        'form': form,
    })
예제 #14
0
def task_add(request: WSGIRequest, *args, **kwargs):
    due_date: Optional[str] = request.GET.get('pour_le')

    form = AddTaskForm(initial={'due_date': due_date})

    if request.method == 'POST':
        form = AddTaskForm(data=request.POST)

        if form.is_valid():
            form.instance.user = request.user
            form.save()

            return redirect(reverse('tasks:list'))

    return render(request, 'tasks/task_add.html', {
        'active_menu': 'tasks',
        'form': form,
    })
예제 #15
0
def add_task(request, *args, **kwargs):
    """
    Allow users to add new task
    """

    if request.POST:
        form = AddTaskForm(request.user, request.POST)
        if form.is_valid():
            try:
                form.save()
                messages.success(request, "A new task has been added.")
                return HttpResponseRedirect(request.path)
            except IntegrityError:
                messages.error(request,
                               "There was a prbolem saving the new task")
    else:
        form = AddTaskForm(request.user)

    return render(request, 'tasks/add_task.html', locals())
예제 #16
0
 def get(self, request, pk, *args, **kwargs):
     t = TodoItem.objects.get(id=pk)
     form = AddTaskForm(instance=t)
     return render(request, "tasks/edit.html", {"form": form, "task": t})
예제 #17
0
 def get(self, request, *args, **kwargs):
     form = AddTaskForm()
     return self.my_render(request, form)