当前位置: 首页>>代码示例>>Python>>正文


Python AddTaskForm.validate_on_submit方法代码示例

本文整理汇总了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()
    )     
开发者ID:jarogers095,项目名称:flasktaskr,代码行数:29,代码来源:views.py

示例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())
开发者ID:sshimp,项目名称:flasktaskr,代码行数:29,代码来源:views.py

示例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())
开发者ID:xtreampy,项目名称:py_get_real,代码行数:27,代码来源:views.py

示例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()
        )
开发者ID:atengler,项目名称:python-testing,代码行数:35,代码来源:views.py

示例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)
开发者ID:zklevsha,项目名称:flasktaskr-old,代码行数:28,代码来源:views.py

示例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"))
开发者ID:joshphiggins,项目名称:FlashTaskr,代码行数:11,代码来源:views.py

示例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"))
开发者ID:janhaans,项目名称:flasktaskr,代码行数:11,代码来源:views.py

示例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'))
开发者ID:wove,项目名称:flasktaskr,代码行数:20,代码来源:views.py

示例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'))
开发者ID:PansFortress,项目名称:flasktasker,代码行数:16,代码来源:views.py

示例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'))
开发者ID:sturmblade,项目名称:flask-cucm,代码行数:16,代码来源:views.py

示例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'))
开发者ID:kwikiel,项目名称:scrumtasker,代码行数:17,代码来源:views.py

示例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'))
开发者ID:jerodestapa,项目名称:flasktodo,代码行数:18,代码来源:views.py

示例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'))
开发者ID:Pampipampupampa,项目名称:RealPython_NoDeploy,代码行数:18,代码来源:views.py

示例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'))
开发者ID:doyomay,项目名称:pruebasflask,代码行数:18,代码来源:views.py

示例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'))
开发者ID:condnsdmatters,项目名称:flask-taskr,代码行数:18,代码来源:views.py


注:本文中的forms.AddTaskForm.validate_on_submit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。