Example #1
0
def quiz(ws_url, db_handler, html_function):
    d = _doc('Quiz')
    with d:
        with t.fieldset(cls='small_fieldset'):
            # Content container - filtered results themselves will be fed into here, via websocket (see _js_socket_quiz_manager):
            t.div(
                id='content', cls='quiz_content'
            )  # Note: this container will contain another div of the same class, in which everything "real" will go; see _multi_choice_question
            t.button('Go', id="go", cls='quiz_button')

        with t.fieldset(cls='small_fieldset'):
            _dropdown(
                t.div(cls='dropdown'), 'choose_subject',
                (('Timeline (sequence)', _gurl(settings.k_history_sequence)),
                 ('Science grammar', _gurl(settings.k_science_grammar)),
                 ('English vocabulary', _gurl(settings.k_english_vocabulary)),
                 ('English grammar', _gurl(settings.k_english_grammar)),
                 ('Latin vocabulary', _gurl(settings.k_latin_vocabulary))),
                True, 'Subjects...')
            _dropdown(t.div(cls='dropdown'), 'cycle_dropdown',
                      (('Cycle 1', 'bogus'), ('Cycle 2', 'bogus'),
                       ('Cycle 3', 'bogus'), ('All Cycles', 'bogus'),
                       ('My Cycle', 'bogus')), True, 'Cycles...')
            _dropdown(t.div(cls='dropdown'), 'weeks_dropdown',
                      (('...', 'bogus'), ('All Weeks', 'bogus')), True,
                      'Weeks...')
            _dropdown(t.div(cls='dropdown'), 'difficulty_dropdown',
                      (('Easy', 'bogus'), ('Medium', 'bogus'),
                       ('Difficult', 'bogus')), True, 'Difficulty...')

        # JS (intentionally at bottom of file; see https://faqs.skillcrush.com/article/176-where-should-js-script-tags-be-linked-in-html-documents and many stackexchange answers):
        t.script(_js_socket_quiz_manager(ws_url, db_handler, html_function))
        t.script(_js_dropdown())
    return d.render()
Example #2
0
def new_user(form, ws_url, errors=None):
    title = 'New User'
    d = _doc(title)
    with d:
        with t.form(action=form.action, method='post'):
            with t.fieldset():
                t.legend(title)
                _errors(errors)
                with t.ol(cls='step_numbers'):
                    with t.li():
                        t.p('First, create a one-word username for yourself (lowercase, no spaces)...'
                            )
                        _text_input(
                            *form.nv('new_username'),
                            ('required', 'autofocus'), {
                                'pattern': valid.re_username,
                                'oninput': 'check_username(this.value)'
                            }, 'Type new username here',
                            _invalid(valid.inv_username,
                                     form.invalid('new_username')))
                        _invalid(valid.inv_username_exists, False,
                                 'username_exists_message')
                    with t.li():
                        t.p("Next, invent a password; type it in twice to make sure you've got it..."
                            )
                        _text_input('password',
                                    None, ('required', ),
                                    {'pattern': valid.re_password},
                                    'Type new password here',
                                    _invalid(valid.inv_password,
                                             form.invalid('password')),
                                    type_='password')
                        _text_input('password_confirmation',
                                    None, ('required', ),
                                    None,
                                    'Type password again for confirmation',
                                    _invalid(
                                        valid.inv_password_confirmation,
                                        form.invalid('password_confirmation'),
                                        'password_match_message'),
                                    type_='password')
                    with t.li():
                        t.p("Finally, type in an email address that can be used if you ever need a password reset (optional, but this may be very useful someday!)..."
                            )
                        _text_input(
                            *form.nv('email'), None,
                            {'pattern': valid.re_email},
                            'Type email address here',
                            _invalid(valid.inv_email, form.invalid('email')))
                t.input_(type="submit", value="Done!")
        t.script(_js_validate_new_user_fields())
        t.script(_js_check_username(ws_url))
    return d.render()
def test1(form, title_prefix, button_title):
    title = title_prefix + ' Test 1'
    d = _doc(title)
    with d:
        with t.form(action=form.action, method='post'):
            with t.fieldset():
                t.legend(title)
                with t.div(cls='form_row'):
                    _text_input(*form.nv('name'), ('autofocus', 'required'),
                                {'pattern': valid.re_alphanum})
            with t.div(cls='form_row'):
                t.input(type='submit', value=button_title)
    return d.render()
Example #4
0
 def __init__(self, title, **kwargs):
     super().__init__(id=self.id, method=self.method, **kwargs)
     with self.add(tags.fieldset()):
         tags.legend(title, style="display: flex;")
         self.content = tags.div()
         tags.input(name=f"{self.id}", type='hidden')
         tags.input(_class='selection', name='selection', type='hidden')
         tags.input(_class='order', name='order', type='hidden')
         self.submit_tag = tags.input(id=f"{self.submit_id}",
                                      type='submit',
                                      name='submit_button',
                                      _class='submit_button',
                                      value=self.submission_label,
                                      style="clear: both; width: 100%; " +
                                      "margin-top: 20px;")
         self.on_ready_scriptage = ""
Example #5
0
def login(action, error=None):
    d = _doc('OHS-Test Login')
    with d:
        with t.form(action=action, method='post'):
            with t.fieldset(cls='small_fieldset'):
                t.legend('Log in...')
                _error(error)
                t.div(_text_input('username',
                                  None, ('required', 'autofocus'),
                                  {'pattern': valid.re_username},
                                  invalid_div=_invalid(valid.inv_username,
                                                       False)),
                      cls='field')
                t.div(_text_input('password',
                                  None, ('required', ),
                                  type_='password'),
                      cls='field')
                t.div(t.input_(type="submit", value="Log in!"), cls='field')
        t.script(_js_validate_login_fields())
    return d.render()