user.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:xiaodi 作者: shenaishiren 项目源码 文件源码
def put_user(user, nickname=None, headimg=None, sex=None, introduction=None):
    if nickname and nickname != user.nickname:
        if (yield get_db_object_by_attr(User, nickname=nickname, ignore=True)) is not None:
            raise gen.Return(already_exist_error('nickname %s is already existed' % nickname))
        user.nickname = nickname
    if headimg:
        if user.headimg != DEFAULT_HEADIMG:
            result = yield remove_image_from_oss(user.headimg)
            if not result:
                LOG.error('failed to remove image: %s' % user.headimg)

        headimg_path = yield save_image_to_oss(headimg, OSS_HEADIMG_PATH,
                                               str(datetime.now()), when_fail=DEFAULT_HEADIMG)
        user.headimg = headimg_path
    if sex:
        user.sex = sex
    if introduction:
        user.introduction = introduction

    yield execute(('add', user))
    yield execute(('commit', None))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号