本文整理汇总了Python中forms.AddTaskForm.validate_on_submit方法的典型用法代码示例。如果您正苦于以下问题:Python AddTaskForm.validate_on_submit方法的具体用法?Python AddTaskForm.validate_on_submit怎么用?Python AddTaskForm.validate_on_submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.AddTaskForm
的用法示例。
在下文中一共展示了AddTaskForm.validate_on_submit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_task
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import validate_on_submit [as 别名]
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()
)
示例2: new_task
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import validate_on_submit [as 别名]
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())
示例3: add
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import validate_on_submit [as 别名]
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())
示例4: new_task
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import validate_on_submit [as 别名]
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()
)
示例5: new_task
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import validate_on_submit [as 别名]
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)
示例6: new_task
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import validate_on_submit [as 别名]
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"))
示例7: new_task
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import validate_on_submit [as 别名]
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
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import validate_on_submit [as 别名]
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 was successfully added.')
return redirect(url_for('tasks'))
else:
flash('All fields are required.')
flash(form.validate_on_submit())
return redirect(url_for('tasks'))
return redirect(url_for('tasks'))
示例9: new_task
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import validate_on_submit [as 别名]
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'))
示例10: new_task
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import validate_on_submit [as 别名]
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'))
示例11: new_task
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import validate_on_submit [as 别名]
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'))
示例12: new_task
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import validate_on_submit [as 别名]
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'))
示例13: new_task
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import validate_on_submit [as 别名]
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',
session["user_id"])
db.session.add(new_task)
db.session.commit()
flash("New entry was successfully posted, Thanks.")
else:
flash("Wrong input field, abort posting task.")
return redirect(url_for('tasks'))
示例14: new_task
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import validate_on_submit [as 别名]
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('Nueva tarea fue agragada con exito')
else:
flash('Por favor, agregue datos validos')
return redirect(url_for('tasks'))
示例15: new_task
# 需要导入模块: from forms import AddTaskForm [as 别名]
# 或者: from forms.AddTaskForm import validate_on_submit [as 别名]
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('Nu entry dun dun dun. Well done.')
else:
flash('did not validate')
return redirect(url_for('tasks'))