def context_validate(self, data): if data['cache_system'] == 'memcached': if not data['memcached_servers']: raise ValidationError(_(u'You have to provide at least one ' u'server to use memcached.')) elif data['cache_system'] == 'filesystem': if not data['filesystem_cache_path']: raise ValidationError(_(u'You have to provide cache folder to ' u'use filesystem cache.'))
def validator(form, value): parts = urlparse.urlsplit(value) if parts.scheme not in ['http', 'https']: raise ValidationError(lazy_gettext(u'URLs must be of type '\ u'http or https.')) elif parts.fragment: raise ValidationError(lazy_gettext(u'URLs may not have a '\ u'#reference part.')) elif parts.netloc.find('@') != -1: raise ValidationError(lazy_gettext(u'URLs should not be specified '\ u'with username and password.')) elif parts.query: raise ValidationError(lazy_gettext(u'URLs may not have a ?query.'))
def validate(form, apikey): blog_url = get_application().cfg['blog_url'] cachekey = (apikey, blog_url) if cachekey in _verified_keys: return data = {'key': apikey, 'blog': blog_url} resp = send_request(apikey, False, data, 'verify-key') if resp is None: raise ValidationError( _('Could not verify key because of a ' 'server to server connection error.')) elif resp != 'valid': raise ValidationError(message) if memorize: _verified_keys.add(cachekey)
def validate_slug(self, value): """Make sure the slug is unique.""" query = Category.query.filter_by(slug=value) if self.category is not None: query = query.filter(Category.id != self.category.id) existing = query.first() if existing is not None: raise ValidationError(_('This slug is already in use'))
class LiveJournalImportForm(forms.Form): """This form asks the user for authorisation and import options.""" username = forms.TextField(lazy_gettext(u'LiveJournal username'), required=True, validators=[is_valid_lj_user()]) password = forms.TextField(lazy_gettext(u'LiveJournal password'), required=True, widget=forms.PasswordInput) import_what = forms.ChoiceField(lazy_gettext(u'Import what?'), choices=[(IMPORT_JOURNAL, lazy_gettext(u'My Journal')), (IMPORT_COMMUNITY, lazy_gettext(u'My Posts in Community')), (IMPORT_COMMUNITY_ALL, lazy_gettext(u'Everything in Community'))], help_text=lazy_gettext(u'Importing a community requires '\ u'administrative access to the community.'), default=IMPORT_JOURNAL, required=True, widget=forms.RadioButtonGroup) community = forms.TextField(lazy_gettext(u'Community name')) security_choices = [(SECURITY_DISCARD, lazy_gettext(u'Don’t import')), (SECURITY_PRIVATE, lazy_gettext(u'Private')), (SECURITY_PROTECTED, lazy_gettext(u'Protected')), (SECURITY_PUBLIC, lazy_gettext(u'Public'))] security_custom = forms.ChoiceField(lazy_gettext( u'Convert custom-security entries to'), choices=security_choices, help_text=lazy_gettext(u'Zine only supports public, private and '\ u'protected entries, so you must choose '\ u'what to do with your custom security '\ u'entries.')) categories = forms.Multiple(forms.TextField(), lazy_gettext(u'Categories'), help_text=lazy_gettext(u'Choose categories to '\ u'assign imported posts to.'), widget=forms.CheckboxGroup) getcomments = forms.BooleanField(lazy_gettext(u'Download Comments?')) def __init__(self, initial=None): initial = forms.fill_dict( initial, getcomments=True, import_what=IMPORT_JOURNAL, security_custom=SECURITY_PROTECTED, ) self.categories.choices = [(c.name, c.name) for c in zine.models.Category.query.all()] forms.Form.__init__(self, initial) def context_validate(self, data): lj = LiveJournalConnect(data['username'], data['password']) try: result = lj.login() except xmlrpclib.Fault, fault: raise ValidationError(fault.faultString) if data['import_what'] in [IMPORT_COMMUNITY, IMPORT_COMMUNITY_ALL]: if data['community'] not in result.get('usejournals', []): raise ValidationError(lazy_gettext(u'You do not have access '\ u'to the specified community.'))
def validate_old_password(self, value): if not self.user.check_password(value): raise ValidationError(_('The old password you\'ve ' 'entered is wrong.'))
def validator(form, value): if value.find(':') != -1 or value.find('@') != -1: raise ValidationError(message)
def context_validate(self, data): if not self.post.comments_enabled: raise ValidationError(_('Post is closed for commenting.'))
def validate(form, level): if not isinstance(level, int) or level < 1 or level > 6: raise ValidationError(message)
def validate_parser(self, value): """Make sure the missing parser is not selected.""" if self.parser_missing and value == self.post.parser: raise ValidationError(_('Selected parser is no longer ' 'available on the system.'))
def validate_username(self, value): query = User.query.filter_by(username=value) if self.user is not None: query = query.filter(User.id != self.user.id) if query.first() is not None: raise ValidationError(_('This username is already in use'))
def context_validate(self, data): if data['action'] == 'reassign' and not data['reassign_to']: # XXX: Bad wording raise ValidationError(_('You have to select the user that ' 'gets the posts assigned.'))
def validate_parent(self, value): if value.post != self.post: #_ this message is only displayed if the user tempered with #_ the form data raise ValidationError(_('Invalid object referenced.'))
def context_validate(self, data): lj = LiveJournalConnect(data['username'], data['password']) try: result = lj.login() except xmlrpclib.Fault, fault: raise ValidationError(fault.faultString)
def context_validate(self, data): if data['action'] == 'relocate' and not data['relocate_to']: raise ValidationError(_('You have to select a group that ' 'gets the users assigned.'))
def validate_groupname(self, value): query = Group.query.filter_by(name=value) if self.group is not None: query = query.filter(Group.id != self.group.id) if query.first() is not None: raise ValidationError(_('This groupname is already in use'))
def context_validate(self, data): if not data['user'].check_password(data['password']): log.warning(_(u'Failed login attempt from “%s”, invalid password') % data['user'].username, 'auth') raise ValidationError(_('Incorrect password.'))
def validator(form, value): if not value or re.search('[^a-z0-9_]', value): raise ValidationError(message % value)
def context_validate(self, data): if data['new_password'] != data['check_password']: raise ValidationError(_('The two passwords don\'t match.'))