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


Python forms.TestForm类代码示例

本文整理汇总了Python中forms.TestForm的典型用法代码示例。如果您正苦于以下问题:Python TestForm类的具体用法?Python TestForm怎么用?Python TestForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TestForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: new_test

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'))
开发者ID:nbcesar,项目名称:sabered,代码行数:29,代码来源:views.py

示例2: tm

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'Вы не можете получить доступ к этой странице'
开发者ID:dimV36,项目名称:webtests,代码行数:35,代码来源:views.py

示例3: home

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))
开发者ID:joesoc,项目名称:Flask-Gae-Init,代码行数:7,代码来源:views.py

示例4: test_multiwidget_field

    def test_multiwidget_field(self):
        template = get_template_from_string(
            u"""
            {% load crispy_forms_tags %}
            {% crispy form %}
        """
        )

        test_form = TestForm()
        test_form.helper = FormHelper()
        test_form.helper.layout = Layout(
            MultiWidgetField(
                "datetime_field",
                attrs=({"rel": "test_dateinput"}, {"rel": "test_timeinput", "style": "width: 30px;", "type": "hidden"}),
            )
        )

        c = Context({"form": test_form})

        html = template.render(c)
        self.assertEqual(html.count('class="dateinput"'), 1)
        self.assertEqual(html.count('rel="test_dateinput"'), 1)
        self.assertEqual(html.count('rel="test_timeinput"'), 1)
        self.assertEqual(html.count('style="width: 30px;"'), 1)
        self.assertEqual(html.count('type="hidden"'), 1)
开发者ID:irumiha,项目名称:django-crispy-forms,代码行数:25,代码来源:tests.py

示例5: test_field_with_buttons

    def test_field_with_buttons(self):
        form = TestForm()
        form.helper = FormHelper()
        form.helper.layout = Layout(
            FieldWithButtons(
                Field("password1", css_class="span4"),
                StrictButton("Go!", css_id="go-button"),
                StrictButton("No!", css_class="extra"),
                StrictButton("Test", type="submit", name="whatever", value="something"),
                css_class="extra",
                autocomplete="off",
            )
        )
        html = render_crispy_form(form)
        self.assertEqual(html.count('class="control-group extra"'), 1)
        self.assertEqual(html.count('autocomplete="off"'), 1)
        self.assertEqual(html.count('class="input-append"'), 1)
        self.assertEqual(html.count('class="span4'), 1)
        self.assertEqual(html.count('id="go-button"'), 1)
        self.assertEqual(html.count("Go!"), 1)
        self.assertEqual(html.count("No!"), 1)
        self.assertEqual(html.count('class="btn"'), 2)
        self.assertEqual(html.count('class="btn extra"'), 1)
        self.assertEqual(html.count('type="submit"'), 1)
        self.assertEqual(html.count('name="whatever"'), 1)
        self.assertEqual(html.count('value="something"'), 1)

        if settings.CRISPY_TEMPLATE_PACK == "bootstrap":
            # Make sure white spaces between buttons are there in bootstrap
            self.assertEqual(len(re.findall(r"</button> <", html)), 3)
开发者ID:irumiha,项目名称:django-crispy-forms,代码行数:30,代码来源:tests.py

示例6: test_form_show_errors_non_field_errors

    def test_form_show_errors_non_field_errors(self):
        form = TestForm({'password1': 'wargame', 'password2': 'god'})
        form.helper = FormHelper()
        form.helper.form_show_errors = True
        form.is_valid()

        template = get_template_from_string(u"""
            {% load crispy_forms_tags %}
            {% crispy testForm %}
        """)

        # First we render with errors
        c = Context({'testForm': form})
        html = template.render(c)

        # Ensure those errors were rendered
        self.assertTrue('<li>Passwords dont match</li>' in html)
        self.assertTrue(unicode(_('This field is required.')) in html)
        self.assertTrue('error' in html)

        # Now we render without errors
        form.helper.form_show_errors = False
        c = Context({'testForm': form})
        html = template.render(c)

        # Ensure errors were not rendered
        self.assertFalse('<li>Passwords dont match</li>' in html)
        self.assertFalse(unicode(_('This field is required.')) in html)
        self.assertFalse('error' in html)
开发者ID:KurtRao,项目名称:django-exadmin,代码行数:29,代码来源:tests.py

示例7: test_form_show_errors

    def test_form_show_errors(self):
        form = TestForm(
            {
                "email": "invalidemail",
                "first_name": "first_name_too_long",
                "last_name": "last_name_too_long",
                "password1": "yes",
                "password2": "yes",
            }
        )
        form.helper = FormHelper()
        form.helper.layout = Layout(
            AppendedText("email", "whatever"),
            PrependedText("first_name", "blabla"),
            AppendedPrependedText("last_name", "foo", "bar"),
            MultiField("legend", "password1", "password2"),
        )
        form.is_valid()

        form.helper.form_show_errors = True
        html = render_crispy_form(form)
        self.assertEqual(html.count("error"), 6)

        form.helper.form_show_errors = False
        html = render_crispy_form(form)
        self.assertEqual(html.count("error"), 0)
