本文整理汇总了Python中forms.TestForm.validate_on_submit方法的典型用法代码示例。如果您正苦于以下问题:Python TestForm.validate_on_submit方法的具体用法?Python TestForm.validate_on_submit怎么用?Python TestForm.validate_on_submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.TestForm
的用法示例。
在下文中一共展示了TestForm.validate_on_submit方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: home
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import validate_on_submit [as 别名]
def home():
form = TestForm()
if form.validate_on_submit():
name = form.name.data
return render_template("home.html", form=form, name=name)
return render_template("home.html", form=form, logout=users.create_logout_url(request.url))
示例2: cso_testing
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import validate_on_submit [as 别名]
def cso_testing(page=1):
if g.user.role.name == ROLE_HEAD_OF_INFORMATION_SECURITY:
is_tm_answered_on_questions = ApplicationData.is_tm_answered_on_questions()
chosen_processes = UserChoice.user_choice_processes_by_role_id(g.user.role_id).paginate(page, 1, False)
if is_tm_answered_on_questions.status:
current_process = chosen_processes.items[0]
questions_by_process = Question.chosen_questions(current_process.id).all()
else:
current_process = None
questions_by_process = []
form = TestForm(questions=questions_by_process)
is_cso_answered_on_questions = ApplicationData.is_cso_answered_on_questions()
if form.validate_on_submit():
if form.finish.data:
save_answers_to_db(form, g.user.role_id, current_process.id)
if not is_cso_answered_on_questions.status:
is_cso_answered_on_questions.status = bool(not is_cso_answered_on_questions.status)
is_cso_answered_on_questions.update()
make_statistic()
return redirect(url_for('cso'))
if form.next_page.data:
save_answers_to_db(form, g.user.role_id, current_process.id)
page = chosen_processes.next_num
return redirect(url_for('cso_testing', page=page))
html = render_template('roles/cso_testing.html', form=form,
current_process=current_process,
is_tm_answered_on_questions=is_tm_answered_on_questions,
is_cso_answered_on_questions=is_cso_answered_on_questions,
processes=chosen_processes,
investment_level=UserChoice.user_choice_chosen_investment_level())
return __make_tooltips(html)
else:
return u'Вы не можете получить доступ к этой странице'
示例3: tm
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import validate_on_submit [as 别名]
def tm(page=1):
if g.user.role.name == ROLE_HEAD_OF_TACTICAL_LEVEL:
is_om_answered_on_questions = ApplicationData.is_om_answered_on_questions()
try:
chosen_processes = UserChoice.user_choice_processes_by_role_id(g.user.role_id).paginate(page, 1, False)
except NoResultFound:
chosen_processes = []
if is_om_answered_on_questions.status:
current_process = chosen_processes.items[0]
questions_by_process = Question.chosen_questions(current_process.id).all()
else:
current_process = None
questions_by_process = []
form = TestForm(questions=questions_by_process)
is_tm_answered_on_questions = ApplicationData.is_tm_answered_on_questions()
if form.validate_on_submit():
if form.finish.data:
page = chosen_processes.pages
save_answers_to_db(form, g.user.role_id, current_process.id)
if not is_tm_answered_on_questions.status:
is_tm_answered_on_questions.status = bool(not is_tm_answered_on_questions.status)
is_tm_answered_on_questions.update()
if form.next_page.data:
save_answers_to_db(form, g.user.role_id, current_process.id)
page = chosen_processes.next_num
return redirect(url_for('tm', page=page))
html = render_template('roles/tm.html', form=form,
current_process=current_process,
is_om_answered_on_questions=is_om_answered_on_questions,
is_tm_answered_on_questions=is_tm_answered_on_questions,
processes=chosen_processes,
investment_level=UserChoice.user_choice_chosen_investment_level())
return __make_tooltips(html)
else:
return u'Вы не можете получить доступ к этой странице'
示例4: new_test
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import validate_on_submit [as 别名]
def new_test():
form = TestForm()
if form.validate_on_submit():
test = Test(
test_name=form.test_name.data,
num_mc=form.num_mc.data,
mc_answers = int(form.mc_answers.data),
num_or=form.num_or.data,
#or_points = int(form.or_points.data),
num_students=form.num_students.data,
#test_data = defaultGrid(form.num_mc.data, int(form.mc_answers.data), form.num_or.data, form.or_points.data,form.num_students.data),
mc_data = mcDetails(form.num_mc.data, int(form.mc_answers.data)),
or_data = orDetails(form.num_mc.data,form.num_or.data),
student_data = studentDetails(form.num_students.data),
added_by=session['email']
)
try:
test.put()
test_id = test.key.id()
test = Test.get_by_id(test_id)
mc_data = json.dumps(test.mc_data)
or_data = json.dumps(test.or_data)
student_data = json.dumps(test.student_data)
flash(u'Test %s successfully saved.' % test_id, 'success')
return render_template('test_details.html', test = Test.get_by_id(test_id), test_id = test_id, mc_data = mc_data, or_data = or_data, student_data = student_data)
except CapabilityDisabledError:
flash(u'App Engine Datastore is currently in read-only mode.', 'info')
return redirect(url_for('list_tests'))
return redirect(url_for('list_tests'))
示例5: cio
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import validate_on_submit [as 别名]
def cio(page=1):
"""
Отображение страницы для CIO
:param page: номер страницы (int)
:return: html
"""
# Проверяем полномочия пользователя (пользователь может просматривать страницы только по своему уровню доступа)
if g.user.role.name == ROLE_HEAD_OF_BASE_LEVEL:
# Получаем информацию о состоянии системы
is_cso_choose_processes = ApplicationData.is_cso_choose_processes()
# Получаем процессы, по которым должен пользователь пройти тестирование
# метод paginate(page, count, error_out) возвращает список объектов в количестве count на страницу page
# тем самым добиваемся того, что тестирование по 1 процессу является 1 страница
try:
chosen_processes = UserChoice.user_choice_processes_by_role_id(g.user.role_id).paginate(page, 1, False)
except NoResultFound:
chosen_processes = []
if is_cso_choose_processes.status:
# Определяем текущий процесс и список вопросов, которые нужно будет отрисовать на форме
current_process = chosen_processes.items[0]
questions_by_process = Question.chosen_questions(current_process.id).all()
else:
# Эта ветвь необходима для корректного завершения функции (например, когда тестирование не началось,
# а CSO прошёл аутентификацию
current_process = None
questions_by_process = []
# Создаём форму, в которую будут поступать ответы пользователя
form = TestForm(questions=questions_by_process)
is_cio_answered_on_questions = ApplicationData.is_cio_answered_on_questions()
# Форма прошла валидацию и отправлена?
if form.validate_on_submit():
# Тестирование завершено?
if form.finish.data:
page = chosen_processes.pages
# Сохраняем ответы в базу данных
save_answers_to_db(form, g.user.role_id, current_process.id)
if not is_cio_answered_on_questions.status:
# Изменяем параметр пройденности тестирования пользователя cio на обратное (False -> True)
is_cio_answered_on_questions.status = bool(not is_cio_answered_on_questions.status)
# Сохраняем параметр в базе данных
is_cio_answered_on_questions.update()
# Если пользователю предстоит проходить тестирование по нескольким процессам,
# и есть ещё процессы, на вопросы которых он не ответил,
# то сохраняем ответы со страницы и изменяем номер страницы на 1
if form.next_page.data:
save_answers_to_db(form, g.user.role_id, current_process.id)
page = chosen_processes.next_num
# Перенаправление пользователя на новый номер страницы
return redirect(url_for('cio', page=page))
# Отрисовка страницы
html = render_template('roles/cio.html', form=form,
current_process=current_process,
is_cso_choose_processes=is_cso_choose_processes,
is_cio_answered_on_questions=is_cio_answered_on_questions,
processes=chosen_processes,
investment_level=UserChoice.user_choice_chosen_investment_level())
return __make_tooltips(html)
else:
return u'Вы не можете получить доступ к этой странице'
示例6: edit_test
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import validate_on_submit [as 别名]
def edit_test(test_id):
test = Test.get_by_id(test_id)
form = TestForm(obj=test)
if request.method == "POST":
if form.validate_on_submit():
test.test_name = form.data.get('test_name')
test.num_mc = form.data.get('num_mc')
test.num_or = form.data.get('num_or')
#test.num_students = json.dumps(form.data.get('num_students'))
test.num_students = form.data.get('num_students')
test.put()
flash(u'Test %s successfully saved.' % test_id, 'success')
return redirect(url_for('list_tests'))
return render_template('edit_test.html', test=test, form=form)