Beispiel #1
0
 def clean_username(self):
     name = self.cleaned_data['username']
     slug_validator(
         name,
         lower=False,
         message=_('Enter a valid username consisting of letters, numbers, '
                   'underscores or hyphens.'))
     if BlacklistedUsername.blocked(name):
         raise forms.ValidationError(_('This username cannot be used.'))
     return name
Beispiel #2
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
Beispiel #3
0
def clean_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
Beispiel #4
0
    def clean_slug(self):
        target = self.cleaned_data['slug']
        slug_validator(target, lower=False)

        if target != self.instance.slug:
            if Addon.objects.filter(slug=target).exists():
                raise forms.ValidationError(_('This slug is already in use.'))

            if BlacklistedSlug.blocked(target):
                raise forms.ValidationError(
                    _('The slug cannot be: %s.' % target))
        return target
Beispiel #5
0
def clean_slug(slug, instance):
    slug_validator(slug, lower=False)
    slug_field = 'app_slug' if instance.is_webapp() else 'slug'

    if slug != getattr(instance, slug_field):
        if Addon.objects.filter(**{slug_field: 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
Beispiel #6
0
    def clean_slug(self):
        target = self.cleaned_data['slug']
        slug_validator(target, lower=False)
        slug_field = 'app_slug' if self.instance.is_webapp() else 'slug'

        if target != getattr(self.instance, slug_field):
            if Addon.objects.filter(**{slug_field: target}).exists():
                raise forms.ValidationError(_('This slug is already in use.'))

            if BlacklistedSlug.blocked(target):
                raise forms.ValidationError(
                    _('The slug cannot be: %s.' % target))
        return target
Beispiel #7
0
    def clean_username(self):
        name = self.cleaned_data['username']
        slug_validator(name, lower=False,
            message=_('Enter a valid username consisting of letters, numbers, '
                      'underscores or hyphens.'))
        if BlacklistedUsername.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
Beispiel #8
0
    def clean_app_slug(self):
        slug = self.cleaned_data['app_slug']
        slug_validator(slug, lower=False)

        if slug != self.instance.app_slug:
            if Webapp.objects.filter(app_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
Beispiel #9
0
    def clean_username(self):
        name = self.cleaned_data['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
Beispiel #10
0
 def clean_username(self):
     name = self.cleaned_data['username']
     slug_validator(name, lower=False)
     if BlacklistedUsername.blocked(name):
         raise forms.ValidationError(_('This username is invalid.'))
     return name
Beispiel #11
0
 def check(x, y):
     eq_(slugify(x), y)
     slug_validator(slugify(x))
Beispiel #12
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/')