本文整理汇总了Python中model.User.getInstanceFromUsername方法的典型用法代码示例。如果您正苦于以下问题:Python User.getInstanceFromUsername方法的具体用法?Python User.getInstanceFromUsername怎么用?Python User.getInstanceFromUsername使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.getInstanceFromUsername方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user_save
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import getInstanceFromUsername [as 别名]
def user_save():
from model import User
# Load user id from original username
user = User.getInstanceFromUsername(request.form['original_username'])
errors = []
# Validate data
# Check for required fields
labels = {'username': 'Username', 'email': 'E-mail', 'display_name': 'Display Name'}
for el in ['username', 'email', 'display_name']:
if el not in request.form or len(request.form[el]) == 0:
errors.append("'{0}' is a required field.".format(labels[el]))
# Make sure username is not currently used
if user.username != request.form['username'] and User.usernameExists(request.form['username'], exclude_user_id = user.user_id):
errors.append("The username '{username}' already exists in our system. Please choose a different one.".format(username = request.form['username']))
# No spaces in username or password
if ' ' in request.form['username']:
errors.append('Username may not contain spaces')
if len(request.form['username']) not in range(4, 31):
errors.append('Username must be 4-30 characters long.')
# If errors, display form again
if len(errors) != 0:
role_id = ''
if 'role_id' in request.form and len(request.form['role_id']) > 0:
role_id = int(request.form['role_id'])
return render_template(
'user/form.html', error = "<br/>\n".join(errors),
original_username = request.form['original_username'],
username = request.form['username'],
email = request.form['email'],
display_name = request.form['display_name'],
active = int(request.form['active']),
role_ids = [role_id]
)
# If no errors, save user as not active and redirect to awaiting approval page
user.username = request.form['username']
user.email = request.form['email']
user.display_name = request.form['display_name']
user.active = request.form['active']
user.save()
user.update_roles([request.form['role_id']])
return redirect(url_for('user_manage'))
示例2: user_form
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import getInstanceFromUsername [as 别名]
def user_form(username):
from model import User
user = User.getInstanceFromUsername(username)
# Do not allow editing administrators
if user.is_administrator():
return redirect(url_for('user'))
return render_template('user/form.html',
username = user.username,
original_username = user.username,
email = user.email,
display_name = user.display_name,
active = user.active,
role_ids = user.role_ids()
)