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


Python ProfileForm.populate_obj方法代码示例

本文整理汇总了Python中forms.ProfileForm.populate_obj方法的典型用法代码示例。如果您正苦于以下问题:Python ProfileForm.populate_obj方法的具体用法?Python ProfileForm.populate_obj怎么用?Python ProfileForm.populate_obj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.ProfileForm的用法示例。


在下文中一共展示了ProfileForm.populate_obj方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: profile

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import populate_obj [as 别名]
def profile():
    if current_user.is_authenticated():
        user = current_user
    else:
        user = None
    
    form = ProfileForm(obj=user)

    if not form.password or form.password == '':
        del form.password
    
    if form.validate_on_submit():
        if user:
            flash('Successfully updated your profile.')
        else:
            user = User()
            user.role = 1
            flash('Congratulations, you just created an account!')

        form.populate_obj(user)
        db.session.add(user)
        db.session.commit()

        if not current_user.is_authenticated():
            login_user(user)

        return redirect('/')

    return render_template('demographic.html', form=form)
开发者ID:aliyarahman,项目名称:student-application,代码行数:31,代码来源:views.py

示例2: profile

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import populate_obj [as 别名]
def profile():
    form = ProfileForm(obj=current_user)

    if form.validate_on_submit():
        form.populate_obj(user)
        user.update_at = get_current_time()

        db.session.commit()

        flash('Public profile updated.', 'success')

    return render_template('user/profile.html', form=form)
开发者ID:LoyiLY,项目名称:fbone,代码行数:14,代码来源:views.py

示例3: create_user

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import populate_obj [as 别名]
def create_user(user_id=None):
    """
    Create or edit a user.
    """
    form = ProfileForm()

    if request.method == 'POST':
        if form.validate():
            if user_id != None:
                # Edit a user
                user = User.query.filter(User.id == user_id).first()
                form.populate_obj(user)
                if form.password.data != "":
                    user.set_password(form.password.data)
                db.session.commit()
                flash('User "' + user.firstname + '" successfully updated.', 'success')
            else:
                # Create a new user
                role_user = Role.query.filter(Role.name == "user").first()
                user = User(firstname=form.firstname.data,
                             lastname=form.lastname.data,
                             email=form.email.data,
                             pwdhash=generate_password_hash(form.password.data))
                user.roles.extend([role_user])
                db.session.add(user)
                try:
                    db.session.commit()
                except IntegrityError:
                    flash('Email already used.', 'warning')
                    return redirect(redirect_url())
                flash('User "' + user.firstname + '" successfully created.', 'success')
            return redirect("/admin/edit_user/"+str(user.id)+"/")
        else:
            return render_template('profile.html', form=form)

    if request.method == 'GET':
        if user_id != None:
            user = User.query.filter(User.id == user_id).first()
            form = ProfileForm(obj=user)
            message = "Edit the user <i>" + user.firstname + "</i>"
        else:
            form = ProfileForm()
            message="Add a new user"
        return render_template('/admin/create_user.html', form=form, message=message)
开发者ID:cedricbonhomme,项目名称:Grenouille,代码行数:46,代码来源:views.py

示例4: profile

# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import populate_obj [as 别名]
def profile():
    """
    Edit the profile of the currently logged user.
    """
    user = User.query.filter(User.email == g.user.email).first()
    form = ProfileForm()

    if request.method == 'POST':
        if form.validate():
            form.populate_obj(user)
            if form.password.data != "":
                user.set_password(form.password.data)
            db.session.commit()
            flash('User "' + user.firstname + '" successfully updated.', 'success')
            return redirect(url_for('profile'))
        else:
            return render_template('profile.html', form=form)

    if request.method == 'GET':
        form = ProfileForm(obj=user)
        return render_template('profile.html', user=user, form=form)
开发者ID:cedricbonhomme,项目名称:Grenouille,代码行数:23,代码来源:views.py


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