Example #1
0
    def clean_username(self):
        name = self.cleaned_data['username']

        if not name:
            if self.instance.has_anonymous_username:
                name = self.instance.username
            else:
                name = self.instance.anonymize_username()

        # All-digits usernames are disallowed since they can be
        # confused for user IDs in URLs. (See bug 862121.)
        if name.isdigit():
            raise forms.ValidationError(
                ugettext('Usernames cannot contain only digits.'))

        slug_validator(
            name, lower=False,
            message=ugettext(
                'Enter a valid username consisting of letters, numbers, '
                'underscores or hyphens.'))
        if DeniedName.blocked(name):
            raise forms.ValidationError(
                ugettext('This username cannot be used.'))

        # FIXME: 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=name).exists()):
            raise forms.ValidationError(
                ugettext('This username is already in use.'))

        return name
Example #2
0
    def clean_username(self):
        name = self.cleaned_data['username']

        if not name:
            if self.instance.has_anonymous_username():
                name = self.instance.username
            else:
                name = self.instance.anonymize_username()

        # All-digits usernames are disallowed since they can be
        # confused for user IDs in URLs. (See bug 862121.)
        if name.isdigit():
            raise forms.ValidationError(
                _('Usernames cannot contain only digits.'))

        slug_validator(
            name,
            lower=False,
            message=_('Enter a valid username consisting of letters, numbers, '
                      'underscores or hyphens.'))
        if BlacklistedName.blocked(name):
            raise forms.ValidationError(_('This username cannot be used.'))

        # FIXME: 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=name).exists()):
            raise forms.ValidationError(_('This username is already in use.'))

        return name
Example #3
0
    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
Example #4
0
    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
Example #5
0
    def validate_slug(self, value):
        slug_validator(value)

        if not self.instance or value != self.instance.slug:
            # DeniedSlug.blocked checks for all numeric slugs as well as being denied.
            if DeniedSlug.blocked(value):
                raise exceptions.ValidationError(
                    'This slug cannot be used. Please choose another.')

        return value
Example #6
0
    def clean_slug(self):
        slug = slugify(self.cleaned_data["slug"])
        slug_validator(slug)
        if self.instance and self.instance.slug == slug:
            return slug

        author = self.initial["author"]
        if author.collections.filter(slug=slug).count():
            raise forms.ValidationError(_("This url is already in use by another collection"))

        return slug
Example #7
0
    def clean_slug(self):
        slug = slugify(self.cleaned_data['slug'])
        slug_validator(slug)
        if self.instance and self.instance.slug == slug:
            return slug

        author = self.initial['author']
        if author.collections.filter(slug=slug).count():
            raise forms.ValidationError(
                ugettext('This url is already in use by another collection'))

        return slug
Example #8
0
def clean_addon_slug(slug, instance):
    slug_validator(slug, lower=False)

    if slug != instance.slug:
        if Addon.objects.filter(slug=slug).exists():
            raise forms.ValidationError(
                _('This slug is already in use. Please choose another.'))
        if BlacklistedSlug.blocked(slug):
            raise forms.ValidationError(
                _('The slug cannot be "%s". Please choose another.' % slug))

    return slug
Example #9
0
    def clean_slug(self):
        slug = slugify(self.cleaned_data['slug'])
        slug_validator(slug)
        if self.instance and self.instance.slug == slug:
            return slug

        author = self.initial['author']
        if author.collections.filter(slug=slug).count():
            raise forms.ValidationError(
                ugettext('This url is already in use by another collection'))

        return slug
Example #10
0
def clean_addon_slug(slug, instance):
    slug_validator(slug, lower=False)

    if slug != instance.slug:
        if Addon.objects.filter(slug=slug).exists():
            raise forms.ValidationError(
                _('This slug is already in use. Please choose another.'))
        if DeniedSlug.blocked(slug):
            raise forms.ValidationError(
                _('The slug cannot be "%s". Please choose another.' % slug))

    return slug
Example #11
0
def clean_addon_slug(slug, instance):
    slug_validator(slug, lower=False)

    if slug != instance.slug:
        if Addon.objects.filter(slug=slug).exists():
            raise forms.ValidationError(ugettext(
                'This slug is already in use. Please choose another.'))
        if DeniedSlug.blocked(slug):
            msg = ugettext(u'The slug cannot be "%(slug)s". '
                           u'Please choose another.')
            raise forms.ValidationError(msg % {'slug': slug})

    return slug
Example #12
0
    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
Example #13
0
    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
Example #14
0
 def check(x, y):
     assert slugify(x) == y
     slug_validator(slugify(x))
 def check(x, y):
     eq_(slugify(x), y)
     slug_validator(slugify(x))
def test_slug_validator():
    eq_(slug_validator(u.lower()), None)
    eq_(slug_validator('-'.join([u.lower(), u.lower()])), None)
    assert_raises(ValidationError, slug_validator, '234.add')
    assert_raises(ValidationError, slug_validator, 'a a a')
    assert_raises(ValidationError, slug_validator, 'tags/')
Example #17
0
def test_slugify(test_input, expected):
    assert slugify(test_input) == expected
    slug_validator(slugify(test_input))
Example #18
0
def test_slug_validator():
    assert slug_validator(u.lower()) is None
    assert slug_validator('-'.join([u.lower(), u.lower()])) is None
    pytest.raises(ValidationError, slug_validator, '234.add')
    pytest.raises(ValidationError, slug_validator, 'a a a')
    pytest.raises(ValidationError, slug_validator, 'tags/')
Example #19
0
def test_slugify(test_input, expected):
    assert slugify(test_input) == expected
    slug_validator(slugify(test_input))
Example #20
0
def test_slug_validator():
    eq_(slug_validator(u.lower()), None)
    eq_(slug_validator('-'.join([u.lower(), u.lower()])), None)
    assert_raises(ValidationError, slug_validator, '234.add')
    assert_raises(ValidationError, slug_validator, 'a a a')
    assert_raises(ValidationError, slug_validator, 'tags/')
Example #21
0
 def check(x, y):
     eq_(slugify(x), y)
     slug_validator(slugify(x))
Example #22
0
def test_slug_validator():
    assert slug_validator(u.lower()) is None
    assert slug_validator('-'.join([u.lower(), u.lower()])) is None
    pytest.raises(ValidationError, slug_validator, '234.add')
    pytest.raises(ValidationError, slug_validator, 'a a a')
    pytest.raises(ValidationError, slug_validator, 'tags/')
Example #23
0
 def check(x, y):
     assert slugify(x) == y
     slug_validator(slugify(x))