当前位置: 首页>>代码示例>>Python>>正文


Python User.getInstanceFromUsername方法代码示例

本文整理汇总了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'))
开发者ID:benpeacock,项目名称:Climb-Spotter,代码行数:54,代码来源:csapp.py

示例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()
    )
开发者ID:benpeacock,项目名称:Climb-Spotter,代码行数:20,代码来源:csapp.py


注:本文中的model.User.getInstanceFromUsername方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。