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())
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})
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())
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)
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)
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)
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, })
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)
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]
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)
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, })
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())
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})
def get(self, request, *args, **kwargs): form = AddTaskForm() return self.my_render(request, form)