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))
评论列表
文章目录