def test_form_valid(self): form = TaskForm( data={ 'Title': 'Build ToDo aplication', 'Description': 'Create Read Update Delete', 'due_time': '2012-06-08 10:29:47' }) self.assertTrue(form.is_valid())
def test_form_invalidate_with_dateformat(self): form = TaskForm( data={ 'Title': 'Build ToDo aplication', 'Description': 'Create Read Update Delete', 'due_time': '2012/06/08 10:29:47' })
def task_update(request, id=None): """ The function for updating the task title task descripion and the level of task""" instance = get_object_or_404(Todo, id=id) print(instance) print(instance) form = TaskForm(request.POST or None, instance=instance) if form.is_valid(): instance = form.save(commit=False) instance.save() return redirect('lists:alllist') context = { "desription": instance.description, "instance": instance, "form": form, } return render(request, "lists/update_task.html", context)
def create_task(request): """function of creating task list with task title, task description and task level""" all_task_list = Todo.objects.all() form = TaskForm() if request.method == 'POST': form = TaskForm(request.POST) if form.is_valid(): # create default todolist user = request.user if request.user.is_authenticated else None task = Todo(description=request.POST['description'], content=request.POST['content'], tesk_medium=request.POST['tesk_medium'], creator=user) task.save() return redirect('lists:alllist') else: return render(request, 'lists/index.html', {'form': form}) context = {'form': form, 'taskli': all_task_list} return render(request, 'lists/create_task.html', context)
def add_task(request): message = "" if request.method == "POST": form = TaskForm(request.POST) if form.is_valid(): form.save() message = "Task added Successfully" else: form = TaskForm() return render_to_response('addtask.html', {'form': form, 'message':message}, context_instance=RequestContext(request))
def edit_task(request, task_id): message = "" task = get_object_or_404(Task, id = task_id) if request.method == "POST": form = TaskForm(request.POST, instance = task) if form.is_valid(): form.save() message = "Task Edited Successfully" else: form = TaskForm(instance = task) return render_to_response('edittask.html', {'form': form, 'message': message, 'task': task}, context_instance=RequestContext(request))
def test_form_invalide(self): form = TaskForm(data={'Title': '', 'Description': '', 'due_time': ''}) self.assertFalse(form.is_valid())