示例#1
0
    def clean_username(self):
        username = self.cleaned_data["username"]
        if not username:
            return self.instance.username

        # Don't be jacking somebody's username
        # This causes a potential race condition however the worst that can
        # happen is bad UI.
        if User.objects.filter(username=username).exclude(
                pk=self.instance.id).exists():
            raise forms.ValidationError(
                _("This username is in use. Please try"
                  " another."))

        # No funky characters in username.
        if not re.match(r"^[\w.@+-]+$", username):
            raise forms.ValidationError(
                _("Please use only alphanumeric"
                  " characters"))

        if not validate_username(username):
            raise forms.ValidationError(
                _("This username is not allowed, "
                  "please choose another."))
        return username
示例#2
0
    def clean_username(self):
        username = self.cleaned_data["username"]
        if not username:
            return self.instance.username

        # Don't be jacking somebody's username
        # This causes a potential race condition however the worst that can
        # happen is bad UI.
        if User.objects.filter(username=username).exclude(pk=self.instance.id).exists():
            raise forms.ValidationError(_(u"This username is in use. Please try" u" another."))

        # No funky characters in username.
        if not re.match(r"^[\w.@+-]+$", username):
            raise forms.ValidationError(_(u"Please use only alphanumeric" u" characters"))

        if not validate_username(username):
            raise forms.ValidationError(_(u"This username is not allowed, " u"please choose another."))
        return username