开发者ID:irumiha,项目名称:django-crispy-forms,代码行数:26,代码来源:tests.py

示例8: test_multiwidget_field

    def test_multiwidget_field(self):
        template = get_template_from_string(u"""
            {% load crispy_forms_tags %}
            {% crispy form %}
        """)

        test_form = TestForm()
        test_form.helper = FormHelper()
        test_form.helper.layout = Layout(
            MultiWidgetField(
                'datetime_field',
                attrs=(
                    {'rel': 'test_dateinput'},
                    {'rel': 'test_timeinput', 'style': 'width: 30px;', 'type': "hidden"}
                )
            )
        )

        c = Context({'form': test_form})

        html = template.render(c)
        self.assertEqual(html.count('class="dateinput"'), 1)
        self.assertEqual(html.count('rel="test_dateinput"'), 1)
        self.assertEqual(html.count('rel="test_timeinput"'), 1)
        self.assertEqual(html.count('style="width: 30px;"'), 1)
        self.assertEqual(html.count('type="hidden"'), 1)
开发者ID:KurtRao,项目名称:django-exadmin,代码行数:26,代码来源:tests.py

示例9: test_form_show_errors_non_field_errors

    def test_form_show_errors_non_field_errors(self):
        form = TestForm({"password1": "wargame", "password2": "god"})
        form.helper = FormHelper()
        form.helper.form_show_errors = True
        form.is_valid()

        template = get_template_from_string(
            u"""
            {% load crispy_forms_tags %}
            {% crispy testForm %}
        """
        )

        # First we render with errors
        c = Context({"testForm": form})
        html = template.render(c)

        # Ensure those errors were rendered
        self.assertTrue("<li>Passwords dont match</li>" in html)
        self.assertTrue(unicode(_("This field is required.")) in html)
        self.assertTrue("error" in html)

        # Now we render without errors
        form.helper.form_show_errors = False
        c = Context({"testForm": form})
        html = template.render(c)

        # Ensure errors were not rendered
        self.assertFalse("<li>Passwords dont match</li>" in html)
        self.assertFalse(unicode(_("This field is required.")) in html)
        self.assertFalse("error" in html)
开发者ID:irumiha,项目名称:django-crispy-forms,代码行数:31,代码来源:tests.py

示例10: test_getitem_by_field_name

 def test_getitem_by_field_name(self):
     form = TestForm()
     form.helper = FormHelper(form)
     layout = Layout(Div("email"), "password1")
     form.helper.layout = layout
     form.helper["email"].wrap(Field, css_class="hero")
     self.assertTrue(isinstance(layout.fields[0].fields[0], Field))
开发者ID:irumiha,项目名称:django-crispy-forms,代码行数:7,代码来源:tests.py

示例11: cso_testing

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'Вы не можете получить доступ к этой странице'
开发者ID:dimV36,项目名称:webtests,代码行数:33,代码来源:views.py

示例12: cio

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'Вы не можете получить доступ к этой странице'
开发者ID:dimV36,项目名称:webtests,代码行数:59,代码来源:views.py

示例13: test_attrs

    def test_attrs(self):
        form = TestForm()
        form.helper = FormHelper()
        form.helper.attrs = {'id': 'TestIdForm', 'autocomplete': "off"}
        html = render_crispy_form(form)

        self.assertTrue('autocomplete="off"' in html)
        self.assertTrue('id="TestIdForm"' in html)
开发者ID:KurtRao,项目名称:django-exadmin,代码行数:8,代码来源:tests.py

示例14: test_exclude_by_widget

 def test_exclude_by_widget(self):
     form = TestForm()
     form.helper = FormHelper(form)
     form.helper.layout = self.advanced_layout
     self.assertEqual(
         form.helper.exclude_by_widget(forms.PasswordInput).slice,
         [[[0, 0, 0, 0], "email"], [[0, 3, 0], "first_name"], [[1], "last_name"]],
     )
开发者ID:irumiha,项目名称:django-crispy-forms,代码行数:8,代码来源:tests.py

示例15: test_filter_by_widget

 def test_filter_by_widget(self):
     form = TestForm()
     form.helper = FormHelper(form)
     form.helper.layout = self.advanced_layout
     self.assertEqual(form.helper.filter_by_widget(forms.PasswordInput).slice, [
         [[0, 1, 0, 0], 'password1'],
         [[0, 4, 0], 'password2'],
     ])
开发者ID:KurtRao,项目名称:django-exadmin,代码行数:8,代码来源:tests.py


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