本文整理汇总了Python中app.users.models.User.make_valid_name方法的典型用法代码示例。如果您正苦于以下问题:Python User.make_valid_name方法的具体用法?Python User.make_valid_name怎么用?Python User.make_valid_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.users.models.User
的用法示例。
在下文中一共展示了User.make_valid_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import make_valid_name [as 别名]
def validate(self):
if not Form.validate(self):
return False
if self.name.data == self.original_name:
return True
if self.name.data != User.make_valid_name(self.name.data):
self.name.errors.append(gettext('This name has invalid characters. Please use letters, numbers, dots and underscores only.'))
return False
user = User.query.filter_by(name=self.name.data).first()
if user != None:
self.name.errors.append(gettext('This name is already in use. Please choose another one.'))
return False
return True
示例2: validate
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import make_valid_name [as 别名]
def validate(self):
valid = True
if not Form.validate(self):
valid = False
if self.name.data != User.make_valid_name(self.name.data):
self.name.errors.append(gettext('This name has invalid characters'))
valid = False
if self.nickname.data != User.make_valid_nickname(self.nickname.data):
self.nickname.errors.append(gettext('This nickname has invalid characters'))
valid = False
if User.is_email_taken(self.email.data):
self.email.errors.append(gettext('This email is already in use. Please choose another one.'))
valid = False
if User.is_nickname_taken(self.nickname.data):
self.nickname.errors.append(gettext('This nickname is already in use. Please choose another one.'))
valid = False
return valid