本文整理汇总了Python中models.Employee.isValidUsername方法的典型用法代码示例。如果您正苦于以下问题:Python Employee.isValidUsername方法的具体用法?Python Employee.isValidUsername怎么用?Python Employee.isValidUsername使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Employee
的用法示例。
在下文中一共展示了Employee.isValidUsername方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import isValidUsername [as 别名]
def clean(self):
"""
Do validation
"""
super(EmployeeForm, self).clean()
username = self.cleaned_data.get('user_name')
if username:
if not Employee.isValidUsername(username):
raise forms.ValidationError(_(
'Invalid username format. Accepted characters are A-Z,a-z,0-9,_-,.'
))
if User.objects.filter(username__exact = username).exists():
raise forms.ValidationError(_('A user with the given username already exists'))
email = self.cleaned_data.get('email')
confirm_email = self.cleaned_data.get('confirm_email')
if not email == confirm_email:
raise forms.ValidationError(_('The emails are not equal'))
if User.objects.filter(email__exact = self.cleaned_data.get('email')).exists():
raise forms.ValidationError(_('A user with the given email already exists'))
return self.cleaned_data