本文整理汇总了Python中models.User.User.by_display_name方法的典型用法代码示例。如果您正苦于以下问题:Python User.by_display_name方法的具体用法?Python User.by_display_name怎么用?Python User.by_display_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User.User
的用法示例。
在下文中一共展示了User.by_display_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_display_name [as 别名]
def post(self, *args, **kwargs):
''' Attempts to create an account, with shitty form validation '''
# Check user_name parameter
try:
user_name = self.get_argument('username')
except:
self.render('public/registration.html', errors = 'Please enter a valid account name')
# Check handle parameter
try:
handle = self.get_argument('handle')
except:
self.render('public/registration.html', errors = 'Please enter a valid handle')
# Check password parameter
try:
password1 = self.get_argument('pass1')
password2 = self.get_argument('pass2')
if password1 != password2:
self.render('public/registration.html', errors = 'Passwords did not match')
else:
password = password1
except:
self.render('public/registration.html', errors = 'Please enter a password')
# Check recaptcha
try:
response = captcha.submit(
self.get_argument('recaptcha_challenge_field'),
self.get_argument('recaptcha_response_field'),
self.application.settings['recaptcha_private_key'],
self.request.remote_ip,)
except:
self.render('public/registration.html', errors = "Please fill out recaptcha!")
# Create account
if User.by_user_name(user_name) != None:
self.render('public/registration.html', errors = 'Account name already taken')
elif user_name == handle:
self.render('public/registration.html', errors = 'Account name and hacker name must differ')
elif User.by_display_name(handle) != None:
self.render('public/registration.html', errors = 'Handle already taken')
elif not 0 < len(password) <= 7:
self.render('public/registration.html', errors = 'Password must be 1-7 characters')
elif not response.is_valid:
self.render('public/registration.html', errors = 'Invalid Recaptcha!')
else:
char_white_list = ascii_letters + digits
user_name = filter(lambda char: char in char_white_list, user_name)
display_name = filter(lambda char: char in char_white_list, handle)
user = User(
user_name = unicode(user_name),
display_name = unicode(display_name),
password = password
)
self.dbsession.add(user)
self.dbsession.flush()
self.redirect('/login')