def _associate_account(self, request, form, accountname, msg=None): _ = request.getText form.append(html.INPUT(type='hidden', name='oidstage', value='3')) table = html.TABLE(border='0') form.append(table) td = html.TD(colspan=2) td.append( html.Raw( _("""The username you have chosen is already taken. If it is your username, enter your password below to associate the username with your OpenID. Otherwise, please choose a different username and leave the password field blank."""))) table.append(html.TR().append(td)) if msg: td.append(html.P().append(html.STRONG().append(html.Raw(msg)))) td1 = html.TD() td1.append(html.STRONG().append(html.Raw(_('Name')))) td2 = html.TD() td2.append(html.INPUT(type='text', name='username', value=accountname)) table.append(html.TR().append(td1).append(td2)) td1 = html.TD() td1.append(html.STRONG().append(html.Raw(_('Password')))) td2 = html.TD() td2.append(html.INPUT(type='password', name='password')) table.append(html.TR().append(td1).append(td2)) td1 = html.TD() td2 = html.TD() td2.append( html.INPUT(type='submit', name='submit', value=_('Associate this name'))) table.append(html.TR().append(td1).append(td2))
def _get_account_name(self, request, form, msg=None): # now we need to ask the user for a new username # that they want to use on this wiki # XXX: request nickname from OP and suggest using it # (if it isn't in use yet) logging.debug("running _get_account_name") _ = request.getText form.append(html.INPUT(type='hidden', name='oidstage', value='2')) table = html.TABLE(border='0') form.append(table) td = html.TD(colspan=2) td.append( html.Raw( _("""Please choose an account name now. If you choose an existing account name you will be asked for the password and be able to associate the account with your OpenID."""))) table.append(html.TR().append(td)) if msg: td = html.TD(colspan='2') td.append(html.P().append(html.STRONG().append(html.Raw(msg)))) table.append(html.TR().append(td)) td1 = html.TD() td1.append(html.STRONG().append(html.Raw(_('Name')))) td2 = html.TD() td2.append(html.INPUT(type='text', name='username')) table.append(html.TR().append(td1).append(td2)) td1 = html.TD() td2 = html.TD() td2.append( html.INPUT(type='submit', name='submit', value=_('Choose this name'))) table.append(html.TR().append(td1).append(td2))
def make_form(self, explanation=None): ''' To have a consistent UI, use this method for most preferences forms and then call make_row(). See existing plugins, e.g. changepass.py. ''' action = self.request.page.url(self.request) _form = html.FORM(action=action) _form.append(html.INPUT(type="hidden", name="action", value="userprefs")) _form.append(html.INPUT(type="hidden", name="handler", value=self.name)) self._table = html.TABLE(border="0") # Use the user interface language and direction lang_attr = self.request.theme.ui_lang_attr() _form.append(html.Raw('<div class="userpref"%s>' % lang_attr)) para = html.P() _form.append(para) if explanation: para.append(explanation) para.append(self._table) _form.append(html.Raw("</div>")) return _form
def testCreate(self): """widget.html: creating html widgets TO DO: add tests for all elements by HTML 4 spec. """ tests = ( # description, call, expected ('Create text', html.Text('<br> &'), '<br> &'), ('Create raw html', html.Raw('<br> &'), '<br> &'), ('Create br', html.BR(), '<br>'), ('Create hr', html.HR(), '<hr>'), ('Create p', html.P(), '<p></p>'), ) for description, obj, expected in tests: result = unicode(obj) assert result == expected
def testCompositeElements(self): """widget.html: append to and extend composite element""" html._SORT_ATTRS = 1 element = html.P() actions = ( # action, data, expected (element.append, html.Text('Text & '), '<p>Text & </p>'), (element.append, html.Text('more text. '), '<p>Text & more text. </p>'), (element.extend, (html.Text('And then '), html.Text('some.')), '<p>Text & more text. And then some.</p>'), ) for action, data, expected in actions: action(data) result = unicode(element) assert result == expected
def _create_prefs_page(request, sel=None): _ = request.getText plugins = wikiutil.getPlugins('userprefs', request.cfg) ret = html.P() ret.append(html.Text(_("Please choose:"))) ret.append(html.BR()) items = html.UL() ret.append(items) for sub in plugins: if sub in request.cfg.userprefs_disabled: continue cls = wikiutil.importPlugin(request.cfg, 'userprefs', sub, 'Settings') obj = cls(request) if not obj.allowed(): continue url = request.page.url(request, {'action': 'userprefs', 'sub': sub}) lnk = html.LI().append(html.A(href=url).append(html.Text(obj.title))) items.append(lnk) return unicode(ret)
def create_form(self): """ Create the complete HTML form code. """ _ = self._ ret = html.P() # Use the user interface language and direction lang_attr = self.request.theme.ui_lang_attr() ret.append(html.Raw('<div %s>' % lang_attr)) self._table = html.TABLE(border="0") ret.append(self._table) ret.append(html.Raw("</div>")) request = self.request if hasattr(request.user, 'openid_trusted_roots') and request.user.openid_trusted_roots: self._trust_root_list() form = self._make_form() label = _("Cancel") form.append(html.INPUT(type="submit", name='cancel', value=label)) self._make_row('', [form]) return unicode(ret)
def create_form(self): """ Create the complete HTML form code. """ _ = self._ ret = html.P() # Use the user interface language and direction lang_attr = self.request.theme.ui_lang_attr() ret.append(html.Raw('<div %s>' % lang_attr)) self._table = html.TABLE(border="0") ret.append(self._table) ret.append(html.Raw("</div>")) request = self.request if 'openid.prefs.form_html' in request.session: txt = _('OpenID verification requires that you click this button:') # create JS to automatically submit the form if possible submitjs = """<script type="text/javascript"> <!--// document.getElementById("openid_message").submit(); //--> </script> """ oidhtml = request.session['openid.prefs.form_html'] del request.session['openid.prefs.form_html'] return ''.join([txt, oidhtml, submitjs]) if hasattr(request.user, 'openids') and request.user.openids: self._oidlist() self._addoidform() form = self._make_form() label = _("Cancel") form.append(html.INPUT(type="submit", name='cancel', value=label)) self._make_row('', [form]) return unicode(ret)
def asHTML(self): """ Create the complete HTML form code. """ _ = self._ request = self.request action = "%s%s" % (request.script_root, request.path) hints = [] for authm in request.cfg.auth: hint = authm.login_hint(request) if hint: hints.append(hint) self._form = html.FORM(action=action, name="loginform", id="loginform") self._table = html.TABLE(border="0") # Use the user interface language and direction lang_attr = request.theme.ui_lang_attr() self._form.append(html.Raw('<div class="userpref"%s>' % lang_attr)) self._form.append( html.INPUT(type="hidden", name="action", value="login")) self._form.append(self._table) for hint in hints: self._form.append(html.P().append(html.Raw(hint))) self._form.append(html.Raw("</div>")) cfg = request.cfg if 'username' in cfg.auth_login_inputs: self.make_row(_('Name'), [ html.INPUT( type="text", size="32", name="name", ), ]) if 'password' in cfg.auth_login_inputs: self.make_row(_('Password'), [ html.INPUT( type="password", size="32", name="password", ), ]) # Restrict type of input available for OpenID input # based on wiki configuration. if 'openid_identifier' in cfg.auth_login_inputs: if len(cfg.openidrp_allowed_op) == 1: self.make_row(_('OpenID'), [ html.INPUT(type="hidden", name="openid_identifier", value=cfg.openidrp_allowed_op[0]), ]) elif len(cfg.openidrp_allowed_op) > 1: op_select = html.SELECT(name="openid_identifier", id="openididentifier") for op_uri in cfg.openidrp_allowed_op: op_select.append( html.OPTION(value=op_uri).append(html.Raw(op_uri))) self.make_row(_('OpenID'), [ op_select, ]) else: self.make_row(_('OpenID'), [ html.INPUT(type="text", size="32", name="openid_identifier", id="openididentifier"), ]) # Need both hidden field and submit values for auto-submit to work self.make_row('', [ html.INPUT(type="hidden", name="login", value=_('Login')), html.INPUT(type="submit", name='login', value=_('Login')), ]) # Automatically submit the form if only a single OpenID Provider is allowed if 'openid_identifier' in cfg.auth_login_inputs and len( cfg.openidrp_allowed_op) == 1: self._form.append("""<script type="text/javascript"> <!--// document.getElementById("loginform").submit(); //--> </script> """) return unicode(self._form)