def update(request, id): todo = Todo.objects.get(id=id) form = TodoForm(request.POST, instance=todo) if form.is_valid(): form.save() return redirect("/") return render(request, 'edit.html', {'employee': todo})
def test_todo_form_valid_recurring_year(self): form = TodoForm(data={ 'headline': 'Test1', 'description': "This is a Test", 'deadline': timezone.now(), 'recurring': 'y' }) self.assertTrue(form.is_valid())
def add_todo(request): form = TodoForm(request.POST, user=request.user) if form.is_valid(): todo = form.save() response = {'id': todo.id, 'title': todo.title} else: response = form.errors_as_json() return JsonResponse(jsonify(response))
def test_todo_form_unvalid_recurring(self): form = TodoForm(data={ 'headline': 'Test1', 'description': "This is a Test", 'deadline': timezone.now(), 'recurring': 't' }) self.assertFalse(form.is_valid()) self.assertEquals(len(form.errors), 1)
def index(request): if request.method == "POST": form = TodoForm(request.POST) if form.is_valid(): form.save() return redirect('/') else: form = TodoForm() return render(request, 'index.html', {'form': form})
def item(request, id): if request.method == 'POST': orig = Todo.objects.get(pk=id) form = TodoForm(request.POST,instance=orig) if form.is_valid(): todo = form.save(commit=False) todo.save() return list(request) else: todo = Todo.objects.get(pk=id) form = TodoForm(instance=todo) return render(request, "item.html", {"form" : form})
def create(request): if request.method != 'POST' or 'todo' not in request.POST: return HttpResponseRedirect('/') form = TodoForm(data=request.POST) if form.is_valid(): todo = form.save(commit=False) todo.author = request.user.get_profile() todo.save() else: log.debug("form error: %s" % (str(form.errors))) messages.error(request, _('There was an error posting ' 'your todo update')) return HttpResponseRedirect('/')
def list(request): todos = Todo.objects.filter(done=False) if request.method == "POST": form = TodoForm(request.POST) if form.is_valid(): form.save() if request.is_ajax(): return render(request, 'todos/list.js', {'form': form}, content_type="text/javascript") else: form = TodoForm() return render(request, 'todos/list.html', {'todos': todos, 'form': form})
def create(request): if request.method=='POST': form=TodoForm(request.POST) if form.is_valid(): todo=form.save(commit=False) todo.user=request.user todo.save() else: form=TodoForm() context={ 'form':form } return render(request, 'todos/form.html', context)
def edit_todo(request, todo_id): profile = get_object_or_404(Profile, user=request.user) todo = get_object_or_404(Todo, id=todo_id) if request.POST: form = TodoForm(profile, request.POST, instance=todo) if form.is_valid(): form.save() return redirect(reverse('todos:home')) else: form = TodoForm(profile=profile, instance=todo) return render(request, 'todos/edit_todo.html', {'form': form})
def create(request): if request.method =="GET": context = { "form":TodoForm() } return render(request, "create.html", context) elif request.method == "POST": form = TodoForm(request.POST) if form.is_valid(): form.save() return redirect("todos:index")
def add_todo(request): profile = get_object_or_404(Profile, user=request.user) if request.POST: form = TodoForm(profile, request.POST) if form.is_valid(): form.save(profile) return redirect(reverse('todos:home')) else: form = TodoForm(profile) return render(request, 'todos/add_todo.html', { 'form': form, 'profile': profile })
def todos_poster(request): if request.method == 'POST': item = Task(author=request.user) form = TodoForm(data=request.POST, instance=item) if form.is_valid(): form.save() else: print(form.errors) return HttpResponseRedirect(reverse('todos:index')) else: form = TodoForm() return render(request, 'todos/todo_post.html', {'form': form})
def create_project_todo(request, project_id): if request.method != 'POST': return HttpResponseRedirect('/') project = get_object_or_404(Project, id=project_id) profile = request.user.get_profile() form = TodoForm(data=request.POST) if form.is_valid(): todo = form.save(commit=False) todo.author = request.user.get_profile() todo.project = project todo.save() else: messages.error(request, _('There was an error posting ' 'your todo update')) log.debug("Saved todo by user (%d) to project (%d): %s" % ( profile.id, project.id, todo)) return HttpResponseRedirect( reverse('projects_show', kwargs=dict(slug=project.slug)))