本文整理汇总了Python中forms.AddTaskForm类的典型用法代码示例。如果您正苦于以下问题:Python AddTaskForm类的具体用法?Python AddTaskForm怎么用?Python AddTaskForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AddTaskForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_task
def new_task():
error = None
form = AddTaskForm(request.form)
# g.db = connect_db()
# name = request.form['name']
# due_date = request.form['due_date']
# priority = request.form['priority']
# if not name or not due_date or not priority:
# flash("All fields are required. Please try again!")
# return redirect(url_for('tasks'))
# else:
# g.db.execute("""insert into tasks (name, due_date, priority, status) values (?,?,?,1)""",
# [request.form['name'],request.form['due_date'],request.form['priority']])
# g.db.commit()
# g.db.close()
if request.method == 'POST':
if form.validate_on_submit():
new_task = Task(form.name.data, form.due_date.data, form.priority.data,'1',
session['user_id'],datetime.utcnow())
db.session.add(new_task)
db.session.commit()
flash("New entry was successfully posted. Thanks!")
else:
# flash('All fields are required!')
return render_template('tasks.html', form=form, error=error)
return render_template('tasks.html', form=form, error=error,
open_tasks=open_tasks(), closed_tasks=closed_tasks())
示例2: new_task
def new_task():
error = []
form = AddTaskForm(flask.request.form)
print(flask.request.form)
if flask.request.method == "POST":
if form.validate_on_submit():
new_task = Task(
form.name.data,
form.due_date.data,
form.priority.data,
datetime.datetime.utcnow(),
"1",
flask.session["user_id"]
)
db.session.add(new_task)
db.session.commit()
flask.flash("New entry was successfully posted.")
return flask.redirect(flask.url_for("tasks"))
else:
error.append("There was an error with the task data. Make sure all fields are filled in.")
return flask.render_template(
"tasks.html",
form = form,
error = error,
open_tasks = open_tasks(),
closed_tasks = closed_tasks()
)
示例3: new_task
def new_task():
error = None
form = AddTaskForm(request.form)
if request.method == 'POST':
if form.validate_on_submit():
new_task = Task(
form.name.data,
session['user_id'],
form.due_date.data,
form.priority.data,
'1',
datetime.datetime.utcnow()
)
db.session.add(new_task)
db.session.commit()
flash("New entry was successfully posted. Thanks.")
return redirect(url_for('tasks'))
else:
return render_template(
'tasks.html',
form=form,
error=error,
open_tasks=open_tasks(),
closed_tasks=closed_tasks()
)
else:
return render_template(
'tasks.html',
form=form,
error=error,
open_tasks=open_tasks(),
closed_tasks=closed_tasks()
)
示例4: add_task
def add_task():
task_id = request.args.get('tid')
ori_task = Task.query.filter(Task.id == task_id).first()
form = AddTaskForm()
if ori_task:
form = AddTaskForm(name=ori_task.name, key=ori_task.redis_key, ctime=ori_task.start_time)
if request.method == 'POST' and form.validate():
tid = request.values.get('tid')
str_key = form.key.data
task = Task(form.name.data, str_key, form.ctime.data)
if tid:
# update
tsObj = Task.query.filter(Task.id == tid).first()
ori_str_key = tsObj.redis_key
rd.delete(ori_str_key)
tsObj.redis_key = str_key
tsObj.name = form.name.data
tsObj.start_time = form.ctime.data
db.session.commit()
else:
db.session.add(task)
rd.setex(str_key, 1, task.seconds)
return redirect('/')
return render_template('add.html', form=form)
示例5: add
def add():
"""g.db = connect_db()
name = request.form['name']
due_date = request.form['due_date']
priority = request.form['priority']
if not name or not due_date or not priority:
flash("Please fill all the fields")
return redirect(url_for('tasks'))
else:
#g.db.execute("INSERT INTO tasks(name, due_date, priority, status) VALUES(?, ?, ?, 1)",[request.form['name'],request.form['due_date'],request.form['priority']])
#g.db.commit()
#g.db.close()
flash("Your entry was successfully admitted")
return redirect(url_for('tasks'))"""
form = AddTaskForm(request.form)
if request.method == "POST":
if form.validate_on_submit():
new_task = Task(form.name.data, form.due_date.data, form.priority.data, "1", session["user_id"])
db.session.add(new_task)
db.session.commit()
flash("New entry was successfully posted. Thanks.")
return redirect(url_for("tasks.tasks"))
else:
return render_template("tasks.html", form=form, error=error)
return render_template("tasks.html", form=form, error=error, open_tasks=open_tasks(), closed_tasks=closed_tasks())
示例6: new_task
def new_task():
error = None
form = AddTaskForm(request.form)
if request.method == 'POST':
if form.validate_on_submit():
new_task = Task(
form.name.data,
form.due_date.data,
form.priority.data,
datetime.datetime.utcnow(),
'1',
session['user_id']
)
db.session.add(new_task)
db.session.commit()
flash('New entry was successfully posted. Thanks')
return redirect(url_for('tasks.tasks'))
else:
open_tasks = db.session.query(Task) \
.filter_by(status='1').order_by(Task.due_date.asc())
closed_tasks = db.session.query(Task) \
.filter_by(status='0').order_by(Task.due_date.asc())
return render_template('tasks.html', form=form, error=error, open_tasks = open_tasks, closed_tasks = closed_tasks)
示例7: new_task
def new_task():
form = AddTaskForm(request.form)
if request.method == "POST":
if form.validate_on_submit():
new_task = Task(form.name.data, form.due_date.data, form.priority.data, 1)
db.session.add(new_task)
db.session.commit()
flash("New task has been added")
return redirect(url_for("tasks"))
示例8: new_task
def new_task():
form = AddTaskForm(request.form)
if request.method == "POST":
if form.validate_on_submit():
new_task = Task(form.name.data, form.due_date.data, form.priority.data, "1")
db.session.add(new_task)
db.session.commit()
flash("New entry was susccessfully posted Thanks.")
return redirect(url_for("tasks"))
示例9: addtask
def addtask(request):
form = AddTaskForm(request.POST)
if request.user.is_authenticated():
if form.is_valid():
list = request.user.list_set.filter(listname=form.cleaned_data['list'])
if not list:
return HttpResponse("list name not found", status=400)
newtask = form.save()
return HttpResponse(json.dumps([]))
else:
return HttpResponse("form validation failed" + str(form.errors), status=400)
else:
return HttpResponse("Url is only available to logged in users", status=401)
示例10: add_task
def add_task(request):
if request.method == 'POST':
form = AddTaskForm(data=request.POST)
if form.is_valid():
new_task = form.save(commit=False)
new_task.author = request.user
new_task.save()
return HttpResponseRedirect(new_task.get_absolute_url())
else:
form = AddTaskForm()
return render_to_response('timetracker/add_task.html',
{'form': form},
context_instance = RequestContext(request))
示例11: new_task
def new_task():
form = AddTaskForm(request.form)
if request.method == 'POST':
if form.validate_on_submit(): # something to look into
new_task = models.Task(
form.name.data,
form.due_date.data,
form.priority.data,
'1'
)
db.session.add(new_task)
db.session.commit()
flash('New Entry Added Successfully')
return redirect(url_for('tasks'))
示例12: new_task
def new_task():
form = AddTaskForm(request.form)
if request.method == 'POST':
if form.validate_on_submit():
new_user = User(
form.username.data,
form.ip_phone.data,
form.ip_phone_type.data,
'1'
)
db.session.add(new_user)
db.session.commit()
flash('New entry was successfully posted. Thanks.')
return redirect(url_for('tasks'))
示例13: tasks
def tasks(request, project_pk=None):
completed_task_list = Task.objects.for_user(request.user).filter(completed=True).order_by('-completion_date')
pending_task_list = Task.objects.for_user(request.user).filter(completed=False)
project_list = Project.objects.for_user(request.user).filter(completed=False)
if not project_pk and 'tasks_latest_project_pk' in request.session:
#print reverse('view-tasks', int(request.session['tasks_latest_project_pk']))
return HttpResponseRedirect("/tasks/%s/" % request.session['tasks_latest_project_pk'])
elif project_pk == 'all':
project_pk = None
if project_pk:
project = get_object_or_404(Project, pk=project_pk)
completed_task_list = completed_task_list.filter(project=project)
pending_task_list = pending_task_list.filter(project=project)
initial = {'project': project.pk}
request.session['tasks_latest_project_pk'] = project.pk
else:
project = None
initial = {}
TaskListFormSet = modelformset_factory(Task, fields=('completed',), extra=0)
if request.POST and 'task_list-INITIAL_FORMS' in request.POST:
task_list_formset = TaskListFormSet(request.POST, queryset=pending_task_list, prefix='task_list')
if task_list_formset.is_valid():
task_list_formset.save()
return HttpResponseRedirect(request.path_info)
else:
task_list_formset = TaskListFormSet(queryset=pending_task_list, prefix='task_list')
if request.POST and 'addtask-task' in request.POST:
task_form = AddTaskForm(request.POST, prefix='addtask')
if task_form.is_valid():
task = task_form.save()
return HttpResponseRedirect(request.path_info)
else:
task_form = AddTaskForm(prefix='addtask', initial=initial)
data = {
'project': project,
'completed_task_list': completed_task_list,
'project_list': project_list,
'task_form': task_form,
'task_list_formset': task_list_formset,
}
return render_to_response('projectmanager/tasks.html', data)
示例14: new_task
def new_task():
form = AddTaskForm(request.form)
if request.method == "POST":
if form.validate_on_submit() or True:
new_task = Task(
name = form.name.data,
due_date = form.due_date.data,
priority = form.priority.data,
status = '1',
posted_date = datetime.datetime.utcnow(),
user_id = session['user_id']
)
db.session.add(new_task)
db.session.commit()
return redirect(url_for('tasks'))
示例15: new_task
def new_task():
form = AddTaskForm(request.form)
if request.method == 'POST':
if form.validate_on_submit():
new_task = Task(
form.name.data,
form.due_date.data,
form.priority.data,
datetime.datetime.utcnow(),
'1',
'1'
)
db.session.add(new_task)
db.session.commit()
flash('New entry posted! Do it, Doug!')
return redirect(url_for('tasks'))