def validate_slug(self, value): slug_validator( value, lower=False, message=ugettext(u'The custom URL must consist of letters, ' u'numbers, underscores or hyphens.')) if DeniedName.blocked(value): raise serializers.ValidationError( ugettext(u'This custom URL cannot be used.')) return value
def validate_name(self, value): # if we have a localised dict of values validate them all. if isinstance(value, dict): return {locale: self.validate_name(sub_value) for locale, sub_value in value.iteritems()} if value.strip() == u'': raise serializers.ValidationError( ugettext(u'Name cannot be empty.')) if DeniedName.blocked(value): raise serializers.ValidationError( ugettext(u'This name cannot be used.')) return value
def autocreate_username(candidate, tries=1): """Returns a unique valid username.""" max_tries = settings.MAX_GEN_USERNAME_TRIES from olympia.amo.utils import slugify, SLUG_OK make_u = partial(slugify, ok=SLUG_OK, lower=True, spaces=False, delimiter='-') adjusted_u = make_u(candidate) if tries > 1: adjusted_u = '%s%s' % (adjusted_u, tries) if (DeniedName.blocked(adjusted_u) or adjusted_u == '' or tries > max_tries or len(adjusted_u) > 255): log.info('username blocked, empty, max tries reached, or too long;' ' username=%s; max=%s' % (adjusted_u, max_tries)) return autocreate_username(uuid.uuid4().hex[0:15]) if UserProfile.objects.filter(username=adjusted_u).count(): return autocreate_username(candidate, tries=tries + 1) return adjusted_u
def validate_username(self, value): # All-digits usernames are disallowed since they can be confused for # user IDs in URLs. if value.isdigit(): raise serializers.ValidationError( ugettext(u'Usernames cannot contain only digits.')) slug_validator( value, lower=False, message=ugettext(u'Enter a valid username consisting of letters, ' u'numbers, underscores or hyphens.')) if DeniedName.blocked(value): raise serializers.ValidationError( ugettext(u'This username cannot be used.')) # Bug 858452. Remove this check when collation of the username # column is changed to case insensitive. if (UserProfile.objects.exclude(id=self.instance.id) .filter(username__iexact=value).exists()): raise serializers.ValidationError( ugettext(u'This username is already in use.')) return value
def validate_username(self, value): # All-digits usernames are disallowed since they can be confused for # user IDs in URLs. if value.isdigit(): raise serializers.ValidationError( ugettext(u'Usernames cannot contain only digits.')) slug_validator(value, lower=False, message=ugettext( u'Enter a valid username consisting of letters, ' u'numbers, underscores or hyphens.')) if DeniedName.blocked(value): raise serializers.ValidationError( ugettext(u'This username cannot be used.')) # Bug 858452. Remove this check when collation of the username # column is changed to case insensitive. if (UserProfile.objects.exclude(id=self.instance.id).filter( username__iexact=value).exists()): raise serializers.ValidationError( ugettext(u'This username is already in use.')) return value
def test_blocked(self): assert DeniedName.blocked('IE6Fan') assert DeniedName.blocked('IE6fantastic') assert not DeniedName.blocked('IE6') assert not DeniedName.blocked('testo')
def validate_reviewer_name(self, value): if DeniedName.blocked(value): raise serializers.ValidationError( ugettext(u'This reviewer name cannot be used.')) return value
def clean_name(self): name = self.cleaned_data['name'] if DeniedName.blocked(name): raise forms.ValidationError(ugettext('This name cannot be used.')) return name
def validate_display_name(self, value): if DeniedName.blocked(value): raise serializers.ValidationError( ugettext(u'This display name cannot be used.')) return value
def validate_display_name(self, value): if DeniedName.blocked(value): raise serializers.ValidationError( gettext('This display name cannot be used.') ) return value
def clean_name(self): name = self.cleaned_data["name"] if DeniedName.blocked(name): raise forms.ValidationError(_("This name cannot be used.")) return name