def __call__(self, field, error=None, **kwargs): """Returns the recaptcha input HTML.""" config = current_handler.app.config['tipfyext.wtforms'] if config.get('recaptcha_use_ssl'): server = RECAPTCHA_SSL_API_SERVER else: server = RECAPTCHA_API_SERVER query_options = dict(k=config.get('recaptcha_public_key')) if field.recaptcha_error is not None: query_options['error'] = unicode(field.recaptcha_error) query = url_encode(query_options) # Widget default options. options = { 'theme': 'clean', 'custom_translations': { 'visual_challenge': _('Get a visual challenge'), 'audio_challenge': _('Get an audio challenge'), 'refresh_btn': _('Get a new challenge'), 'instructions_visual': _('Type the two words:'), 'instructions_audio': _('Type what you hear:'), 'help_btn': _('Help'), 'play_again': _('Play sound again'), 'cant_hear_this': _('Download sound as MP3'), 'incorrect_try_again': _('Incorrect. Try again.'), } } custom_options = config.get('recaptcha_options') if custom_options: options.update(custom_options) return RECAPTCHA_HTML % dict( script_url='%schallenge?%s' % (server, query), frame_url='%snoscript?%s' % (server, query), options=json_encode(options) )
def __call__(self, field, error=None, **kwargs): """Returns the recaptcha input HTML.""" config = current_handler.get_config('tipfyext.wtforms') if config.get('recaptcha_use_ssl'): server = RECAPTCHA_SSL_API_SERVER else: server = RECAPTCHA_API_SERVER query_options = dict(k=config.get('recaptcha_public_key')) if field.recaptcha_error is not None: query_options['error'] = unicode(field.recaptcha_error) query = url_encode(query_options) # Widget default options. options = { 'theme': 'clean', 'custom_translations': { 'visual_challenge': _('Get a visual challenge'), 'audio_challenge': _('Get an audio challenge'), 'refresh_btn': _('Get a new challenge'), 'instructions_visual': _('Type the two words:'), 'instructions_audio': _('Type what you hear:'), 'help_btn': _('Help'), 'play_again': _('Play sound again'), 'cant_hear_this': _('Download sound as MP3'), 'incorrect_try_again': _('Incorrect. Try again.'), } } custom_options = config.get('recaptcha_options') if custom_options: options.update(custom_options) return RECAPTCHA_HTML % dict(script_url='%schallenge?%s' % (server, query), frame_url='%snoscript?%s' % (server, query), options=json_encode(options))
class SigninForm(Form): # csrf_protection = True email = fields.TextField(_('Email'), [req, emailsize, emailformat]) password = fields.PasswordField(_('Password'), [req, passize]) remember = fields.BooleanField(_('Keep me signed in'))
class SignupForm(Form): # csrf_protection = True username = fields.TextField(_('User name'), [req, namesize]) email = fields.TextField(_('Email'), [req, emailsize, emailformat]) password = fields.PasswordField(_('New Password'), [req, passize]) # match
from tipfy.i18n import lazy_gettext as _ from tipfyext.wtforms import Form, fields, validators req = validators.required(message=_('This field is required')) namesize = validators.length(min=3, max=16, message=_('User name must have between %(min)d and %(max)d characters', min=3, max=16)) passize = validators.length(min=8, max=32, message=_('Password must be at least %(min)d characters long', min=8, max=32)) emailsize = validators.length(min=5, max=200, message=_('Email must have at least %(min)d characters', min=5)) emailformat = validators.email(message=_('Valid email address is required')) match = validators.equal_to('confirm', message=_('Passwords must match')) class SignupForm(Form): # csrf_protection = True username = fields.TextField(_('User name'), [req, namesize]) email = fields.TextField(_('Email'), [req, emailsize, emailformat]) password = fields.PasswordField(_('New Password'), [req, passize]) # match # confirm = fields.PasswordField(_('Repeat Password'), [req]) class SigninForm(Form): # csrf_protection = True email = fields.TextField(_('Email'), [req, emailsize, emailformat]) password = fields.PasswordField(_('Password'), [req, passize]) remember = fields.BooleanField(_('Keep me signed in'))
def test_gettext_(self): self.assertEqual(i18n._('foo'), u'foo')