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


Python User.delete_instance方法代码示例

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


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

示例1: user_edit

# 需要导入模块: from streetsign_server.models import User [as 别名]
# 或者: from streetsign_server.models.User import delete_instance [as 别名]
def user_edit(userid=-1):
    ''' edit one user.  Admins can edit any user, but other users
        can only edit themselves. if userid is -1, create a new user. '''

    try:
        current_user = user_session.get_user()
    except user_session.NotLoggedIn as e:
        flash("Sorry, you're not logged in!")
        return permission_denied("You're not logged in!")

    userid = int(userid)

    if userid != -1:
        try:
            user = User.get(id=userid)
        except User.DoesNotExist:
            return not_found(title="User doesn't exist",
                             message="Sorry, that user does not exist!")
    else:
        if not current_user.is_admin:
            flash('Sorry! Only admins can create new users!')
            return permission_denied("Admins only!")

        try:
            user = User.get(loginname=request.form['loginname'])
            return permission_denied("Username already exists!")
        except peewee.DoesNotExist:
            pass

        user = User() #pylint: disable=no-value-for-parameter

    if request.method == 'POST':
        if current_user != user and not current_user.is_admin:
            return permission_denied("Sorry, you may not edit this user.")

        update_user(user, request.form, current_user)

        # save:

        try:
            user.save()
            if userid == -1:
                flash('New user created.')
                return redirect(url_for('user_edit', userid=user.id))
            else:
                flash('Saved')

        except peewee.IntegrityError as err:
            flash('Cannot Save:' + str(err))

    elif request.method == 'DELETE':
        if not current_user.is_admin:
            return 'Sorry, only admins can delete users', 403

        if user.id == current_user.id:
            return 'Sorry! You cannot delete yourself!', 403

        user.delete_instance(recursive=True)

        return 'User: %s deleted. (And all their posts)' % user.displayname

    users_posts = Post.select().where(Post.author == user) \
                               .order_by(Post.write_date.desc()) \
                               .limit(10)

    return render_template('user.html',
                           allgroups=Group.select(),
                           posts=users_posts, user=user)
开发者ID:Fivebread,项目名称:streetsign,代码行数:70,代码来源:users_and_auth.py


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