def add_todo(): """Add a todo.""" form = TodoForm() if request.method == 'POST' and form.validate_on_submit(): todo = Todo(text=form.todo.data) todo.save() return redirect(url_for('todo_list'))
def add(request): if request.method == 'POST': form = TodoForm(request.POST) if form.is_valid(): title = form.cleaned_data['title'] # Create or get bookmark. todo = Todo.objects.create( title=title, finished=0, author=request.user) # Create new tag list. tag_names = form.cleaned_data['tags'].split() for tag_name in tag_names: tag, dummy = Tag.objects.get_or_create(name=tag_name) todo.tag_set.add(tag) todo.save() messages.info(request, u'新增成功 !') return HttpResponseRedirect(reverse('todo_user', args=[request.user])) else: form = TodoForm() variables = RequestContext(request, { 'form': form }) return render_to_response('add.html', variables)
def hello(): form = TodoForm() if form.validate_on_submit(): try: conn=pymongo.MongoClient() db = conn.test todo = db.todo data = {} print request.form['todo'] data['todo'] = request.form['todo'] todo.insert(data) return redirect('/') except: print "Failed" return redirect('/') else: try: conn=pymongo.MongoClient() db = conn.test todo = db.todo myList = list(todo.find()) print myList return render_template('./app.html', form=form, myList = myList) except: print "Failed" return render_template('./app.html', form=form, myList = [])
def modify(request, id): if request.method == 'POST': form = TodoForm(request.POST) if form.is_valid(): todo = get_object_or_404(Todo, id=id) todo.title = form.cleaned_data['title'] todo.author = request.user todo.pubtime = datetime.datetime.now() # 创建新的 tags todo.tag_set.clear() tag_names = form.cleaned_data['tags'].split() for tag_name in tag_names: tag, dummy = Tag.objects.get_or_create(name=tag_name) todo.tag_set.add(tag) todo.save() messages.info(request, u'编辑成功') return HttpResponseRedirect(reverse('todo_user', args=[request.user])) else: form = TodoForm() todo = Todo.objects.get(id=id) variables = RequestContext(request, { 'form': form, 'todo': todo }) return render_to_response('add.html', variables)
def submit_word(user_id): """Add a todo.""" form = TodoForm() if request.method == 'POST' and form.validate_on_submit(): todo = Todo(text=form.todo.data) todo.save() return redirect(url_for('game_list'))
def index(): form = TodoForm() if form.validate_on_submit(): todo = Todo(subject = form.subject.data, priority = form.priority.data, user = g.user.id, deadline = form.deadline.data) db.session.add(todo) db.session.commit() redirect(url_for('index')) todo = Todo.query.filter_by(user = g.user.id).order_by(Todo.priority.desc()).all() return render_template('index.html', todo = todo, form = form)
def add_new_todo(request): if request.POST: form = TodoForm(request.POST) if form.is_valid(): new_todo = form.save() return HttpResponseRedirect("/todo/updated/%s/" % (new_todo.id)) else: form = TodoForm() return render_to_response("model_form.html", dict(form=form))
def edit_todo(request, todo_id): todo_instance = get_object_or_404(Todo, pk=todo_id) if request.POST: form = TodoForm(request.POST, instance=todo_instance) if form.is_valid(): form.save() return HttpResponseRedirect("/todo/updated/%s/" % (todo_id)) else: form = TodoForm(instance=todo_instance) return render_to_response("model_form.html", dict(form=form))
def index(): form = TodoForm() if form.validate_on_submit(): todo_content = form.todo_content.data thistag=Tag.query.filter_by(tag_content=form.select_tag.data).first() # if thistag=='': # flash("you should add a tag first") # return redirect('index') todo = Todo(todo_content=todo_content,tag=thistag) db.session.add(todo) return redirect(url_for('index')) alltodos = Todo.query.order_by(Todo.time.desc()).all() return render_template("index.html",alltodos=alltodos,form=form)
def post_todo(request, project_id): if request.method == 'POST': form = TodoForm(request.POST) if form.is_valid(): detail = form.cleaned_data['detail'] status = form.cleaned_data['status'] priority = form.cleaned_data['priority'] p = Project.objects.get(id=project_id) t = Todo.objects.create(detail=detail, status=status, priority=priority) p.todos.add(t) p.save() return JsonResponse({"data": "success"}) print form.errors
def todo_details(todo_id): todo = todossqlite.get(todo_id) data_todo = {} data_todo['title'] = todo[0][1] data_todo['description'] = todo[0][2] data_todo['status'] = todo[0][3] form_todo = TodoForm(data=data_todo) if request.method == "POST": if request.form["btn"] == "Save": todossqlite.update(todo_id=todo_id, data=form_todo.data) if request.form["btn"] == "Delete": todossqlite.delete(todo_id) return redirect(url_for("todos_list")) return render_template("todo.html", form=form_todo, todo_id=todo_id)
def todo_details(todo_id): todo = todos.get(todo_id) form = TodoForm(data=todo) if request.method == "POST": full_url = str(request.url_root) + \ url_for("update_todo", todo_id=todo_id) response = requests.put(full_url, json=form.data, headers={ 'Content-type': 'application/json', 'Accept': 'text/plain' }) logging.info("response code from API: %s" % response.status_code) if response.status_code != 201: logging.error("Technical problem with API funcion") return redirect(url_for("todos_list")) return render_template("todo.html", form=form, todo_id=todo_id)
def todo_list(): """Simple todo page.""" form = TodoForm() todos = Todo.all().order('-created_at') return render_template('todo.html', form=form, todos=todos)
def hello(): form = TodoForm() if form.validate_on_submit(): return render_template('./app.html', form=form, myList = []) else: return render_template('./app.html', form=form, myList = [])
def index(): todoform = TodoForm() todos = Todo.query.all() return render_template("index.html", todos=todos, template_form=TodoForm())
def add_reminder(request): if request.method == 'POST': form = TodoForm(request.POST) form.save() return HttpResponse(json.dumps(success_response), content_type='application/json')